Page 1 of 1

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

Posted: Tue Nov 25, 2014 8:31 pm
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

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

Posted: Tue Nov 25, 2014 9:51 pm
by greenya
Try player->getAbsolutePosition()

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

Posted: Wed Nov 26, 2014 12:07 pm
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).

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

Posted: Wed Nov 26, 2014 1:27 pm
by acra
Thank you all. It's working. Changed to static_cast <3