【问题标题】:Intersection with terrain与地形相交
【发布时间】:2014-07-19 16:43:24
【问题描述】:

我尝试用一​​些 Ogre::Ray 实现碰撞系统,但它似乎不起作用......

这是代码:

Ogre::Vector3 robotPos = mRobotNode->getPosition();
Ogre::Ray robotRay(Ogre::Vector3(robotPos.x,5000.0f,robotPos.z),Ogre::Vector3::NEGATIVE_UNIT_Y);

mRaySceneQuery->setRay(robotRay);
mRaySceneQuery->setSortByDistance(false);

Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
Ogre::RaySceneQueryResult::iterator itr;

for(itr = result.begin();itr != result.end(); itr++)
{
    if(itr->worldFragment)
    {

        Ogre::Real terrainHeight = itr->worldFragment->singleIntersection.y;
        if(terrainHeight!=robotPos.y)
        {
            mRobotNode->setPosition(Ogre::Vector3(robotPos.x,terrainHeight,robotPos.z));
            mCameraNode->setPosition(Ogre::Vector3(robotPos.x,terrainHeight,robotPos.z));
            break;
        }
    }
}

这段代码放入函数中:framerenderingqueued :)

但我的网格仍然低于地形

有人可以帮助我吗? :) 谢谢

【问题讨论】:

    标签: c++ ogre


    【解决方案1】:

    您为什么不使用调试器更深入地了解呢?您可以意识到,您的“if(terrainHeight!=robotPos.y)”条件中的问题,或者您的“结果”变量内部可能有零个元素,或者结果元素中没有一个具有正的“worldFragment”字段。
    如果您提供更多关于运行时发生的情况的信息,有助于识别问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-14
      • 2012-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多