Added osg::CameraView to help application/modellers position their cameras in scenes. Note,

CameraView is *not* a camera, it isn't an active object, but a passive one that
camera must track each frame to following the path of the CameraView.
This commit is contained in:
Robert Osfield 2005-10-04 13:41:20 +00:00
parent ff9ace16b4
commit 8e9ffd09af
4 changed files with 167 additions and 0 deletions

View File

@ -152,6 +152,10 @@ SOURCE=..\..\src\osg\CameraNode.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=..\..\src\osg\CameraView.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osg\ClearNode.cpp SOURCE=..\..\src\osg\ClearNode.cpp
# End Source File # End Source File
# Begin Source File # Begin Source File
@ -604,6 +608,10 @@ SOURCE=..\..\include\osg\CameraNode
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=..\..\include\osg\CameraView
# End Source File
# Begin Source File
SOURCE=..\..\include\osg\ClearNode SOURCE=..\..\include\osg\ClearNode
# End Source File # End Source File
# Begin Source File # Begin Source File

105
include/osg/CameraView Normal file
View File

@ -0,0 +1,105 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_CAMERAVIEW
#define OSG_CAMERAVIEW 1
#include <osg/Group>
#include <osg/Transform>
#include <osg/AnimationPath>
#include <osg/Vec3d>
#include <osg/Quat>
namespace osg {
/** CameraView - is a Transform that is used to specify camera views from within the scene graph.
* The application must attach a camera to a CameraView via the NodePath from the top of the scene graph
* to the CameraView node itself, and accimulate the view matrix from this NodePath.
*/
class OSG_EXPORT CameraView : public Transform
{
public :
CameraView();
CameraView(const CameraView& pat,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Transform(pat,copyop),
_position(pat._position),
_attitude(pat._attitude),
_fieldOfView(pat._fieldOfView),
_fieldOfViewMode(pat._fieldOfViewMode),
_focalLength(pat._focalLength) {}
META_Node(osg, CameraView);
/** Set the position of the camera view.*/
inline void setPosition(const Vec3d& pos) { _position = pos; dirtyBound(); }
/** Get the position of the camera view.*/
inline const Vec3d& getPosition() const { return _position; }
/** Set the attitide of the camera view.*/
inline void setAttitude(const Quat& quat) { _attitude = quat; dirtyBound(); }
/** Get the attitide of the camera view.*/
inline const Quat& getAttitude() const { return _attitude; }
/** Set the field of view.
* The cameras field of view can be contrained to either the horizontal or vertex axis of the camera, or unconstrained
* in which case the camera/application are left to choose an appropriate field of view.
* The default value if 60 degrres. */
inline void setFieldOfView(double fieldOfView) { _fieldOfView; }
/** Get the field of view.*/
inline double getFieldOfView() const { return _fieldOfView; }
enum FieldOfViewMode
{
UNCONSTRAINED,
HORIZONTAL,
VERTICAL
};
/** Set the field of view mode - controlling how the field of view of the camera is contrained by the CameaView settings.*/
inline void setFieldOfViewMode(FieldOfViewMode mode) { _fieldOfViewMode = mode; }
/** Get the field of view mode.*/
inline FieldOfViewMode getFieldOfViewMode() const { return _fieldOfViewMode; }
/** Set the focal length of the camera.
* A focal length of 0.0 indicates that the camera/application should determine the focal length.
* The default value is 0.0. */
inline void setFocalLength(double FocalLength) { _focalLength; }
/** Get the focal length of the camera.*/
inline double getFocalLength() const { return _focalLength; }
virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const;
virtual bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor* nv) const;
protected :
virtual ~CameraView() {}
Vec3d _position;
Quat _attitude;
double _fieldOfView;
FieldOfViewMode _fieldOfViewMode;
double _focalLength;
};
}
#endif

53
src/osg/CameraView.cpp Normal file
View File

@ -0,0 +1,53 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#include <osg/CameraView>
using namespace osg;
CameraView::CameraView():
_fieldOfView(60.0),
_fieldOfViewMode(VERTICAL),
_focalLength(0.0)
{
}
bool CameraView::computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
{
if (_referenceFrame==RELATIVE_RF)
{
matrix.preMult(osg::Matrix::rotate(_attitude)*
osg::Matrix::translate(_position));
}
else // absolute
{
matrix = osg::Matrix::rotate(_attitude)*
osg::Matrix::translate(_position);
}
return true;
}
bool CameraView::computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const
{
if (_referenceFrame==RELATIVE_RF)
{
matrix.postMult(osg::Matrix::translate(-_position)*
osg::Matrix::rotate(_attitude.inverse()));
}
else // absolute
{
matrix = osg::Matrix::translate(-_position)*
osg::Matrix::rotate(_attitude.inverse());
}
return true;
}

View File

@ -16,6 +16,7 @@ CXXFILES =\
BoundingSphere.cpp\ BoundingSphere.cpp\
BufferObject.cpp\ BufferObject.cpp\
CameraNode.cpp\ CameraNode.cpp\
CameraView.cpp\
ClearNode.cpp\ ClearNode.cpp\
ClipNode.cpp\ ClipNode.cpp\
ClipPlane.cpp\ ClipPlane.cpp\