From 9d8a301551f06ed45c8a0668a0d62eca3a1ebfbf Mon Sep 17 00:00:00 2001 From: Chris Laurel Date: Tue, 30 Nov 2010 20:54:22 +0000 Subject: [PATCH] Fixed rendering of sensor geometry: - Account for geometry orientation in intersection calculation - Draw sensor out to its range when it doesn't intersect the target body --- src/celengine/sensorgeometry.cpp | 20 +++++++++++++------- src/celengine/solarsys.cpp | 6 ++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/celengine/sensorgeometry.cpp b/src/celengine/sensorgeometry.cpp index 764adc742..350b301b0 100644 --- a/src/celengine/sensorgeometry.cpp +++ b/src/celengine/sensorgeometry.cpp @@ -74,11 +74,6 @@ SensorGeometry::render(RenderContext& rc, double tsec) Vector3d pos = targetPos.offsetFromKm(obsPos); - if (pos.norm() > m_range) - { - pos = pos.normalized() * m_range; - } - Quaterniond q = m_observer->getOrientation(jd); const unsigned int sectionCount = 40; @@ -86,7 +81,7 @@ SensorGeometry::render(RenderContext& rc, double tsec) Vector3d profile[sectionCount]; Vector3d footprint[sectionCount]; - Quaterniond obsOrientation = m_observer->getOrientation(jd).conjugate(); + Quaterniond obsOrientation = m_observer->getOrientation(jd).conjugate() * m_observer->getGeometryOrientation().cast().conjugate(); Quaterniond targetOrientation = m_target->getOrientation(jd).conjugate(); Vector3d origin = targetOrientation.conjugate() * -pos; Ellipsoidd targetEllipsoid(m_target->getSemiAxes().cast()); @@ -110,6 +105,8 @@ SensorGeometry::render(RenderContext& rc, double tsec) double t = double(i) / double(sectionCount); double theta = t * PI * 2.0; + // Note: -sin() is used here to reverse the vertex order so that the _outside_ + // of the frustum is drawn. profile[i] = obsOrientation * Vector3d(cos(theta) * m_horizontalFov, -sin(theta) * m_verticalFov, 1.0).normalized(); } @@ -120,8 +117,17 @@ SensorGeometry::render(RenderContext& rc, double tsec) Vector3d direction = profile[i]; Vector3d testDirection = targetOrientation.conjugate() * direction; + // Draw the sensor frustum out to either the range or the point of + // intersection with the target body--whichever is closer. double distance = 0.0; - testIntersection(Ray3d(origin, testDirection), targetEllipsoid, distance); + if (testIntersection(Ray3d(origin, testDirection), targetEllipsoid, distance)) + { + distance = std::min(distance, m_range); + } + else + { + distance = m_range; + } footprint[i] = distance * direction; } diff --git a/src/celengine/solarsys.cpp b/src/celengine/solarsys.cpp index db1d75f7e..aeb25b775 100644 --- a/src/celengine/solarsys.cpp +++ b/src/celengine/solarsys.cpp @@ -921,6 +921,10 @@ static Body* CreateBody(const string& name, cerr << "No target specified for sensor.\n"; } + double range = 1.0; + sensorData->getNumber("Range", range); + sensor->setRange(range); + double horizontalFov = 5.0; double verticalFov = 5.0; sensorData->getNumber("HorizontalFOV", horizontalFov); @@ -938,8 +942,6 @@ static Body* CreateBody(const string& name, sensor->setFrustumOpacity(frustumOpacity); sensor->setGridOpacity(gridOpacity); - sensor->setRange(30000.0); - string resName = string("sensor") + targetName + body->getName(); GeometryInfo info(resName, path, Vector3f::Zero(), 1.0f, false); info.resource = sensor;