I suggest:
ICameraSceneNode::setTargetNode()
ICameraSceneNode::getTargetNode()
I suggest that naming because the get method needs to be disambiguated, and the set should be consistent.
The change to example 04 is just to demonstrate the functionality, not a commit candidate.
Code: Select all
Index: examples/04.Movement/main.cpp
===================================================================
--- examples/04.Movement/main.cpp (revision 1250)
+++ examples/04.Movement/main.cpp (working copy)
@@ -183,6 +183,8 @@
scene::ICameraSceneNode * cam = smgr->addCameraSceneNodeFPS(0, 100.0f, 100.0f);
device->getCursorControl()->setVisible(false);
+ cam->setTargetNode(anms);
+
/*
Add a colorful irrlicht logo
*/
Index: include/ICameraSceneNode.h
===================================================================
--- include/ICameraSceneNode.h (revision 1250)
+++ include/ICameraSceneNode.h (working copy)
@@ -66,6 +66,15 @@
/** \return Returns the current look at target of the camera */
virtual core::vector3df getTarget() const = 0;
+ //! Sets a scene node as the look at target of the camera.
+ //! The camera will track this node's position.
+ /** \param node: Look at target of the camera. */
+ virtual void setTargetNode(ISceneNode * node) = 0;
+
+ //! Gets the current look at target node of the camera
+ /** \return Returns the current look at target node of the camera, which may be 0 */
+ virtual ISceneNode * getTargetNode() const = 0;
+
//! Sets the up vector of the camera.
/** \param pos: New upvector of the camera. */
virtual void setUpVector(const core::vector3df& pos) = 0;
Index: source/Irrlicht/CCameraSceneNode.cpp
===================================================================
--- source/Irrlicht/CCameraSceneNode.cpp (revision 1250)
+++ source/Irrlicht/CCameraSceneNode.cpp (working copy)
@@ -23,8 +23,10 @@
setDebugName("CCameraSceneNode");
#endif
+ // By default, don't track a target node
+ TargetNode = 0;
+
// set default view
-
UpVector.set(0.0f, 1.0f, 0.0f);
Target.set(lookat);
@@ -49,6 +51,8 @@
//! destructor
CCameraSceneNode::~CCameraSceneNode()
{
+ if(TargetNode)
+ TargetNode->drop();
}
@@ -125,7 +129,30 @@
}
+//! Sets a scene node as the look at target of the camera.
+//! The camera will track this node's position.
+/** \param node: Look at target of the camera. */
+void CCameraSceneNode::setTargetNode(ISceneNode * node)
+{
+ if(TargetNode)
+ TargetNode->drop();
+ TargetNode = node;
+
+ if(TargetNode)
+ TargetNode->grab();
+}
+
+//! Gets the current look at target node of the camera
+/** \return Returns the current look at target node of the camera, which may be 0 */
+ISceneNode * CCameraSceneNode::getTargetNode() const
+{
+ return TargetNode;
+}
+
+
+
+
//! sets the up vector of the camera
//! \param pos: New upvector of the camera.
void CCameraSceneNode::setUpVector(const core::vector3df& pos)
@@ -197,6 +224,12 @@
//! prerender
void CCameraSceneNode::OnRegisterSceneNode()
{
+ if(TargetNode)
+ {
+ TargetNode->updateAbsolutePosition();
+ setTarget(TargetNode->getAbsolutePosition());
+ }
+
// if upvector and vector to the target are the same, we have a
// problem. so solve this problem:
Index: source/Irrlicht/CCameraSceneNode.h
===================================================================
--- source/Irrlicht/CCameraSceneNode.h (revision 1250)
+++ source/Irrlicht/CCameraSceneNode.h (working copy)
@@ -53,6 +53,15 @@
//! \return Returns the current look at target of the camera
virtual core::vector3df getTarget() const;
+ //! Sets a scene node as the look at target of the camera.
+ //! The camera will track this node's position.
+ /** \param node: Look at target of the camera. */
+ virtual void setTargetNode(ISceneNode * node);
+
+ //! Gets the current look at target node of the camera
+ /** \return Returns the current look at target node of the camera, which may be 0 */
+ virtual ISceneNode * getTargetNode() const;
+
//! Sets the up vector of the camera.
//! \param pos: New upvector of the camera.
virtual void setUpVector(const core::vector3df& pos);
@@ -128,6 +137,8 @@
core::vector3df Target;
core::vector3df UpVector;
+ ISceneNode * TargetNode; // May be 0
+
f32 Fovy; // Field of view, in radians.
f32 Aspect; // Aspect ratio.
f32 ZNear; // value of the near view-plane.