Set Rotation to Point

Fdot
Posts: 6
Joined: Wed Sep 29, 2010 8:02 am

Set Rotation to Point

Post by Fdot »

Hi,

I tried to rotate a object so it looks to a given point. But I don't get it. Is there a possibility to solve that?
Fdot
Posts: 6
Joined: Wed Sep 29, 2010 8:02 am

Re: Set Rotation to Point

Post by Fdot »

Okay I solved this by using Ogre3D. Maybe someone got the same problem and has also Ogre3D. So here the code:

Code: Select all

    void BodyHandler::SetOrientation(std::string strObjectID, std::string strObjectID2)
    {
        Ogre::SceneNode *SceneNode1 = Scenegraph::GetSingleton().GetSceneNode(strObjectID);
        Ogre::Vector3 vec3Pos1 = SceneNode1->getPosition();

        Ogre::SceneNode *SceneNode2 = Scenegraph::GetSingleton().GetSceneNode(strObjectID2);
        Ogre::Vector3 vec3Pos2 = SceneNode2->getPosition();
        vec3Pos2 = Ogre::Vector3(vec3Pos2.x, 0, vec3Pos2.z);
        SceneNode1->lookAt(vec3Pos2, Ogre::Node::TS_WORLD, Vector3::UNIT_Z    );
        Ogre::Quaternion Q = SceneNode1->getOrientation();

        btTransform transform;
        transform.setOrigin(btVector3(vec3Pos1.x, vec3Pos1.y, vec3Pos1.z));
        transform.setRotation(btQuaternion(Q.x, Q.y, Q.z, Q.w));

        mapBodies[strObjectID]->setWorldTransform(transform);
    }
Some comments:
strObjectID and strObjectID2 are the names of the scenenodes. strObjectID is the node which rotates and strObjectID2 is the position to rotate against. I only want to rotate round the Y axis, so I set the y coord. to 0.