Page 1 of 1

Moving camera

Posted: Sat Jan 03, 2009 1:51 pm
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);
	}

Posted: Sat Jan 03, 2009 3:22 pm
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

Posted: Sat Jan 03, 2009 4:58 pm
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?

Posted: Sat Jan 03, 2009 5:25 pm
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.

Posted: Sat Jan 03, 2009 6:01 pm
by Velud
But what I have to do for move camera?

Posted: Mon Jan 05, 2009 10:50 am
by Velud
up

Posted: Mon Jan 05, 2009 11:12 am
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...)

Posted: Mon Jan 05, 2009 12:15 pm
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...