Let space() find points on the spaceship
parent
483a855848
commit
fdc1792932
|
@ -4101,14 +4101,34 @@ float SearchNearestObject(CObjectManager* objMan, Math::Vector center, CObject*
|
|||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
bool BlockedByObject(CObjectManager* objMan, Math::Vector center, float space, CObject* exclu)
|
||||
{
|
||||
for (CObject* obj : objMan->GetAllObjects())
|
||||
{
|
||||
if (!obj->GetDetectable()) continue; // inactive?
|
||||
if (IsObjectBeingTransported(obj)) continue;
|
||||
|
||||
if (obj == exclu) continue;
|
||||
|
||||
for (const auto &crashSphere : obj->GetAllCrashSpheres())
|
||||
{
|
||||
const Math::Vector oPos = crashSphere.sphere.pos;
|
||||
const float oRadius = crashSphere.sphere.radius;
|
||||
const float minDist = oRadius + space;
|
||||
|
||||
if (Math::DistanceSquared(center, oPos) < minDist * minDist)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//! Calculates a free space
|
||||
bool CRobotMain::FreeSpace(Math::Vector ¢er, float minRadius, float maxRadius,
|
||||
float space, CObject *exclu)
|
||||
{
|
||||
if (minRadius < maxRadius) // from internal to external?
|
||||
{
|
||||
for (float radius = minRadius; radius <= maxRadius; radius += space)
|
||||
{
|
||||
float ia = space/radius;
|
||||
|
@ -4123,11 +4143,10 @@ bool CRobotMain::FreeSpace(Math::Vector ¢er, float minRadius, float maxRadiu
|
|||
pos.z = p.y;
|
||||
pos.y = 0.0f;
|
||||
m_terrain->AdjustToFloor(pos, true);
|
||||
float dist = SearchNearestObject(m_objMan.get(), pos, exclu);
|
||||
if (dist >= space)
|
||||
if (!BlockedByObject(m_objMan.get(), pos, space, exclu))
|
||||
{
|
||||
float flat = m_terrain->GetFlatZoneRadius(pos, dist/2.0f);
|
||||
if (flat >= dist/2.0f)
|
||||
float flat = m_terrain->GetFlatZoneRadius(pos, space);
|
||||
if (flat >= space)
|
||||
{
|
||||
center = pos;
|
||||
return true;
|
||||
|
@ -4135,36 +4154,6 @@ bool CRobotMain::FreeSpace(Math::Vector ¢er, float minRadius, float maxRadiu
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else // from external to internal?
|
||||
{
|
||||
for (float radius=maxRadius; radius >= minRadius; radius -= space)
|
||||
{
|
||||
float ia = space/radius;
|
||||
for (float angle=0.0f ; angle<Math::PI*2.0f ; angle+=ia )
|
||||
{
|
||||
Math::Point p;
|
||||
p.x = center.x+radius;
|
||||
p.y = center.z;
|
||||
p = Math::RotatePoint(Math::Point(center.x, center.z), angle, p);
|
||||
Math::Vector pos;
|
||||
pos.x = p.x;
|
||||
pos.z = p.y;
|
||||
pos.y = 0.0f;
|
||||
m_terrain->AdjustToFloor(pos, true);
|
||||
float dist = SearchNearestObject(m_objMan.get(), pos, exclu);
|
||||
if (dist >= space)
|
||||
{
|
||||
float flat = m_terrain->GetFlatZoneRadius(pos, dist/2.0f);
|
||||
if (flat >= dist/2.0f)
|
||||
{
|
||||
center = pos;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue