【问题标题】:Casting an (local space) cameras facing direction to the global spaces x-y-Plane将(局部空间)摄像机朝向全局空间 x-y-Plane 投射
【发布时间】:2014-12-13 03:51:10
【问题描述】:

(食人魔3D) 我有一个相机对象,与下面的表面倾斜约 30 度。

现在,当用户按下某个键(例如 W 或 S)时,相机应该沿着朝向的方向移动,但会保持在全局空间的 x-y 平面上,就像你吸尘一样;)我认为帝国时代例如具有相同的视图机制。

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

我的问题不在于代码本身,而在于其背后的计算。如何从面向方向的局部对象中提取全局 x-y 平面方向?

感谢您的帮助!

【问题讨论】:

  • 取 3 个地面点并将它们视为三角形,因此从它的两个顶点中的任何一个顶点生成 2 个向量做叉积,你就有了平面的 normal 向量......所以在平移相机之前通过movementvector 删除轴向部分,例如:movement-=dot(normal,movement)/|normal| ...如果我没记错的话。如果您的叉积为您提供了相反的方向向量,则只需否定 normal

标签: c++ math 3d transformation ogre


【解决方案1】:

我明白了。如果有人也需要帮助,这是我的食人魔代码,您可以提取原理:

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)));
    }

【讨论】:

    猜你喜欢
    • 2014-12-11
    • 2016-01-07
    • 1970-01-01
    • 2012-05-03
    • 2019-08-11
    • 1970-01-01
    • 2011-11-08
    • 1970-01-01
    相关资源
    最近更新 更多