Camera Rotation

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
NightCrawler
Posts: 20
Joined: Thu Nov 05, 2009 11:36 am

Camera Rotation

Post by NightCrawler »

Hi,
i m making a game with 3rd person camera. now when i ratate the camera on x axis it looks towards sky, it does not set its target (hero). but its rotating on y axis perfectly.
here is the code:
//Mouse Looking Void
void mouse_look()
{
//Get Mouse's Position
mousePos = device->getCursorControl()->getPosition();

//Mouse's X Movement
if(mousePos.X > lastMousePos.X)
{
char_direc+=mouse_sensitivity;
}
if(mousePos.X < lastMousePos.X)
{
char_direc-=mouse_sensitivity;
}

//Mouse's X Loop
if(lastMousePos.X>=screen_width-1)
{
device->getCursorControl()->setPosition(2,mousePos.Y);
}
if(lastMousePos.X<=1)
{
device->getCursorControl()->setPosition(screen_width-2,mousePos.Y);
}

//Make sure direction stays between -360 and 360
if(char_direc<=-360)
{
char_direc=0;
}
if(char_direc>=360)
{
char_direc=0;
}

//Mouse's Y limit
if(lastMousePos.Y>screen_height)
{
device->getCursorControl()->setPosition(mousePos.X,screen_height);
}
if(lastMousePos.Y<0)
{
device->getCursorControl()->setPosition(mousePos.X,0);
}

//Update Last Position
lastMousePos = mousePos;
}
and the setTarget:
//Place the Camera on the Character Model
camera->setTarget(tris_node->getAbsolutePosition()+vector3df(0,120-lastMousePos.Y,0));
tris_node->setRotation(vector3df(0.f, char_direc, 0.f));
can somebody tell me how to fix it.
thnks
squisher
Competition winner
Posts: 91
Joined: Sat May 17, 2008 2:23 am
Contact:

Post by squisher »

You may want to take a look at http://irrlicht.sourceforge.net/phpBB2/ ... php?t=4680

It's for free space, but could be easily adapted to land movements. Although as I re-read your post, I'm not sure I understand your question.
NightCrawler
Posts: 20
Joined: Thu Nov 05, 2009 11:36 am

Post by NightCrawler »

My problem is simple. camera rotation on x axis has some proble. as when i rotate it, the camera looks towards the sky, while it should always look at its target (the hero).
I Hate Those, Who Like To Sleep.
squisher
Competition winner
Posts: 91
Joined: Sat May 17, 2008 2:23 am
Contact:

Post by squisher »

so you're having problems pivoting?
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Post by zillion42 »

after trying to understand your question and reading your code I also dont quite know what to tell you.
All your code does is finding the mousePos and if greater lastMousePos incrementing a value char_direc, if less decrementing by another value mouse_sensitivity, setting the camera target on top of something (tris_node) with 120-lastMousePos.Y above and rotating the tris_node to you char_direc and making sure that stays between -360 - 360...
Really dont see where you rotate the camera there, and if you set the target 120 units above the character maybe thats why your camera looks to the "sky".
It's unclear what your problem is. The camera can be rotated but you're setting a target. So maybe it's just to high
NightCrawler
Posts: 20
Joined: Thu Nov 05, 2009 11:36 am

Post by NightCrawler »

Yes zillion42, right, seems that u r a good trnaslator, a little more, i think i hv almost near the mistake point :) .a little more :P .
//Place the Camera on the Character Model
camera->setTarget(tris_node->getAbsolutePosition()+vector3df(0,0-lastMousePos.Y,0));
tris_node->setRotation(vector3df(0.f, char_direc, 0.f));
now it is not rotating :shock:
I Hate Those, Who Like To Sleep.
Post Reply