Let space() find points on the spaceship
parent
483a855848
commit
fdc1792932
|
@ -4101,66 +4101,55 @@ float SearchNearestObject(CObjectManager* objMan, Math::Vector center, CObject*
|
||||||
}
|
}
|
||||||
return min;
|
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
|
//! Calculates a free space
|
||||||
bool CRobotMain::FreeSpace(Math::Vector ¢er, float minRadius, float maxRadius,
|
bool CRobotMain::FreeSpace(Math::Vector ¢er, float minRadius, float maxRadius,
|
||||||
float space, CObject *exclu)
|
float space, CObject *exclu)
|
||||||
{
|
{
|
||||||
if (minRadius < maxRadius) // from internal to external?
|
for (float radius = minRadius; radius <= maxRadius; radius += space)
|
||||||
{
|
{
|
||||||
for (float radius = minRadius; radius <= maxRadius; radius += space)
|
float ia = space/radius;
|
||||||
|
for (float angle = 0.0f; angle < Math::PI*2.0f; angle += ia)
|
||||||
{
|
{
|
||||||
float ia = space/radius;
|
Math::Point p;
|
||||||
for (float angle = 0.0f; angle < Math::PI*2.0f; angle += ia)
|
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);
|
||||||
|
if (!BlockedByObject(m_objMan.get(), pos, space, exclu))
|
||||||
{
|
{
|
||||||
Math::Point p;
|
float flat = m_terrain->GetFlatZoneRadius(pos, space);
|
||||||
p.x = center.x+radius;
|
if (flat >= space)
|
||||||
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);
|
center = pos;
|
||||||
if (flat >= dist/2.0f)
|
return true;
|
||||||
{
|
|
||||||
center = pos;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue