Minor cleanup and constification of camera node.

git-svn-id: http://svn.code.sf.net/p/irrlicht/code/trunk@1458 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
hybrid 2008-08-07 12:45:53 +00:00
parent 3a1273357a
commit 87443393ca
3 changed files with 20 additions and 45 deletions

View File

@ -31,9 +31,6 @@ namespace scene
const core::vector3df& scale = core::vector3df(1.0f,1.0f,1.0f)) const core::vector3df& scale = core::vector3df(1.0f,1.0f,1.0f))
: ISceneNode(parent, mgr, id, position, rotation, scale), IsOrthogonal(false) {} : ISceneNode(parent, mgr, id, position, rotation, scale), IsOrthogonal(false) {}
//! Destructor
virtual ~ICameraSceneNode() {}
//! Sets the projection matrix of the camera. //! Sets the projection matrix of the camera.
/** The core::matrix4 class has some methods /** The core::matrix4 class has some methods
to build a projection matrix. e.g: core::matrix4::buildProjectionMatrixPerspectiveFovLH. to build a projection matrix. e.g: core::matrix4::buildProjectionMatrixPerspectiveFovLH.
@ -66,7 +63,7 @@ namespace scene
//! Gets the current look at target of the camera //! Gets the current look at target of the camera
/** \return Returns the current look at target of the camera */ /** \return Returns the current look at target of the camera */
virtual core::vector3df getTarget() const = 0; virtual const core::vector3df& getTarget() const = 0;
//! Sets the up vector of the camera. //! Sets the up vector of the camera.
/** \param pos: New upvector of the camera. */ /** \param pos: New upvector of the camera. */
@ -74,7 +71,7 @@ namespace scene
//! Gets the up vector of the camera. //! Gets the up vector of the camera.
/** \return Returns the up vector of the camera. */ /** \return Returns the up vector of the camera. */
virtual core::vector3df getUpVector() const = 0; virtual const core::vector3df& getUpVector() const = 0;
//! Gets the value of the near plane of the camera. //! Gets the value of the near plane of the camera.
/** \return Returns the value of the near plane of the camera. */ /** \return Returns the value of the near plane of the camera. */

View File

