Moving camera

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
Velud
Posts: 6
Joined: Thu Jan 01, 2009 8:01 pm

Moving camera

Post by Velud »

I try to move camera by arrows
it normally movs by X axis? but it rotates arond Y, when I move it by Z axis

this s a method of my class
cpos is a temporary vector
pCamera is a pointer to object created with AddCameraSceneNode()

Code: Select all

void Move(irr::EKEY_CODE k)
	{
		this->cpos=this->pCamera->getPosition();
		int fps = driver->getFPS();
		float dist;

		if (fps > 1)
			dist = 200.0f / fps;
		else
			dist = 1.0f;   
		switch(k)
		{
		case KEY_UP:
			{
				this->cpos.X+=dist;
			}
			break;
		case KEY_DOWN:
			this->cpos.X-=dist;
			break;

		case KEY_LEFT:
			this->cpos.Z+=dist;
			break;
		case KEY_RIGHT:
			this->cpos.Z-=dist;
			break;
		default:
			break;
		}
		pCamera->setPosition(cpos);
	}
What can change the nature of man?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

You also need to move the target (use camera->setTarget), or the camera will continue to look at the same point in space.
Also, the cross product of the target's direction and the camera's up vector will give you a better sideways direction:
http://www.phy.syr.edu/courses/java-suite/crosspro.html
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Velud
Posts: 6
Joined: Thu Jan 01, 2009 8:01 pm

Post by Velud »

you mean increment both position and target?
camera rotates right and left on up/down arrows and moves back forward on left right arrows.
and what absolute postion mean?
What can change the nature of man?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Yes, both the position and target or the camera will appear to rotate.
Absolute position is the position in world space, relative position is the offset from the node's parent.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Velud
Posts: 6
Joined: Thu Jan 01, 2009 8:01 pm

Post by Velud »

But what I have to do for move camera?
What can change the nature of man?
Velud
Posts: 6
Joined: Thu Jan 01, 2009 8:01 pm

Post by Velud »

up
What can change the nature of man?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

how do you want to move the camera up? Do you want it to work like the FPS camera and move up when you look up? (which would lead me to ask why you're not using the FPS camera in the first place...)
Image Image Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

:lol:
Anyway, you can move cameras just as usual scene nodes, so check tutorial 4. The only thing which might be astonishing is that you can rotate a camera, but it won't rotate its view. But that was already handled some posts before...
Post Reply