本文整理汇总了C++中CBoundingBoxAligned::RayIntersect方法的典型用法代码示例。如果您正苦于以下问题:C++ CBoundingBoxAligned::RayIntersect方法的具体用法?C++ CBoundingBoxAligned::RayIntersect怎么用?C++ CBoundingBoxAligned::RayIntersect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBoundingBoxAligned
的用法示例。
在下文中一共展示了CBoundingBoxAligned::RayIntersect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cmpRangeManager
std::vector<entity_id_t> EntitySelection::PickEntitiesAtPoint(CSimulation2& simulation, const CCamera& camera, int screenX, int screenY, player_id_t player, bool allowEditorSelectables)
{
CVector3D origin, dir;
camera.BuildCameraRay(screenX, screenY, origin, dir);
CmpPtr<ICmpRangeManager> cmpRangeManager(simulation, SYSTEM_ENTITY);
ENSURE(cmpRangeManager);
std::vector<std::pair<float, entity_id_t> > hits; // (dist^2, entity) pairs
const CSimulation2::InterfaceListUnordered& ents = simulation.GetEntitiesWithInterfaceUnordered(IID_Selectable);
for (CSimulation2::InterfaceListUnordered::const_iterator it = ents.begin(); it != ents.end(); ++it)
{
entity_id_t ent = it->first;
// Check if this entity is only selectable in Atlas
if (!allowEditorSelectables && static_cast<ICmpSelectable*>(it->second)->IsEditorOnly())
continue;
// Ignore entities hidden by LOS (or otherwise hidden, e.g. when not IsInWorld)
if (cmpRangeManager->GetLosVisibility(ent, player) == ICmpRangeManager::VIS_HIDDEN)
continue;
CmpPtr<ICmpVisual> cmpVisual(simulation.GetSimContext(), ent);
if (!cmpVisual)
continue;
CVector3D center;
float tmin, tmax;
CBoundingBoxOriented selectionBox = cmpVisual->GetSelectionBox();
if (selectionBox.IsEmpty())
{
if (!allowEditorSelectables)
continue;
// Fall back to using old AABB selection method for decals
// see: http://trac.wildfiregames.com/ticket/1032
CBoundingBoxAligned aABBox = cmpVisual->GetBounds();
if (aABBox.IsEmpty())
continue;
if (!aABBox.RayIntersect(origin, dir, tmin, tmax))
continue;
aABBox.GetCentre(center);
}
else
{
if (!selectionBox.RayIntersect(origin, dir, tmin, tmax))
continue;
center = selectionBox.m_Center;
}
// Find the perpendicular distance from the object's centre to the picker ray
float dist2;
CVector3D closest = origin + dir * (center - origin).Dot(dir);
dist2 = (closest - center).LengthSquared();
hits.push_back(std::make_pair(dist2, ent));
}
// Sort hits by distance
std::sort(hits.begin(), hits.end()); // lexicographic comparison
// Extract the entity IDs
std::vector<entity_id_t> hitEnts;
hitEnts.reserve(hits.size());
for (size_t i = 0; i < hits.size(); ++i)
hitEnts.push_back(hits[i].second);
return hitEnts;
}
示例2: pos
std::vector<entity_id_t> EntitySelection::PickEntitiesAtPoint(CSimulation2& simulation, const CCamera& camera, int screenX, int screenY, player_id_t player, bool allowEditorSelectables, int range)
{
PROFILE2("PickEntitiesAtPoint");
CVector3D origin, dir;
camera.BuildCameraRay(screenX, screenY, origin, dir);
CmpPtr<ICmpRangeManager> cmpRangeManager(simulation, SYSTEM_ENTITY);
ENSURE(cmpRangeManager);
/* We try to approximate where the mouse is hovering by drawing a ray from
* the center of the camera and through the mouse then taking the position
* at which the ray intersects the terrain. */
// TODO: Do this smarter without being slow.
CVector3D pos3d = camera.GetWorldCoordinates(screenX, screenY, true);
// Change the position to 2D by removing the terrain height.
CFixedVector2D pos(fixed::FromFloat(pos3d.X), fixed::FromFloat(pos3d.Z));
// Get a rough group of entities using our approximated origin.
SpatialQueryArray ents;
cmpRangeManager->GetSubdivision()->GetNear(ents, pos, entity_pos_t::FromInt(range));
// Filter for relevent entities and calculate precise distances.
std::vector<std::pair<float, entity_id_t> > hits; // (dist^2, entity) pairs
for (int i = 0; i < ents.size(); ++i)
{
CmpPtr<ICmpSelectable> cmpSelectable(simulation, ents[i]);
if (!cmpSelectable)
continue;
CEntityHandle handle = cmpSelectable->GetEntityHandle();
// Check if this entity is only selectable in Atlas
if (!allowEditorSelectables && cmpSelectable->IsEditorOnly())
continue;
// Ignore entities hidden by LOS (or otherwise hidden, e.g. when not IsInWorld)
if (cmpRangeManager->GetLosVisibility(handle, player) == ICmpRangeManager::VIS_HIDDEN)
continue;
CmpPtr<ICmpVisual> cmpVisual(handle);
if (!cmpVisual)
continue;
CVector3D center;
float tmin, tmax;
CBoundingBoxOriented selectionBox = cmpVisual->GetSelectionBox();
if (selectionBox.IsEmpty())
{
if (!allowEditorSelectables)
continue;
// Fall back to using old AABB selection method for decals
// see: http://trac.wildfiregames.com/ticket/1032
CBoundingBoxAligned aABBox = cmpVisual->GetBounds();
if (aABBox.IsEmpty())
continue;
if (!aABBox.RayIntersect(origin, dir, tmin, tmax))
continue;
aABBox.GetCentre(center);
}
else
{
if (!selectionBox.RayIntersect(origin, dir, tmin, tmax))
continue;
center = selectionBox.m_Center;
}
// Find the perpendicular distance from the object's centre to the picker ray
float dist2;
CVector3D closest = origin + dir * (center - origin).Dot(dir);
dist2 = (closest - center).LengthSquared();
hits.push_back(std::make_pair(dist2, ents[i]));
}
// Sort hits by distance
std::sort(hits.begin(), hits.end()); // lexicographic comparison
// Extract the entity IDs
std::vector<entity_id_t> hitEnts;
hitEnts.reserve(hits.size());
for (size_t i = 0; i < hits.size(); ++i)
hitEnts.push_back(hits[i].second);
return hitEnts;
}