@ -17,41 +17,29 @@ namespace scene
CCameraSceneNode::CCameraSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id, CCameraSceneNode::CCameraSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position, const core::vector3df& lookat) const core::vector3df& position, const core::vector3df& lookat)
: ICameraSceneNode(parent, mgr, id, position, core::vector3df(0.0f, 0.0f, 0.0f), : ICameraSceneNode(parent, mgr, id, position, core::vector3df(0.0f, 0.0f, 0.0f),
core::vector3df(1.0f, 1.0f, 1.0f)), InputReceiverEnabled(true) core::vector3df(1.0f, 1.0f, 1.0f)),
Target(lookat), UpVector(0.0f, 1.0f, 0.0f), ZNear(1.0f), ZFar(3000.0f),
InputReceiverEnabled(true)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CCameraSceneNode"); setDebugName("CCameraSceneNode");
#endif #endif
// set default view
UpVector.set(0.0f, 1.0f, 0.0f);
Target.set(lookat);
// set default projection // set default projection
Fovy = core::PI / 2.5f; // Field of view, in radians. Fovy = core::PI / 2.5f; // Field of view, in radians.
Aspect = 4.0f / 3.0f; // Aspect ratio.
ZNear = 1.0f; // value of the near view-plane.
ZFar = 3000.0f; // Z-value of the far view-plane.
video::IVideoDriver* d = mgr->getVideoDriver(); const video::IVideoDriver* const d = mgr?mgr->getVideoDriver():0;
if (d) if (d)
Aspect = (f32)d->getCurrentRenderTargetSize().Width / Aspect = (f32)d->getCurrentRenderTargetSize().Width /
(f32)d->getCurrentRenderTargetSize().Height; (f32)d->getCurrentRenderTargetSize().Height;
else
Aspect = 4.0f / 3.0f; // Aspect ratio.
recalculateProjectionMatrix(); recalculateProjectionMatrix();
recalculateViewArea(); recalculateViewArea();
} }
//! destructor
CCameraSceneNode::~CCameraSceneNode()
{
}
//! Disables or enables the camera to get key or mouse inputs. //! Disables or enables the camera to get key or mouse inputs.
void CCameraSceneNode::setInputReceiverEnabled(bool enabled) void CCameraSceneNode::setInputReceiverEnabled(bool enabled)
{ {
@ -78,7 +66,6 @@ void CCameraSceneNode::setProjectionMatrix(const core::matrix4& projection, bool
} }
//! Gets the current projection matrix of the camera //! Gets the current projection matrix of the camera
//! \return Returns the current projection matrix of the camera. //! \return Returns the current projection matrix of the camera.
const core::matrix4& CCameraSceneNode::getProjectionMatrix() const const core::matrix4& CCameraSceneNode::getProjectionMatrix() const
@ -87,7 +74,6 @@ const core::matrix4& CCameraSceneNode::getProjectionMatrix() const
} }
//! Gets the current view matrix of the camera //! Gets the current view matrix of the camera
//! \return Returns the current view matrix of the camera. //! \return Returns the current view matrix of the camera.
const core::matrix4& CCameraSceneNode::getViewMatrix() const const core::matrix4& CCameraSceneNode::getViewMatrix() const
@ -96,7 +82,6 @@ const core::matrix4& CCameraSceneNode::getViewMatrix() const
} }
//! It is possible to send mouse and key events to the camera. Most cameras //! It is possible to send mouse and key events to the camera. Most cameras
//! may ignore this input, but camera scene nodes which are created for //! may ignore this input, but camera scene nodes which are created for
//! example with scene::ISceneManager::addMayaCameraSceneNode or //! example with scene::ISceneManager::addMayaCameraSceneNode or
@ -120,7 +105,6 @@ bool CCameraSceneNode::OnEvent(const SEvent& event)
} }
//! sets the look at target of the camera //! sets the look at target of the camera
//! \param pos: Look at target of the camera. //! \param pos: Look at target of the camera.
void CCameraSceneNode::setTarget(const core::vector3df& pos) void CCameraSceneNode::setTarget(const core::vector3df& pos)
@ -129,16 +113,14 @@ void CCameraSceneNode::setTarget(const core::vector3df& pos)
} }
//! Gets the current look at target of the camera //! Gets the current look at target of the camera
//! \return Returns the current look at target of the camera //! \return Returns the current look at target of the camera
core::vector3df CCameraSceneNode::getTarget() const const core::vector3df& CCameraSceneNode::getTarget() const
{ {
return Target; return Target;
} }
//! sets the up vector of the camera //! sets the up vector of the camera
//! \param pos: New upvector of the camera. //! \param pos: New upvector of the camera.
void CCameraSceneNode::setUpVector(const core::vector3df& pos) void CCameraSceneNode::setUpVector(const core::vector3df& pos)
@ -147,10 +129,9 @@ void CCameraSceneNode::setUpVector(const core::vector3df& pos)
} }
//! Gets the up vector of the camera. //! Gets the up vector of the camera.
//! \return Returns the up vector of the camera. //! \return Returns the up vector of the camera.
core::vector3df CCameraSceneNode::getUpVector() const const core::vector3df& CCameraSceneNode::getUpVector() const
{ {
return UpVector; return UpVector;
} }
@ -161,45 +142,53 @@ f32 CCameraSceneNode::getNearValue() const
return ZNear; return ZNear;
} }
f32 CCameraSceneNode::getFarValue() const f32 CCameraSceneNode::getFarValue() const
{ {
return ZFar; return ZFar;
} }
f32 CCameraSceneNode::getAspectRatio() const f32 CCameraSceneNode::getAspectRatio() const
{ {
return Aspect; return Aspect;
} }
f32 CCameraSceneNode::getFOV() const f32 CCameraSceneNode::getFOV() const
{ {
return Fovy; return Fovy;
} }
void CCameraSceneNode::setNearValue(f32 f) void CCameraSceneNode::setNearValue(f32 f)
{ {
ZNear = f; ZNear = f;
recalculateProjectionMatrix(); recalculateProjectionMatrix();
} }
void CCameraSceneNode::setFarValue(f32 f) void CCameraSceneNode::setFarValue(f32 f)
{ {
ZFar = f; ZFar = f;
recalculateProjectionMatrix(); recalculateProjectionMatrix();
} }
void CCameraSceneNode::setAspectRatio(f32 f) void CCameraSceneNode::setAspectRatio(f32 f)
{ {
Aspect = f; Aspect = f;
recalculateProjectionMatrix(); recalculateProjectionMatrix();
} }
void CCameraSceneNode::setFOV(f32 f) void CCameraSceneNode::setFOV(f32 f)
{ {
Fovy = f; Fovy = f;
recalculateProjectionMatrix(); recalculateProjectionMatrix();
} }
void CCameraSceneNode::recalculateProjectionMatrix() void CCameraSceneNode::recalculateProjectionMatrix()
{ {
ViewArea.Matrices [ video::ETS_PROJECTION ].buildProjectionMatrixPerspectiveFovLH(Fovy, Aspect, ZNear, ZFar); ViewArea.Matrices [ video::ETS_PROJECTION ].buildProjectionMatrixPerspectiveFovLH(Fovy, Aspect, ZNear, ZFar);
@ -238,7 +227,6 @@ void CCameraSceneNode::OnRegisterSceneNode()
} }
//! render //! render
void CCameraSceneNode::render() void CCameraSceneNode::render()
{ {
@ -258,17 +246,12 @@ const core::aabbox3d<f32>& CCameraSceneNode::getBoundingBox() const
} }
//! returns the view frustum. needed sometimes by bsp or lod render nodes. //! returns the view frustum. needed sometimes by bsp or lod render nodes.
const SViewFrustum* CCameraSceneNode::getViewFrustum() const const SViewFrustum* CCameraSceneNode::getViewFrustum() const
{ {
return &ViewArea; return &ViewArea;
} }
core::vector3df CCameraSceneNode::getAbsolutePosition() const
{
return AbsoluteTransformation.getTranslation();
}
void CCameraSceneNode::recalculateViewArea() void CCameraSceneNode::recalculateViewArea()
{ {

View File

@ -22,9 +22,6 @@ namespace scene
const core::vector3df& position = core::vector3df(0,0,0), const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& lookat = core::vector3df(0,0,100)); const core::vector3df& lookat = core::vector3df(0,0,100));
//! destructor
virtual ~CCameraSceneNode();
//! Sets the projection matrix of the camera. //! Sets the projection matrix of the camera.
/** The core::matrix4 class has some methods /** The core::matrix4 class has some methods
to build a projection matrix. e.g: core::matrix4::buildProjectionMatrixPerspectiveFovLH. to build a projection matrix. e.g: core::matrix4::buildProjectionMatrixPerspectiveFovLH.
@ -56,7 +53,7 @@ namespace scene
//! Gets the current look at target of the camera //! Gets the current look at target of the camera
//! \return Returns the current look at target of the camera //! \return Returns the current look at target of the camera
virtual core::vector3df getTarget() const; virtual const core::vector3df& getTarget() const;
//! Sets the up vector of the camera. //! Sets the up vector of the camera.
//! \param pos: New upvector of the camera. //! \param pos: New upvector of the camera.
@ -64,7 +61,7 @@ namespace scene
//! Gets the up vector of the camera. //! Gets the up vector of the camera.
//! \return Returns the up vector of the camera. //! \return Returns the up vector of the camera.
virtual core::vector3df getUpVector() const; virtual const core::vector3df& getUpVector() const;
//! Gets distance from the camera to the near plane. //! Gets distance from the camera to the near plane.
//! \return Value of the near plane of the camera. //! \return Value of the near plane of the camera.
@ -123,8 +120,6 @@ namespace scene
//! Returns type of the scene node //! Returns type of the scene node
virtual ESCENE_NODE_TYPE getType() const { return ESNT_CAMERA; } virtual ESCENE_NODE_TYPE getType() const { return ESNT_CAMERA; }
virtual core::vector3df getAbsolutePosition() const;
protected: protected:
void recalculateProjectionMatrix(); void recalculateProjectionMatrix();