Better selection boxes. Closes #914, #295, #810.

This was SVN commit r10593.
This commit is contained in:
vts
2011-11-25 06:36:13 +00:00
parent 9e97c73544
commit 85186c98b2
58 changed files with 1315 additions and 205 deletions
+6 -5
View File
@@ -100,15 +100,16 @@ CUnit* CUnitManager::PickUnit(const CVector3D& origin, const CVector3D& dir) con
CUnit* unit = m_Units[i];
float tmin, tmax;
if (unit->GetModel().GetBounds().RayIntersect(origin, dir, tmin, tmax))
const CBoundingBoxOriented& selectionBox = unit->GetModel().GetSelectionBox();
if (selectionBox.RayIntersect(origin, dir, tmin, tmax))
{
// Point of closest approach
CVector3D obj;
unit->GetModel().GetBounds().GetCentre(obj);
CVector3D delta = obj - origin;
// TODO: this next bit is virtually identical to Selection::PickEntitiesAtPoint; might be useful to factor it out and
// reuse it
CVector3D delta = selectionBox.m_Center - origin;
float distance = delta.Dot(dir);
CVector3D closest = origin + dir * distance;
CVector3D offset = obj - closest;
CVector3D offset = selectionBox.m_Center - closest;
float rel = offset.Length();
if (rel < minrel) {