camera movement problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
me

camera movement problem

Post by me »

Okay, I know how to create a scene node, add a mesh to it, and stick a camera on it. I even figured out how to capture key input and manipulate my node with it (move it, whatever). Howevever, when I move the node, the mesh connected to it does not move like it should, and the camera target changes, not its position. Here's the code:

Code: Select all

...
ICameraSceneNode* camera = 0;
IAnimatedMeshSceneNode* animNode = 0;


//This is a simple internal class that handles input for camera motion
//TODO: seperate this into its own class and make it more robust.
class MyEventReceiver : public IEventReceiver{
public:
	virtual bool OnEvent(SEvent event) {
		if(animNode != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown) {
			switch(event.KeyInput.Key)
			{
			case KEY_KEY_W :
			case KEY_KEY_S : {
				vector3df v = animNode->getPosition();
				v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
				animNode->setPosition(v);
				}//end case
			}//end switch
		}//end if

    return false;
	}//end method
};//end class
...
IAnimatedMesh* mesh = smgr->getMesh("media\\sydney.md2");
	animNode = smgr->addAnimatedMeshSceneNode(mesh);

	//The next commented out lines turns off lighting, sets an
	//animation loop for the mesh, and gives the mesh a texture.
	if(animNode) {
		animNode->setFrameLoop(0,1000);
		animNode->setMaterialTexture(0, driver->getTexture("media\\sydney.bmp"));
	}//end if

...
ISceneNode* node = 0;
...
camera = smgr->addCameraSceneNode(animNode, vector3df(0,10,-10), vector3df(0,0,10));
...
sorry about all the elipses, but those are just setting up a skybox, map, what-have-you.

Any help would be apreciated!

Thanx,
Me.
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

Actually, I would expect the position to remain constant in relation to your mesh, but the target to move (or from the world view, continue pointing at (0,0,10) while the position moves). To fix this, at the end of the W/S case, update the camera's target.

eg: camera->setTarget(v+vector3df(0,0,10));
Post Reply