rotating camera help

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
chronos1981
Posts: 8
Joined: Wed Mar 19, 2008 12:03 pm

rotating camera help

Post by chronos1981 »

Hi im new to IRRLICHT and im working on a rpg style game. So I need a camera that works like a rpg camera. I have read alot of stuff and searched the api (hard to read the api used to msdn) but just don't get it yet. I don't want someone to give me the code just point me in the right direction. How do i rotate the camera around a fixed point? I want something simular to the maya camera. Any help is appriciated THANKS!
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: rotating camera help

Post by randomMesh »

chronos1981 wrote:...works like a rpg camera.
What's an rpg camera?
chronos1981 wrote:How do i rotate the camera around a fixed point?
Using spherical coordinates should do the trick.
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=17033

Use the for.. er... the search button Luke.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

There's lots of 3rd person/RPG cameras on this forum if you search for them.

To rotate the camera you have to use setTarget() as the camera effectively ignores anything provided to setRotation().
Image Image Image
chronos1981
Posts: 8
Joined: Wed Mar 19, 2008 12:03 pm

Post by chronos1981 »

Thanks for the quick replys JP and randomMesh
Using spherical coordinates should do the trick.
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=17033
That's what I thought. I was just hoping for an already existing command, but I figured it out today.

Code: Select all

while(device->run())
	{

		if (fw) //forward
		{
		    hero->setPosition(hero->getPosition()-vector3df(sin(h*(pi/180))*10,0,cos(h*(pi/180))*10));
			camera->setPosition(hero->getPosition()+ vector3df( sin(h*(pi/180))*cos(v*(pi/180))*d,sin(v*(pi/180))*d,cos(h*(pi/180))*cos(v*(pi/180))*d  ));			
			camera->setTarget(hero->getPosition());
		}
		if (lt) //left
		{
		
			camera->setPosition(hero->getPosition()+ vector3df( sin(h*(pi/180))*cos(v*(pi/180))*d,sin(v*(pi/180))*d,cos(h*(pi/180))*cos(v*(pi/180))*d  ));			
			camera->setTarget(hero->getPosition());
		}

		if (rt) //right
		{
		
			camera->setPosition(hero->getPosition()+ vector3df( sin(h*(pi/180))*cos(v*(pi/180))*d,sin(v*(pi/180))*d,cos(h*(pi/180))*cos(v*(pi/180))*d  ));
			camera->setTarget(hero->getPosition());
		}
		if (down)
		{
			camera->setPosition(hero->getPosition()+ vector3df( sin(h*(pi/180))*cos(v*(pi/180))*d,sin(v*(pi/180))*d,cos(h*(pi/180))*cos(v*(pi/180))*d  ));
			camera->setTarget(hero->getPosition());
		}

		if (up)
		{
			camera->setPosition(hero->getPosition()+ vector3df( sin(h*(pi/180))*cos(v*(pi/180))*d,sin(v*(pi/180))*d,cos(h*(pi/180))*cos(v*(pi/180))*d  ));
			camera->setTarget(hero->getPosition());
		}
I could simplify the code I know the if statements up, down, lt and rt all do the same thing just had it like this for debugging.

To any one reading this post who is new to c++ when using sin or cos you have to convert you angle in degrees to radians, just multiply degrees by (pi/180), this annoyed me for hours. Hope this helps anyone else.

JP I enjoyed your Avatar Pinhead playing with a rubik's cube, woot.
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

There is actually a built-in Irrlicht macro called DEGTORAD, and RADTODEG. Those would sure help you, and that would make your code much more readable.
TheQuestion = 2B || !2B
Post Reply