Renamed osg::CameraNode to osg::Camera, cleaned up osg::View.
Added beginnings of new osgViewer::Scene,View,Viewer,CompositeViewer and GraphicsWindowProxy files.
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
#include <osg/AnimationPath>
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/PositionAttitudeTransform>
|
||||
#include <osg/CameraNode>
|
||||
#include <osg/Camera>
|
||||
#include <osg/CameraView>
|
||||
#include <osg/io_utils>
|
||||
|
||||
@@ -156,7 +156,7 @@ class AnimationPathCallbackVisitor : public NodeVisitor
|
||||
_pivotPoint(pivotPoint),
|
||||
_useInverseMatrix(useInverseMatrix) {}
|
||||
|
||||
virtual void apply(CameraNode& camera)
|
||||
virtual void apply(Camera& camera)
|
||||
{
|
||||
Matrix matrix;
|
||||
if (_useInverseMatrix)
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
#include <osg/CameraNode>
|
||||
#include <osg/Camera>
|
||||
#include <osg/Notify>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
CameraNode::CameraNode():
|
||||
Camera::Camera():
|
||||
_view(0),
|
||||
_clearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f)),
|
||||
_clearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT),
|
||||
@@ -30,7 +30,7 @@ CameraNode::CameraNode():
|
||||
setStateSet(new StateSet);
|
||||
}
|
||||
|
||||
CameraNode::CameraNode(const CameraNode& camera,const CopyOp& copyop):
|
||||
Camera::Camera(const Camera& camera,const CopyOp& copyop):
|
||||
Transform(camera,copyop),
|
||||
CullSettings(camera),
|
||||
_view(camera._view),
|
||||
@@ -53,23 +53,23 @@ CameraNode::CameraNode(const CameraNode& camera,const CopyOp& copyop):
|
||||
}
|
||||
|
||||
|
||||
CameraNode::~CameraNode()
|
||||
Camera::~Camera()
|
||||
{
|
||||
}
|
||||
|
||||
bool CameraNode::isRenderToTextureCamera() const
|
||||
bool Camera::isRenderToTextureCamera() const
|
||||
{
|
||||
return (!_bufferAttachmentMap.empty());
|
||||
}
|
||||
|
||||
void CameraNode::setRenderTargetImplementation(RenderTargetImplementation impl)
|
||||
void Camera::setRenderTargetImplementation(RenderTargetImplementation impl)
|
||||
{
|
||||
_renderTargetImplementation = impl;
|
||||
if (impl<FRAME_BUFFER) _renderTargetFallback = (RenderTargetImplementation)(impl+1);
|
||||
else _renderTargetFallback = impl;
|
||||
}
|
||||
|
||||
void CameraNode::setRenderTargetImplementation(RenderTargetImplementation impl, RenderTargetImplementation fallback)
|
||||
void Camera::setRenderTargetImplementation(RenderTargetImplementation impl, RenderTargetImplementation fallback)
|
||||
{
|
||||
if (impl<fallback || (impl==FRAME_BUFFER && fallback==FRAME_BUFFER))
|
||||
{
|
||||
@@ -78,12 +78,12 @@ void CameraNode::setRenderTargetImplementation(RenderTargetImplementation impl,
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Warning: CameraNode::setRenderTargetImplementation(impl,fallback) must have a lower rated fallback than the main target implementation."<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<"Warning: Camera::setRenderTargetImplementation(impl,fallback) must have a lower rated fallback than the main target implementation."<<std::endl;
|
||||
setRenderTargetImplementation(impl);
|
||||
}
|
||||
}
|
||||
|
||||
void CameraNode::setColorMask(osg::ColorMask* colorMask)
|
||||
void Camera::setColorMask(osg::ColorMask* colorMask)
|
||||
{
|
||||
if (_colorMask == colorMask) return;
|
||||
|
||||
@@ -101,13 +101,13 @@ void CameraNode::setColorMask(osg::ColorMask* colorMask)
|
||||
}
|
||||
}
|
||||
|
||||
void CameraNode::setColorMask(bool red, bool green, bool blue, bool alpha)
|
||||
void Camera::setColorMask(bool red, bool green, bool blue, bool alpha)
|
||||
{
|
||||
if (!_colorMask) setColorMask(new osg::ColorMask);
|
||||
if (_colorMask.valid()) _colorMask->setMask(red,green,blue,alpha);
|
||||
}
|
||||
|
||||
void CameraNode::setViewport(osg::Viewport* viewport)
|
||||
void Camera::setViewport(osg::Viewport* viewport)
|
||||
{
|
||||
if (_viewport == viewport) return;
|
||||
|
||||
@@ -125,19 +125,19 @@ void CameraNode::setViewport(osg::Viewport* viewport)
|
||||
}
|
||||
}
|
||||
|
||||
void CameraNode::setViewport(int x,int y,int width,int height)
|
||||
void Camera::setViewport(int x,int y,int width,int height)
|
||||
{
|
||||
if (!_viewport) setViewport(new osg::Viewport);
|
||||
if (_viewport.valid()) _viewport->setViewport(x,y,width,height);
|
||||
}
|
||||
|
||||
Matrixd CameraNode::getInverseViewMatrix() const
|
||||
Matrixd Camera::getInverseViewMatrix() const
|
||||
{
|
||||
Matrixd inverse;
|
||||
inverse.invert(_viewMatrix);
|
||||
return inverse;
|
||||
}
|
||||
void CameraNode::setProjectionMatrixAsOrtho(double left, double right,
|
||||
void Camera::setProjectionMatrixAsOrtho(double left, double right,
|
||||
double bottom, double top,
|
||||
double zNear, double zFar)
|
||||
{
|
||||
@@ -146,14 +146,14 @@ void CameraNode::setProjectionMatrixAsOrtho(double left, double right,
|
||||
zNear, zFar));
|
||||
}
|
||||
|
||||
void CameraNode::setProjectionMatrixAsOrtho2D(double left, double right,
|
||||
void Camera::setProjectionMatrixAsOrtho2D(double left, double right,
|
||||
double bottom, double top)
|
||||
{
|
||||
setProjectionMatrix(osg::Matrixd::ortho2D(left, right,
|
||||
bottom, top));
|
||||
}
|
||||
|
||||
void CameraNode::setProjectionMatrixAsFrustum(double left, double right,
|
||||
void Camera::setProjectionMatrixAsFrustum(double left, double right,
|
||||
double bottom, double top,
|
||||
double zNear, double zFar)
|
||||
{
|
||||
@@ -162,14 +162,14 @@ void CameraNode::setProjectionMatrixAsFrustum(double left, double right,
|
||||
zNear, zFar));
|
||||
}
|
||||
|
||||
void CameraNode::setProjectionMatrixAsPerspective(double fovy,double aspectRatio,
|
||||
void Camera::setProjectionMatrixAsPerspective(double fovy,double aspectRatio,
|
||||
double zNear, double zFar)
|
||||
{
|
||||
setProjectionMatrix(osg::Matrixd::perspective(fovy,aspectRatio,
|
||||
zNear, zFar));
|
||||
}
|
||||
|
||||
bool CameraNode::getProjectionMatrixAsOrtho(double& left, double& right,
|
||||
bool Camera::getProjectionMatrixAsOrtho(double& left, double& right,
|
||||
double& bottom, double& top,
|
||||
double& zNear, double& zFar)
|
||||
{
|
||||
@@ -178,7 +178,7 @@ bool CameraNode::getProjectionMatrixAsOrtho(double& left, double& right,
|
||||
zNear, zFar);
|
||||
}
|
||||
|
||||
bool CameraNode::getProjectionMatrixAsFrustum(double& left, double& right,
|
||||
bool Camera::getProjectionMatrixAsFrustum(double& left, double& right,
|
||||
double& bottom, double& top,
|
||||
double& zNear, double& zFar)
|
||||
{
|
||||
@@ -187,29 +187,29 @@ bool CameraNode::getProjectionMatrixAsFrustum(double& left, double& right,
|
||||
zNear, zFar);
|
||||
}
|
||||
|
||||
bool CameraNode::getProjectionMatrixAsPerspective(double& fovy,double& aspectRatio,
|
||||
bool Camera::getProjectionMatrixAsPerspective(double& fovy,double& aspectRatio,
|
||||
double& zNear, double& zFar)
|
||||
{
|
||||
return _projectionMatrix.getPerspective(fovy, aspectRatio, zNear, zFar);
|
||||
}
|
||||
|
||||
void CameraNode::setViewMatrixAsLookAt(const Vec3& eye,const Vec3& center,const Vec3& up)
|
||||
void Camera::setViewMatrixAsLookAt(const Vec3& eye,const Vec3& center,const Vec3& up)
|
||||
{
|
||||
setViewMatrix(osg::Matrixd::lookAt(eye,center,up));
|
||||
}
|
||||
|
||||
void CameraNode::getViewMatrixAsLookAt(Vec3& eye,Vec3& center,Vec3& up,float lookDistance)
|
||||
void Camera::getViewMatrixAsLookAt(Vec3& eye,Vec3& center,Vec3& up,float lookDistance)
|
||||
{
|
||||
_viewMatrix.getLookAt(eye,center,up,lookDistance);
|
||||
}
|
||||
|
||||
|
||||
void CameraNode::attach(BufferComponent buffer, GLenum internalFormat)
|
||||
void Camera::attach(BufferComponent buffer, GLenum internalFormat)
|
||||
{
|
||||
_bufferAttachmentMap[buffer]._internalFormat = internalFormat;
|
||||
}
|
||||
|
||||
void CameraNode::attach(BufferComponent buffer, osg::Texture* texture, unsigned int level, unsigned int face, bool mipMapGeneration)
|
||||
void Camera::attach(BufferComponent buffer, osg::Texture* texture, unsigned int level, unsigned int face, bool mipMapGeneration)
|
||||
{
|
||||
_bufferAttachmentMap[buffer]._texture = texture;
|
||||
_bufferAttachmentMap[buffer]._level = level;
|
||||
@@ -217,26 +217,26 @@ void CameraNode::attach(BufferComponent buffer, osg::Texture* texture, unsigned
|
||||
_bufferAttachmentMap[buffer]._mipMapGeneration = mipMapGeneration;
|
||||
}
|
||||
|
||||
void CameraNode::attach(BufferComponent buffer, osg::Image* image)
|
||||
void Camera::attach(BufferComponent buffer, osg::Image* image)
|
||||
{
|
||||
_bufferAttachmentMap[buffer]._image = image;
|
||||
}
|
||||
|
||||
void CameraNode::detach(BufferComponent buffer)
|
||||
void Camera::detach(BufferComponent buffer)
|
||||
{
|
||||
_bufferAttachmentMap.erase(buffer);
|
||||
}
|
||||
|
||||
void CameraNode::releaseGLObjects(osg::State* state) const
|
||||
void Camera::releaseGLObjects(osg::State* state) const
|
||||
{
|
||||
if (state) const_cast<CameraNode*>(this)->_renderingCache[state->getContextID()] = 0;
|
||||
else const_cast<CameraNode*>(this)->_renderingCache.setAllElementsTo(0);
|
||||
if (state) const_cast<Camera*>(this)->_renderingCache[state->getContextID()] = 0;
|
||||
else const_cast<Camera*>(this)->_renderingCache.setAllElementsTo(0);
|
||||
|
||||
Transform::releaseGLObjects(state);
|
||||
}
|
||||
|
||||
|
||||
bool CameraNode::computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
|
||||
bool Camera::computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
|
||||
{
|
||||
if (_referenceFrame==RELATIVE_RF)
|
||||
{
|
||||
@@ -256,7 +256,7 @@ bool CameraNode::computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CameraNode::computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const
|
||||
bool Camera::computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const
|
||||
{
|
||||
const Matrixd& inverse = getInverseViewMatrix();
|
||||
|
||||
@@ -282,7 +282,7 @@ FrameBufferAttachment::FrameBufferAttachment(TextureRectangle* target)
|
||||
_ximpl->textureTarget = target;
|
||||
}
|
||||
|
||||
FrameBufferAttachment::FrameBufferAttachment(CameraNode::Attachment& attachment)
|
||||
FrameBufferAttachment::FrameBufferAttachment(Camera::Attachment& attachment)
|
||||
{
|
||||
osg::Texture* texture = attachment._texture.get();
|
||||
|
||||
@@ -344,12 +344,12 @@ FrameBufferAttachment::FrameBufferAttachment(CameraNode::Attachment& attachment)
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify(osg::WARN)<<"Error: FrameBufferAttachment::FrameBufferAttachment(CameraNode::Attachment&) passed an empty osg::Image, image must be allocated first."<<std::endl;
|
||||
osg::notify(osg::WARN)<<"Error: FrameBufferAttachment::FrameBufferAttachment(Camera::Attachment&) passed an empty osg::Image, image must be allocated first."<<std::endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
osg::notify(osg::WARN)<<"Error: FrameBufferAttachment::FrameBufferAttachment(CameraNode::Attachment&) passed an unrecognised Texture type."<<std::endl;
|
||||
osg::notify(osg::WARN)<<"Error: FrameBufferAttachment::FrameBufferAttachment(Camera::Attachment&) passed an unrecognised Texture type."<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ CXXFILES =\
|
||||
BoundingBox.cpp\
|
||||
BoundingSphere.cpp\
|
||||
BufferObject.cpp\
|
||||
CameraNode.cpp\
|
||||
Camera.cpp\
|
||||
CameraView.cpp\
|
||||
ClearNode.cpp\
|
||||
ClipNode.cpp\
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osg/Notify>
|
||||
#include <osg/OccluderNode>
|
||||
#include <osg/CameraNode>
|
||||
#include <osg/Transform>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/PositionAttitudeTransform>
|
||||
#include <osg/CameraView>
|
||||
#include <osg/CameraNode>
|
||||
#include <osg/Camera>
|
||||
#include <osg/Notify>
|
||||
|
||||
using namespace osg;
|
||||
@@ -28,7 +28,7 @@ class ApplyMatrixVisitor : public NodeVisitor
|
||||
ApplyMatrixVisitor(const osg::Matrix& matrix):
|
||||
_matrix(matrix) {}
|
||||
|
||||
virtual void apply(CameraNode& camera)
|
||||
virtual void apply(Camera& camera)
|
||||
{
|
||||
camera.setViewMatrix(_matrix);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
#include <osg/Transform>
|
||||
#include <osg/CameraNode>
|
||||
#include <osg/Camera>
|
||||
|
||||
#include <osg/Notify>
|
||||
|
||||
@@ -30,13 +30,13 @@ class TransformVisitor : public NodeVisitor
|
||||
|
||||
CoordMode _coordMode;
|
||||
Matrix& _matrix;
|
||||
bool _ignoreCameraNodes;
|
||||
bool _ignoreCameras;
|
||||
|
||||
TransformVisitor(Matrix& matrix,CoordMode coordMode, bool ignoreCameraNodes):
|
||||
TransformVisitor(Matrix& matrix,CoordMode coordMode, bool ignoreCameras):
|
||||
NodeVisitor(),
|
||||
_coordMode(coordMode),
|
||||
_matrix(matrix),
|
||||
_ignoreCameraNodes(ignoreCameraNodes)
|
||||
_ignoreCameras(ignoreCameras)
|
||||
{}
|
||||
|
||||
virtual void apply(Transform& transform)
|
||||
@@ -56,9 +56,9 @@ class TransformVisitor : public NodeVisitor
|
||||
if (nodePath.empty()) return;
|
||||
|
||||
unsigned int i = 0;
|
||||
if (_ignoreCameraNodes)
|
||||
if (_ignoreCameras)
|
||||
{
|
||||
// we need to found out the last absolute CameraNode in NodePath and
|
||||
// we need to found out the last absolute Camera in NodePath and
|
||||
// set the i index to after it so the final accumulation set ignores it.
|
||||
i = nodePath.size();
|
||||
NodePath::const_reverse_iterator ritr;
|
||||
@@ -66,7 +66,7 @@ class TransformVisitor : public NodeVisitor
|
||||
ritr != nodePath.rend();
|
||||
++ritr, --i)
|
||||
{
|
||||
const osg::CameraNode* camera = dynamic_cast<const osg::CameraNode*>(*ritr);
|
||||
const osg::Camera* camera = dynamic_cast<const osg::Camera*>(*ritr);
|
||||
if (camera &&
|
||||
(camera->getReferenceFrame()==osg::Transform::ABSOLUTE_RF || camera->getParents().empty()))
|
||||
{
|
||||
@@ -86,35 +86,35 @@ class TransformVisitor : public NodeVisitor
|
||||
|
||||
};
|
||||
|
||||
Matrix osg::computeLocalToWorld(const NodePath& nodePath, bool ignoreCameraNodes)
|
||||
Matrix osg::computeLocalToWorld(const NodePath& nodePath, bool ignoreCameras)
|
||||
{
|
||||
Matrix matrix;
|
||||
TransformVisitor tv(matrix,TransformVisitor::LOCAL_TO_WORLD,ignoreCameraNodes);
|
||||
TransformVisitor tv(matrix,TransformVisitor::LOCAL_TO_WORLD,ignoreCameras);
|
||||
tv.accumulate(nodePath);
|
||||
return matrix;
|
||||
}
|
||||
|
||||
Matrix osg::computeWorldToLocal(const NodePath& nodePath, bool ignoreCameraNodes)
|
||||
Matrix osg::computeWorldToLocal(const NodePath& nodePath, bool ignoreCameras)
|
||||
{
|
||||
osg::Matrix matrix;
|
||||
TransformVisitor tv(matrix,TransformVisitor::WORLD_TO_LOCAL,ignoreCameraNodes);
|
||||
TransformVisitor tv(matrix,TransformVisitor::WORLD_TO_LOCAL,ignoreCameras);
|
||||
tv.accumulate(nodePath);
|
||||
return matrix;
|
||||
}
|
||||
|
||||
Matrix osg::computeLocalToEye(const Matrix& modelview,const NodePath& nodePath, bool ignoreCameraNodes)
|
||||
Matrix osg::computeLocalToEye(const Matrix& modelview,const NodePath& nodePath, bool ignoreCameras)
|
||||
{
|
||||
Matrix matrix(modelview);
|
||||
TransformVisitor tv(matrix,TransformVisitor::LOCAL_TO_WORLD,ignoreCameraNodes);
|
||||
TransformVisitor tv(matrix,TransformVisitor::LOCAL_TO_WORLD,ignoreCameras);
|
||||
tv.accumulate(nodePath);
|
||||
return matrix;
|
||||
}
|
||||
|
||||
Matrix osg::computeEyeToLocal(const Matrix& modelview,const NodePath& nodePath, bool ignoreCameraNodes)
|
||||
Matrix osg::computeEyeToLocal(const Matrix& modelview,const NodePath& nodePath, bool ignoreCameras)
|
||||
{
|
||||
Matrix matrix;
|
||||
matrix.invert(modelview);
|
||||
TransformVisitor tv(matrix,TransformVisitor::WORLD_TO_LOCAL,ignoreCameraNodes);
|
||||
TransformVisitor tv(matrix,TransformVisitor::WORLD_TO_LOCAL,ignoreCameras);
|
||||
tv.accumulate(nodePath);
|
||||
return matrix;
|
||||
}
|
||||
|
||||
190
src/osg/View.cpp
190
src/osg/View.cpp
@@ -6,7 +6,7 @@
|
||||
* 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
|
||||
* but WITHOUT ANY WARRA;NTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
@@ -15,203 +15,69 @@
|
||||
|
||||
using namespace osg;
|
||||
|
||||
// use this cull callback to allow the camera to traverse the View's children without
|
||||
// actuall having them assigned as children to the camea itself. This make the camera a
|
||||
// decorator without ever directly being assigned to it.
|
||||
class ViewCameraTraverseNodeCallback : public osg::NodeCallback
|
||||
{
|
||||
public:
|
||||
|
||||
ViewCameraTraverseNodeCallback(osg::View* view):_view(view) {}
|
||||
|
||||
virtual void operator()(osg::Node*, osg::NodeVisitor* nv)
|
||||
{
|
||||
_view->Group::traverse(*nv);
|
||||
}
|
||||
|
||||
osg::View* _view;
|
||||
};
|
||||
|
||||
|
||||
View::View()
|
||||
{
|
||||
setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
||||
}
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
View::View(const View& view,const CopyOp& copyop):
|
||||
Transform(view,copyop),
|
||||
CullSettings(view),
|
||||
_projectionMatrix(view._projectionMatrix),
|
||||
_viewMatrix(view._viewMatrix)
|
||||
{
|
||||
// need to clone the cameras.
|
||||
for(unsigned int i=0; i<view.getNumCameras(); ++i)
|
||||
{
|
||||
const CameraData& cd = view.getCameraData(i);
|
||||
addCamera(dynamic_cast<osg::CameraNode*>(cd._camera->clone(copyop)), cd._projectionOffset, cd._viewOffset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
View::~View()
|
||||
{
|
||||
// detatch the cameras from this View to prevent dangling pointers
|
||||
for(CameraList::iterator itr = _cameras.begin();
|
||||
itr != _cameras.end();
|
||||
for(Slaves::iterator itr = _slaves.begin();
|
||||
itr != _slaves.end();
|
||||
++itr)
|
||||
{
|
||||
CameraData& cd = *itr;
|
||||
Slave& cd = *itr;
|
||||
cd._camera->setView(0);
|
||||
cd._camera->setCullCallback(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Matrixd View::getInverseViewMatrix() const
|
||||
void View::updateSlaves()
|
||||
{
|
||||
Matrixd inverse;
|
||||
inverse.invert(_viewMatrix);
|
||||
return inverse;
|
||||
}
|
||||
|
||||
void View::setProjectionMatrixAsOrtho(double left, double right,
|
||||
double bottom, double top,
|
||||
double zNear, double zFar)
|
||||
{
|
||||
setProjectionMatrix(osg::Matrixd::ortho(left, right,
|
||||
bottom, top,
|
||||
zNear, zFar));
|
||||
}
|
||||
|
||||
void View::setProjectionMatrixAsOrtho2D(double left, double right,
|
||||
double bottom, double top)
|
||||
{
|
||||
setProjectionMatrix(osg::Matrixd::ortho2D(left, right,
|
||||
bottom, top));
|
||||
}
|
||||
|
||||
void View::setProjectionMatrixAsFrustum(double left, double right,
|
||||
double bottom, double top,
|
||||
double zNear, double zFar)
|
||||
{
|
||||
setProjectionMatrix(osg::Matrixd::frustum(left, right,
|
||||
bottom, top,
|
||||
zNear, zFar));
|
||||
}
|
||||
|
||||
void View::setProjectionMatrixAsPerspective(double fovy,double aspectRatio,
|
||||
double zNear, double zFar)
|
||||
{
|
||||
setProjectionMatrix(osg::Matrixd::perspective(fovy,aspectRatio,
|
||||
zNear, zFar));
|
||||
}
|
||||
|
||||
bool View::getProjectionMatrixAsOrtho(double& left, double& right,
|
||||
double& bottom, double& top,
|
||||
double& zNear, double& zFar)
|
||||
{
|
||||
return _projectionMatrix.getOrtho(left, right,
|
||||
bottom, top,
|
||||
zNear, zFar);
|
||||
}
|
||||
|
||||
bool View::getProjectionMatrixAsFrustum(double& left, double& right,
|
||||
double& bottom, double& top,
|
||||
double& zNear, double& zFar)
|
||||
{
|
||||
return _projectionMatrix.getFrustum(left, right,
|
||||
bottom, top,
|
||||
zNear, zFar);
|
||||
}
|
||||
|
||||
bool View::getProjectionMatrixAsPerspective(double& fovy,double& aspectRatio,
|
||||
double& zNear, double& zFar)
|
||||
{
|
||||
return _projectionMatrix.getPerspective(fovy, aspectRatio, zNear, zFar);
|
||||
}
|
||||
|
||||
void View::setViewMatrixAsLookAt(const Vec3& eye,const Vec3& center,const Vec3& up)
|
||||
{
|
||||
setViewMatrix(osg::Matrixd::lookAt(eye,center,up));
|
||||
}
|
||||
|
||||
void View::getViewMatrixAsLookAt(Vec3& eye,Vec3& center,Vec3& up,float lookDistance)
|
||||
{
|
||||
_viewMatrix.getLookAt(eye,center,up,lookDistance);
|
||||
}
|
||||
|
||||
|
||||
bool View::computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
|
||||
{
|
||||
if (_referenceFrame==RELATIVE_RF)
|
||||
{
|
||||
matrix.preMult(_viewMatrix);
|
||||
}
|
||||
else // absolute
|
||||
{
|
||||
matrix = _viewMatrix;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool View::computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const
|
||||
{
|
||||
const Matrixd& inverse = getInverseViewMatrix();
|
||||
|
||||
if (_referenceFrame==RELATIVE_RF)
|
||||
{
|
||||
// note doing inverse so pre becomes post.
|
||||
matrix.postMult(inverse);
|
||||
}
|
||||
else // absolute
|
||||
{
|
||||
matrix = inverse;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void View::updateCameras()
|
||||
{
|
||||
for(CameraList::iterator itr = _cameras.begin();
|
||||
itr != _cameras.end();
|
||||
if (!_camera) return;
|
||||
|
||||
for(Slaves::iterator itr = _slaves.begin();
|
||||
itr != _slaves.end();
|
||||
++itr)
|
||||
{
|
||||
CameraData& cd = *itr;
|
||||
cd._camera->setProjectionMatrix(cd._projectionOffset * _projectionMatrix);
|
||||
cd._camera->setViewMatrix(cd._viewOffset * _viewMatrix);
|
||||
cd._camera->inheritCullSettings(*this);
|
||||
Slave& cd = *itr;
|
||||
cd._camera->setProjectionMatrix(cd._projectionOffset * _camera->getProjectionMatrix());
|
||||
cd._camera->setViewMatrix(cd._viewOffset * _camera->getViewMatrix());
|
||||
cd._camera->inheritCullSettings(*_camera);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool View::addCamera(osg::CameraNode* camera, const osg::Matrix& projectionOffset, const osg::Matrix& viewOffset)
|
||||
bool View::addSlave(osg::Camera* camera, const osg::Matrix& projectionOffset, const osg::Matrix& viewOffset)
|
||||
{
|
||||
if (!camera) return false;
|
||||
|
||||
ViewCameraTraverseNodeCallback* cb = new ViewCameraTraverseNodeCallback(this);
|
||||
camera->setCullCallback(cb);
|
||||
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
||||
camera->setProjectionMatrix(projectionOffset * _projectionMatrix);
|
||||
camera->setViewMatrix(viewOffset * _viewMatrix);
|
||||
camera->inheritCullSettings(*this);
|
||||
|
||||
_cameras.push_back(CameraData(camera, projectionOffset, viewOffset));
|
||||
|
||||
if (_camera.valid())
|
||||
{
|
||||
camera->setProjectionMatrix(projectionOffset * _camera->getProjectionMatrix());
|
||||
camera->setViewMatrix(viewOffset * _camera->getViewMatrix());
|
||||
camera->inheritCullSettings(*_camera);
|
||||
}
|
||||
|
||||
_slaves.push_back(Slave(camera, projectionOffset, viewOffset));
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"Added camera"<<std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool View::removeCamera(unsigned int pos)
|
||||
bool View::removeSlave(unsigned int pos)
|
||||
{
|
||||
if (pos >= _cameras.size()) return false;
|
||||
if (pos >= _slaves.size()) return false;
|
||||
|
||||
_cameras[pos]._camera->setView(0);
|
||||
_cameras[pos]._camera->setCullCallback(0);
|
||||
_slaves[pos]._camera->setView(0);
|
||||
_slaves[pos]._camera->setCullCallback(0);
|
||||
|
||||
_cameras.erase(_cameras.begin()+pos);
|
||||
_slaves.erase(_slaves.begin()+pos);
|
||||
|
||||
osg::notify(osg::NOTICE)<<"Removed camera"<<std::endl;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user