Commit 70a1d335 authored by hybrid's avatar hybrid

Added ViewMatrix affector, proposed by mandrav.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2315 dfc29bdd-3216-0410-991c-e03cc46cb475
parent c8bdc67d
...@@ -42,15 +42,26 @@ namespace scene ...@@ -42,15 +42,26 @@ namespace scene
\param isOrthogonal Set this to true if the matrix is an \param isOrthogonal Set this to true if the matrix is an
orthogonal one (e.g. from matrix4::buildProjectionMatrixOrtho). orthogonal one (e.g. from matrix4::buildProjectionMatrixOrtho).
*/ */
virtual void setProjectionMatrix(const core::matrix4& projection, bool isOrthogonal = false) = 0; virtual void setProjectionMatrix(const core::matrix4& projection, bool isOrthogonal=false) =0;
//! Gets the current projection matrix of the camera. //! Gets the current projection matrix of the camera.
/** \return The current projection matrix of the camera. */ /** \return The current projection matrix of the camera. */
virtual const core::matrix4& getProjectionMatrix() const = 0; virtual const core::matrix4& getProjectionMatrix() const =0;
//! Gets the current view matrix of the camera. //! Gets the current view matrix of the camera.
/** \return The current view matrix of the camera. */ /** \return The current view matrix of the camera. */
virtual const core::matrix4& getViewMatrix() const = 0; virtual const core::matrix4& getViewMatrix() const =0;
//! Sets a custom view matrix affector.
/** The matrix passed here, will be multiplied with the view
matrix when it gets updated. This allows for custom camera
setups like, for example, a reflection camera.
\param affector The affector matrix. */
virtual void setViewMatrixAffector(const core::matrix4& affector) =0;
//! Get the custom view matrix affector.
/** \return The affector matrix. */
virtual const core::matrix4& getViewMatrixAffector() const =0;
//! It is possible to send mouse and key events to the camera. //! It is possible to send mouse and key events to the camera.
/** Most cameras may ignore this input, but camera scene nodes /** Most cameras may ignore this input, but camera scene nodes
...@@ -59,14 +70,14 @@ namespace scene ...@@ -59,14 +70,14 @@ namespace scene
ISceneManager::addCameraSceneNodeFPS, may want to get ISceneManager::addCameraSceneNodeFPS, may want to get
this input for changing their position, look at target or this input for changing their position, look at target or
whatever. */ whatever. */
virtual bool OnEvent(const SEvent& event) = 0; virtual bool OnEvent(const SEvent& event) =0;
//! Sets the look at target of the camera //! Sets the look at target of the camera
/** If the camera's target and rotation are bound ( @see /** If the camera's target and rotation are bound ( @see
bindTargetAndRotation() ) then calling this will also change bindTargetAndRotation() ) then calling this will also change
the camera's scene node rotation to match the target. the camera's scene node rotation to match the target.
\param pos Look at target of the camera, in world co-ordinates. */ \param pos Look at target of the camera, in world co-ordinates. */
virtual void setTarget(const core::vector3df& pos) = 0; virtual void setTarget(const core::vector3df& pos) =0;
//! Sets the rotation of the node. //! Sets the rotation of the node.
/** This only modifies the relative rotation of the node. /** This only modifies the relative rotation of the node.
...@@ -74,64 +85,64 @@ namespace scene ...@@ -74,64 +85,64 @@ namespace scene
bindTargetAndRotation() ) then calling this will also change bindTargetAndRotation() ) then calling this will also change
the camera's target to match the rotation. the camera's target to match the rotation.
\param rotation New rotation of the node in degrees. */ \param rotation New rotation of the node in degrees. */
virtual void setRotation(const core::vector3df& rotation) = 0; virtual void setRotation(const core::vector3df& rotation) =0;
//! Gets the current look at target of the camera //! Gets the current look at target of the camera
/** \return The current look at target of the camera, in world co-ordinates */ /** \return The current look at target of the camera, in world co-ordinates */
virtual const 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. */
virtual void setUpVector(const core::vector3df& pos) = 0; virtual void setUpVector(const core::vector3df& pos) =0;
//! Gets the up vector of the camera. //! Gets the up vector of the camera.
/** \return The up vector of the camera, in world space. */ /** \return The up vector of the camera, in world space. */
virtual const 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 The value of the near plane of the camera. */ /** \return The value of the near plane of the camera. */
virtual f32 getNearValue() const = 0; virtual f32 getNearValue() const =0;
//! Gets the value of the far plane of the camera. //! Gets the value of the far plane of the camera.
/** \return The value of the far plane of the camera. */ /** \return The value of the far plane of the camera. */
virtual f32 getFarValue() const = 0; virtual f32 getFarValue() const =0;
//! Gets the aspect ratio of the camera. //! Gets the aspect ratio of the camera.
/** \return The aspect ratio of the camera. */ /** \return The aspect ratio of the camera. */
virtual f32 getAspectRatio() const = 0; virtual f32 getAspectRatio() const =0;
//! Gets the field of view of the camera. //! Gets the field of view of the camera.
/** \return The field of view of the camera in radiants. */ /** \return The field of view of the camera in radiants. */
virtual f32 getFOV() const = 0; virtual f32 getFOV() const =0;
//! Sets the value of the near clipping plane. (default: 1.0f) //! Sets the value of the near clipping plane. (default: 1.0f)
/** \param zn: New z near value. */ /** \param zn: New z near value. */
virtual void setNearValue(f32 zn) = 0; virtual void setNearValue(f32 zn) =0;
//! Sets the value of the far clipping plane (default: 2000.0f) //! Sets the value of the far clipping plane (default: 2000.0f)
/** \param zf: New z far value. */ /** \param zf: New z far value. */
virtual void setFarValue(f32 zf) = 0; virtual void setFarValue(f32 zf) =0;
//! Sets the aspect ratio (default: 4.0f / 3.0f) //! Sets the aspect ratio (default: 4.0f / 3.0f)
/** \param aspect: New aspect ratio. */ /** \param aspect: New aspect ratio. */
virtual void setAspectRatio(f32 aspect) = 0; virtual void setAspectRatio(f32 aspect) =0;
//! Sets the field of view (Default: PI / 2.5f) //! Sets the field of view (Default: PI / 2.5f)
/** \param fovy: New field of view in radiants. */ /** \param fovy: New field of view in radiants. */
virtual void setFOV(f32 fovy) = 0; virtual void setFOV(f32 fovy) =0;
//! Get the view frustum. //! Get the view frustum.
/** Needed sometimes by bspTree or LOD render nodes. /** Needed sometimes by bspTree or LOD render nodes.
\return The current view frustum. */ \return The current view frustum. */
virtual const SViewFrustum* getViewFrustum() const = 0; virtual const SViewFrustum* getViewFrustum() const =0;
//! Disables or enables the camera to get key or mouse inputs. //! Disables or enables the camera to get key or mouse inputs.
/** If this is set to true, the camera will respond to key /** If this is set to true, the camera will respond to key
inputs otherwise not. */ inputs otherwise not. */
virtual void setInputReceiverEnabled(bool enabled) = 0; virtual void setInputReceiverEnabled(bool enabled) =0;
//! Checks if the input receiver of the camera is currently enabled. //! Checks if the input receiver of the camera is currently enabled.
virtual bool isInputReceiverEnabled() const = 0; virtual bool isInputReceiverEnabled() const =0;
//! Checks if a camera is orthogonal. //! Checks if a camera is orthogonal.
virtual bool isOrthogonal() const virtual bool isOrthogonal() const
...@@ -149,11 +160,11 @@ namespace scene ...@@ -149,11 +160,11 @@ namespace scene
\param bound True to bind the camera's scene node rotation \param bound True to bind the camera's scene node rotation
and targetting, false to unbind them. and targetting, false to unbind them.
@see getTargetAndRotationBinding() */ @see getTargetAndRotationBinding() */
virtual void bindTargetAndRotation(bool bound) = 0; virtual void bindTargetAndRotation(bool bound) =0;
//! Queries if the camera scene node's rotation and its target position are bound together. //! Queries if the camera scene node's rotation and its target position are bound together.
/** @see bindTargetAndRotation() */ /** @see bindTargetAndRotation() */
virtual bool getTargetAndRotationBinding(void) const = 0; virtual bool getTargetAndRotationBinding(void) const =0;
protected: protected:
......
...@@ -81,6 +81,23 @@ const core::matrix4& CCameraSceneNode::getViewMatrix() const ...@@ -81,6 +81,23 @@ const core::matrix4& CCameraSceneNode::getViewMatrix() const
} }
//! Sets a custom view matrix affector. The matrix passed here, will be
//! multiplied with the view matrix when it gets updated.
//! This allows for custom camera setups like, for example, a reflection camera.
/** \param affector: The affector matrix. */
void CCameraSceneNode::setViewMatrixAffector(const core::matrix4& affector)
{
Affector = affector;
}
//! Gets the custom view matrix affector.
const core::matrix4& CCameraSceneNode::getViewMatrixAffector() const
{
return Affector;
}
//! 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
...@@ -233,7 +250,8 @@ void CCameraSceneNode::OnRegisterSceneNode() ...@@ -233,7 +250,8 @@ void CCameraSceneNode::OnRegisterSceneNode()
up.X += 0.5f; up.X += 0.5f;
} }
ViewArea.getTransform( video::ETS_VIEW ).buildCameraLookAtMatrixLH(pos, Target, up); ViewArea.getTransform(video::ETS_VIEW).buildCameraLookAtMatrixLH(pos, Target, up);
ViewArea.getTransform(video::ETS_VIEW) *= Affector;
recalculateViewArea(); recalculateViewArea();
if ( SceneManager->getActiveCamera () == this ) if ( SceneManager->getActiveCamera () == this )
...@@ -273,10 +291,9 @@ void CCameraSceneNode::recalculateViewArea() ...@@ -273,10 +291,9 @@ void CCameraSceneNode::recalculateViewArea()
{ {
ViewArea.cameraPosition = getAbsolutePosition(); ViewArea.cameraPosition = getAbsolutePosition();
core::matrix4 m ( core::matrix4::EM4CONST_NOTHING ); core::matrix4 m(core::matrix4::EM4CONST_NOTHING);
m.setbyproduct_nocheck ( ViewArea.getTransform (video::ETS_PROJECTION), m.setbyproduct_nocheck(ViewArea.getTransform(video::ETS_PROJECTION),
ViewArea.getTransform (video::ETS_VIEW) ViewArea.getTransform(video::ETS_VIEW));
);
ViewArea.setFrom(m); ViewArea.setFrom(m);
} }
......
...@@ -40,6 +40,13 @@ namespace scene ...@@ -40,6 +40,13 @@ namespace scene
//! \return Returns the current view matrix of the camera. //! \return Returns the current view matrix of the camera.
virtual const core::matrix4& getViewMatrix() const; virtual const core::matrix4& getViewMatrix() const;
//! Sets a custom view matrix affector.
/** \param affector: The affector matrix. */
virtual void setViewMatrixAffector(const core::matrix4& affector);
//! Gets the custom view matrix affector.
virtual const core::matrix4& getViewMatrixAffector() 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
...@@ -149,9 +156,9 @@ namespace scene ...@@ -149,9 +156,9 @@ namespace scene
f32 ZFar; // Z-value of the far view-plane. f32 ZFar; // Z-value of the far view-plane.
SViewFrustum ViewArea; SViewFrustum ViewArea;
core::matrix4 Affector;
bool InputReceiverEnabled; bool InputReceiverEnabled;
bool TargetAndRotationAreBound; bool TargetAndRotationAreBound;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment