Best way to control camera manually

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
tracerx
Posts: 19
Joined: Thu Feb 26, 2009 6:36 am

Best way to control camera manually

Post by tracerx »

I've got existing code that gives me a height above the terrain, and a
heading in degrees. I'm trying to get the camera situated height-wise,
and make sure it always pointed straight ahead as I manually move my
character position across the terrain based on heading (it's legacy code).


I noticed after I call (in the setup)

Code: Select all

m_pCamera =m_pSmgr->addCameraSceneNodeFPS(m_pParent,100.0f,1.2f);
	m_pCamera->setPosition(core::vector3df(2700*2,255*2,2600*2));
	m_pCamera->setTarget(core::vector3df(2397*2,343*2,2700*2));
	m_pCamera->setFarValue(42000.0f);
that manipulating it to try and get the camera higher with something like

Code: Select all

	m_pCamera->setPosition(core::vector3df(2700*2,255*8,2600*2));
Leaves the camera pointing down instead of straight ahead. I'm guessing
this is because the camera lookat hasn't changed. So how do I keep that
straight ahead?


How do I position the scene based on a heading in degrees?

I'm currently using (in the render loop)

Code: Select all

		//handle movement
		core::vector3df nodePosition = m_pCamera->getPosition();
		//based on the heading set X and Z
		float fHeadingRadians = ((m_pMe->m_iHeading/m_pMe->ANGLE_1) * PI)/180;
		nodePosition.X -= (m_pMe->m_iSpeed*cos(fHeadingRadians));
		nodePosition.Z += (m_pMe->m_iSpeed*sin(fHeadingRadians));
		m_pCamera->setPosition(nodePosition);


thanks![/code]
Nimrod
Posts: 8
Joined: Sun Feb 22, 2009 8:10 pm

Post by Nimrod »

So how do I keep that straight ahead?
Move the target with setTarget as well?
tracerx
Posts: 19
Joined: Thu Feb 26, 2009 6:36 am

Post by tracerx »

Nimrod wrote:
So how do I keep that straight ahead?
Move the target with setTarget as well?
Setting the target y to 0 did the trick. Maybe this has something to do with the way the FPS camera is setup.

Code: Select all

	m_pCamera = m_pSmgr->addCameraSceneNodeFPS(m_pParent,100.0f,1.2f);
	m_pCamera->setPosition(core::vector3df(2700*2,2600,2600*2));
	m_pCamera->setTarget(core::vector3df(2397*2,0,2700*2));
Then I added this to handle the movement and rotation.

Code: Select all

		core::vector3df nodePosition = m_pCamera->getPosition();
		float fHeading = ((float)m_pMe->m_iHeading/(float)m_pMe->ANGLE_1);
		float fHeadingRadians = (fHeading * PI)/180;
		nodePosition.X -= ((m_pMe->m_iSpeed*cos(fHeadingRadians)));
		nodePosition.Z += ((m_pMe->m_iSpeed*sin(fHeadingRadians)));
		m_pCamera->setPosition(nodePosition);
		float x = m_pCamera->getRotation().X;
		float z = m_pCamera->getRotation().Z;
		float y = m_pCamera->getRotation().Y;
		m_pCamera->setRotation(core::vector3df( x , 270+fHeading, z ) );
Post Reply