本文整理汇总了C++中QuadTree::intersectionRay方法的典型用法代码示例。如果您正苦于以下问题:C++ QuadTree::intersectionRay方法的具体用法?C++ QuadTree::intersectionRay怎么用?C++ QuadTree::intersectionRay使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QuadTree
的用法示例。
在下文中一共展示了QuadTree::intersectionRay方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: selectObject
bool MouseMarker::selectObject(int types, bool overrideObject)
{
//Attempt to select an object.
if(!mpObject || overrideObject)
{
LogicQuadTree *pLogicTree = LogicQuadTree::getInstance();
QuadTree *pTree = pLogicTree->getQuadTree();
vector<CollisionObject *> objects;
//Check intersection with the mouse ray.
pTree->intersectionRay(mMouseRay.mOrigin, mMouseRay.mDirection, objects);
float minDistance = (float)INT_MAX;
float distance = 0.0f;
CollisionObject *pClosestObject = NULL;
//Find the closest object.
for(vector<CollisionObject *>::iterator objectIter = objects.begin();
objectIter != objects.end(); ++objectIter)
{
//Ignore ground objects.
if((*objectIter)->getID() != KEY_GROUND)
{
distance = (*objectIter)->getDistance(mMouseRay.mOrigin);
if(distance < minDistance)
{
minDistance = distance;
pClosestObject = (*objectIter);
}
}
}
if(pClosestObject)
{
TransformObject *pObject = (TransformObject *)pClosestObject->getParent();
Actor *pActor = (Actor *)pObject->getActor();
mObjectRotation = pObject->getRotation();
//Apply rotation offset.
mObjectRotation += D3DXVECTOR3(0.0f, -(float)(0.5 * D3DX_PI), 0.0f);
mObjectScale = pObject->getScale();
//Check for trigger.
if(pObject->getID() == KEY_TRIGGER.convertToGfxId())
{
if(types & MouseMarker::MarkerType_Trigger)
{
mMarkerState = MouseMarker::MarkerState_Select;
mMarkerType = MouseMarker::MarkerType_Trigger;
mpObject = pObject;
return true;
}
}
//Check if the selected object is an actor.
else if(pActor)
{
if(types & MouseMarker::MarkerType_Actor)
{
//Check that the actor is owned by the player.
if(pActor->getKey().isOwner())
{
//Set type to actor.
mMarkerState = MouseMarker::MarkerState_Select;
mMarkerType = MouseMarker::MarkerType_Actor;
mpObject = pActor;
return true;
}
}
}
//Should be an object otherwise.
else
{
if(types & MouseMarker::MarkerType_Object)
{
//Set type to object.
if(pObject->getID() >= 0)
{
mMarkerState = MouseMarker::MarkerState_Select;
mMarkerType = MouseMarker::MarkerType_Object;
mpObject = pObject;
return true;
}
}
}
}
else
{
clearObject();
}
}
return false;
}