|
|
这里有一段关于地形碰撞检测,射线场景查询的代码,引自Ogre官方中级教程2。
源码地址:http://www.ogre3d.org/wiki/index.php/IntermediateTutorial2Source
教程地址:http://www.ogre3d.cn/index.php?title=%E6%96%87%E6%A1%A3:%E6%95%99%E7%A8%8B:%E4%B8%AD%E7%BA%A7%E6%95%99%E7%A8%8B:%E4%B8%AD%E7%BA%A7%E6%95%99%E7%A8%8B%E4%BA%8C#.E4.BB.8B.E7.BB.8D
代码:
bool frameStarted(const FrameEvent &evt)
{
// Process the base frame listener code. Since we are going to be
// manipulating the translate vector, we need this to happen first.
if (!ExampleFrameListener::frameStarted(evt))
return false;
// Setup the scene query
Vector3 camPos = mCamera->getPosition();
Ray cameraRay(Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y);//定义一条射线
mRaySceneQuery->setRay(cameraRay);//设置射线场景查询的“射线”
// Perform the scene query
RaySceneQueryResult &result = mRaySceneQuery->execute();//执行查询,返回查询结果
RaySceneQueryResult::iterator itr = result.begin();
// Get the results, set the camera height
if (itr != result.end() && itr->worldFragment)
{
Real terrainHeight = itr->worldFragment->singleIntersection.y;
if ((terrainHeight + 10.0f) > camPos.y)
mCamera->setPosition( camPos.x, terrainHeight + 10.0f, camPos.z );
}
return true;
}
问题:
1、在上面代码RaySceneQueryResult &result里存放的是些什么内容?也就是执行完射线场景查询函数后返回的是什么?
2、&result值为何需要使用一个迭代器指向它?有很多内容么?在代码中也没见到迭代器遍历操作。场景查询的execute()过程大致是怎么样的?
请赐教。
|
|