Page 1 of 1

ICameraSceneNode problems

Posted: Mon Jan 24, 2011 2:07 am
by [DEF]
I'm having problems moving an ICameraSceneNode, it's seems that whenever I go to move it, it points in some weird direction, until I stop moving it. Might be better explained with some code:

Code: Select all

ICameraSceneNode* camera = smgr->addCameraSceneNode();
camera->bindTargetAndRotation(true);

......

cursorPosition = device->getCursorControl()->getPosition();
device->getCursorControl()->setPosition(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
double mouseMultiplier = 0.25;
lookAngle_y += (cursorPosition.X-(SCREEN_WIDTH/2))*mouseMultiplier;
lookAngle_x += (cursorPosition.Y-(SCREEN_HEIGHT/2))*mouseMultiplier;
            
camera->setRotation(vector3df(lookAngle_x, lookAngle_y, 0));
            
if (receiver.IsKeyDown(KEY_KEY_W)) {
        camera->setPosition(camera->getPosition() + vector3df(0, 1, 0));
}

Posted: Mon Jan 24, 2011 5:22 am
by lazerblade
You have to handle the look at target and the up vector and gimbal lock and local rotation if you want to transform the camera. My recommendation is that you just use a pre-made camera handling class like this one:

http://irrlicht.sourceforge.net/phpBB2/ ... 5&start=15

8)

Posted: Mon Jan 24, 2011 1:40 pm
by [DEF]
Ahaha!! Yes, your camera class is very well set out, thankyou!! :D I've seen other code snippets on the forum that also do it similar. But yours look quite complete!

Posted: Mon Jan 24, 2011 3:02 pm
by lazerblade
Thank you, :D