Rotating Mesh Based on Camera Position

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.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Rotating Mesh Based on Camera Position

Post by CuteAlien »

Sorry, no idea what your moveForward is supposed to do (not saying it makes no sense, but on a quick view I couldn't figure out how it's supposed to work). Just to explain what I tried to say above how I would try to do that (not 100% sure if it works as I have no example right now, but that's how I would start):

Code: Select all

 
void Player::moveForward()
{
   irr::core::vector3df oldPos(   playerMesh->getPosition());
   irr::core::vector3df direction(0,0,1); // front of your model (the direction of the nose)
 
   cam->GetIrrCamNode()->updateAbsolutePosition();
   core::CMatrix4<float> tempMat(cam->GetIrrCamNode()->getAbsoluteTransformation());
   tempMat. rotateVect(direction);
   direction.Y = 0.f;
   direction.normalize();
   const float SPEED = 10.f; // or whatever value
   direction *= SPEED;
 
   playerMesh->setPosition(oldPos+direction);
}
 
And by using values like (1,0,0) and (0,0,-1) and (-1,0,0) instead you can move in all 4 directions.
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
GuyOnAWallaby
Posts: 15
Joined: Sat Oct 11, 2014 6:13 am

Re: Rotating Mesh Based on Camera Position

Post by GuyOnAWallaby »

Thanks that helped. I am very new to programming in 3D so not quite sure what I am doing.
Post Reply