0

(Ogre3D) I have an camera-object, pitched about 30 degrees to the surface below.

Now, when the User presses a certain key, for example W or S, the Camera should move along the direction facing but stick to the x-y plane of the global space, like you vacuum a floor ;) I think Age of Empires for example has the same view mechanics.

    \ Camera-View Ray / User Presses W 
     \
      \  --->> desired moving direction 
       \
        \
____________________________________________________ Global Space X,Y-Plane Ground

My problem isn't the code itself but the calculating behind it. How can I extract the global x-y Plane-Direction out of a local objects facing Direction?

Thanks for your help!

  • take 3 ground points and think of them as triangle so make 2 vectors from any of its two vertices do the cross product and you have the `normal` vector of the plane ... so before translating camera by `movement`vector remove the axial part like: `movement-=dot(normal,movement)/|normal|` ... if I am not mistaken. if your cross product gets you the opposite direction vector then just negate the `normal` – Spektre Dec 13 '14 at 15:01

1 Answers1

0

I got it. If someone needs help too, here is my Ogre Code, you can extract the principe:

float coeff = 150.0f * deltaTime_s;
Ogre::Quaternion dirY(Ogre::Degree(-90), Ogre::Vector3::UNIT_Y);
    if(keyboard->isKeyDown(OIS::KC_W))
    { 
        GameManager::getSingeltonPtr()->getCameraNode()->translate 
            ( dirY* (GameManager::getSingeltonPtr()->getCameraNode()->getOrientation () * Ogre::Vector3 (-coeff, 0, 0)));
    }
    if(keyboard->isKeyDown(OIS::KC_S)){
        GameManager::getSingeltonPtr()->getCameraNode()->translate 
            ( dirY* (GameManager::getSingeltonPtr()->getCameraNode()->getOrientation () * Ogre::Vector3 (coeff, 0, 0)));
    }
    if(keyboard->isKeyDown(OIS::KC_A))
    { 
        GameManager::getSingeltonPtr()->getCameraNode()->translate 
            ( (GameManager::getSingeltonPtr()->getCameraNode()->getOrientation () * Ogre::Vector3 (-coeff, 0, 0)));

    }
    if(keyboard->isKeyDown(OIS::KC_D))
    { 
        GameManager::getSingeltonPtr()->getCameraNode()->translate 
            ( (GameManager::getSingeltonPtr()->getCameraNode()->getOrientation () * Ogre::Vector3 (coeff, 0, 0)));
    }