camera->setTarget(player->getPosition()) watching in nowhere

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
acra
Posts: 3
Joined: Sat Nov 22, 2014 1:55 pm

camera->setTarget(player->getPosition()) watching in nowhere

Post by acra »

I want to implement 3rd view camera.

Code: Select all

 
...
scene::ISceneNodeAnimator* anim = mSmgr->createCollisionResponseAnimator(
        meta, camera, core::vector3df(5, 5, 5),
        core::vector3df(0, 0, 0));
meta->drop(); // done with the meta selector now
 
    camera->addAnimator(anim);
    anim->drop(); // done with the animator now
 
    // And set the camera position so that it doesn't start off stuck in the geometry
    camera->setPosition(core::vector3df(-50.0f, 50.0f, 0.0f));
    
    scene::IAnimatedMeshSceneNode* player = reinterpret_cast<scene::IAnimatedMeshSceneNode*>(mSmgr->getSceneNodeFromName("player"));
    scene::ISceneNode* gnome = mSmgr->getSceneNodeFromName("Gnome");
    player->addChild(camera);
 
And in cycle

Code: Select all

 
player->setPosition(nodePosition);
camera->setTarget(player->getPosition());
 
Camera following correctly but watching in wrong position. What I do wrong?
THANKS!

Image
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: camera->setTarget(player->getPosition()) watching in now

Post by greenya »

Try player->getAbsolutePosition()
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: camera->setTarget(player->getPosition()) watching in now

Post by CuteAlien »

Another thing (not related to your problem) - you don't have to use reinterpret_cast when casting to a base-class, it's better to just use a static_cast for that. reinterpret_cast forces the compiler to accept any kind of type conversion, so you can even do invalid casts and the compiler will no longer warn you about those. You typically only need that when you want to reinterpret what a memory locations means (meaning you know the exact bit-layout and know it will still work after the cast). Using a static_cast on the other hand will allow the compiler to check for example if a class is really derived from a base-class and thereby helps you to catch errors. Also in case of multiple inheritance the reinterpret_cast can even give you the wrong results while static_cast will be correct (the pointer-address must change when you have 2 base-classes which both are not just interfaces but need memory and you cast not to the first one).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
acra
Posts: 3
Joined: Sat Nov 22, 2014 1:55 pm

Re: camera->setTarget(player->getPosition()) watching in now

Post by acra »

Thank you all. It's working. Changed to static_cast <3
Post Reply