Removed the cached matrices from osg::Camera, so that
osg::Camrea::getModelViewMatrix() and osg::Camera::getProjectionMatrix() are calculated on the fly. Removed various redudent methods, including the project and unproject methods which are better supported within osgUtil::SceneView. Added a computeWindowMatrix() method to Viewport, to make it easier to construct a MV*P*W matrix for converting local coords into screen coords and visa versa. Converted SceneView and CullVisitor to use this new method.
This commit is contained in:
@@ -106,12 +106,12 @@ class SG_EXPORT Camera: public osg::Referenced
|
||||
* width/height.*/
|
||||
void adjustAspectRatio(const double newAspectRatio, const AdjustAspectRatioMode aa);
|
||||
|
||||
const double left() const;
|
||||
const double right() const;
|
||||
const double top() const;
|
||||
const double bottom() const;
|
||||
const double zNear() const;
|
||||
const double zFar() const;
|
||||
const double left() const { return _left; }
|
||||
const double right() const { return _right; }
|
||||
const double bottom() const { return _bottom; }
|
||||
const double top() const { return _top; }
|
||||
const double zNear() const { return _zNear; }
|
||||
const double zFar() const { return _zFar; }
|
||||
|
||||
/** Calculate and return the equivalent fovx for the current project setting.
|
||||
* This value is only valid for when a symmetric perspective projection exists.
|
||||
@@ -127,7 +127,6 @@ class SG_EXPORT Camera: public osg::Referenced
|
||||
* Aspect ratio is defined as width/height.*/
|
||||
const double calc_aspectRatio() const;
|
||||
|
||||
const Matrix& getProjectionMatrix() const;
|
||||
|
||||
|
||||
|
||||
@@ -222,38 +221,13 @@ class SG_EXPORT Camera: public osg::Referenced
|
||||
* allow the OSG to update matrices accordingly.*/
|
||||
void attachTransform(const TransformMode mode, Matrix* modelTransform=0);
|
||||
|
||||
/** must be called after you modify an attachedTransform. */
|
||||
void dirtyTransform();
|
||||
|
||||
Matrix* getTransform(const TransformMode mode);
|
||||
|
||||
const Matrix* getTransform(const TransformMode mode) const;
|
||||
|
||||
|
||||
const Vec3 getEyePoint_Model() const;
|
||||
const Vec3 getCenterPoint_Model() const;
|
||||
const Vec3 getLookVector_Model() const;
|
||||
const Vec3 getUpVector_Model() const;
|
||||
const Vec3 getSideVector_Model() const;
|
||||
|
||||
/** Get the ModelView matrix.
|
||||
* If a ModelTransform is supplied then the ModelView matrix is
|
||||
* created by multiplying the current LookAt by ModelTransform.
|
||||
* Otherwise it is simply created by using the current LookAt,
|
||||
* equivalent to using gluLookAt.*/
|
||||
const Matrix& getModelViewMatrix() const;
|
||||
|
||||
|
||||
/** Map object coordinates into windows coordinates.
|
||||
* Equivalent to gluProject(...). */
|
||||
const bool project(const Vec3& obj,const Viewport& viewport,Vec3& win) const;
|
||||
|
||||
/** Map window coordinates into object coordinates.
|
||||
* Equivalent to gluUnProject(...). */
|
||||
const bool unproject(const Vec3& win,const Viewport& viewport,Vec3& obj) const;
|
||||
|
||||
|
||||
|
||||
enum FusionDistanceMode
|
||||
{
|
||||
PROPORTIONAL_TO_LOOK_DISTANCE,
|
||||
@@ -263,7 +237,7 @@ class SG_EXPORT Camera: public osg::Referenced
|
||||
/** Set the mode of the fusion distance function which in use to calculate the
|
||||
* fusion distance used in stereo rendering. Default value is
|
||||
* PROPORTIONAL_TO_LOOK_DISTANCE. Use in conjunction with setFusionDistanceRatio(float).*/
|
||||
void setFusionDistanceMode(FusionDistanceMode mode) { _fusionDistanceMode = mode; _dirty = true; }
|
||||
void setFusionDistanceMode(FusionDistanceMode mode) { _fusionDistanceMode = mode; }
|
||||
|
||||
/** Get the mode of the fusion distance function.*/
|
||||
FusionDistanceMode getFusionDistanceMode() const { return _fusionDistanceMode; }
|
||||
@@ -271,7 +245,7 @@ class SG_EXPORT Camera: public osg::Referenced
|
||||
/** Set the ratio of the fusion distance function which in use to calculate the
|
||||
* fusion distance used in stereo rendering. Default value is 1.0f
|
||||
* Use in conjunction with setFusionDistanceMode(..).*/
|
||||
void setFusionDistanceRatio(float ratio) { _fusionDistanceRatio = ratio; _dirty = true; }
|
||||
void setFusionDistanceRatio(float ratio) { _fusionDistanceRatio = ratio; }
|
||||
|
||||
/** Get the ratio of the fusion distance function.*/
|
||||
float getFusionDistanceRatio() const { return _fusionDistanceRatio; }
|
||||
@@ -282,12 +256,30 @@ class SG_EXPORT Camera: public osg::Referenced
|
||||
|
||||
/** Set the physical distance between the viewers eyes and the display system.
|
||||
* Note, only used when rendering in stereo.*/
|
||||
void setScreenDistance(float screenDistance) { _screenDistance = screenDistance; _dirty = true; }
|
||||
void setScreenDistance(float screenDistance) { _screenDistance = screenDistance; }
|
||||
|
||||
/** Get the physical distance between the viewers eyes and the display system.*/
|
||||
const float getScreenDistance() const { return _screenDistance; }
|
||||
|
||||
|
||||
|
||||
/** Get the Projection Matrix.*/
|
||||
const Matrix getProjectionMatrix() const;
|
||||
|
||||
/** Get the ModelView matrix.
|
||||
* If a ModelTransform is supplied then the ModelView matrix is
|
||||
* created by multiplying the current LookAt by ModelTransform.
|
||||
* Otherwise it is simply created by using the current LookAt,
|
||||
* equivalent to using gluLookAt.*/
|
||||
const Matrix getModelViewMatrix() const;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void copy(const Camera&);
|
||||
@@ -320,20 +312,6 @@ class SG_EXPORT Camera: public osg::Referenced
|
||||
TransformMode _attachedTransformMode;
|
||||
ref_ptr<Matrix> _eyeToModelTransform;
|
||||
ref_ptr<Matrix> _modelToEyeTransform;
|
||||
|
||||
// flag to determine if near and far clipping planes are required.
|
||||
bool _useNearAndFarClippingPlanes;
|
||||
|
||||
// cached matrix and clipping volume derived from above settings.
|
||||
mutable bool _dirty;
|
||||
mutable ref_ptr<Matrix> _projectionMatrix;
|
||||
mutable ref_ptr<Matrix> _modelViewMatrix;
|
||||
mutable ClippingVolume _clippingVolume;
|
||||
|
||||
mutable ref_ptr<Matrix> _mp;
|
||||
mutable ref_ptr<Matrix> _inversemp;
|
||||
|
||||
void computeMatrices() const;
|
||||
|
||||
float _screenDistance;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Types>
|
||||
#include <osg/Matrix>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -72,6 +73,16 @@ class SG_EXPORT Viewport : public StateAttribute
|
||||
/** Return the aspcetRatio of the viewport, which is equal to width/height.
|
||||
* If height is zero, the potental division by zero is avoid by simply returning 1.0f.*/
|
||||
inline const float aspectRatio() const { if (_height!=0) return (float)_width/(float)_height; else return 1.0f; }
|
||||
|
||||
/** Compute the Window Matrix which takes projected coords into Window coordinates.
|
||||
* To converted local coodinates into window coordinates use v_window = v_local * MVPW matrix,
|
||||
* where the MVPW matrix is ModelViewMatrix * ProjectionMatrix * WindowMatrix, the later supplied by
|
||||
* viewport::computeWindowMatrix(), the ModelView and Projection Matrix can either be sourced from the
|
||||
* curre osg::State object, via osgUtil::SceneView or CullVisitor.*/
|
||||
inline const osg::Matrix computeWindowMatrix() const
|
||||
{
|
||||
return osg::Matrix::translate(1.0f,1.0f,1.0f)*osg::Matrix::scale(0.5f*width(),0.5f*height(),0.5f);
|
||||
}
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
|
||||
@@ -329,7 +329,7 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
|
||||
if (!_viewportStack.empty())
|
||||
{
|
||||
osg::Viewport* viewport = _viewportStack.back().get();
|
||||
return osg::Matrix::scale(0.5f*viewport->width(),viewport->height(),0.5f)*osg::Matrix::translate(0.5f,0.5f,0.5f);
|
||||
return viewport->computeWindowMatrix();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -248,6 +248,8 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
|
||||
virtual void cullStage(osg::Matrix* projection,osg::Matrix* modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::RenderGraph* rendergraph, osgUtil::RenderStage* renderStage);
|
||||
virtual void drawStage(osgUtil::RenderStage* renderStage);
|
||||
|
||||
const osg::Matrix computeMVPW() const;
|
||||
|
||||
osg::ref_ptr<osg::Node> _sceneData;
|
||||
osg::ref_ptr<osg::StateSet> _globalState;
|
||||
osg::ref_ptr<osg::Light> _light;
|
||||
|
||||
Reference in New Issue
Block a user