Implemented horizontal and vertical FOV properties for sensor frustum geometry.

sensor-dev
Chris Laurel 2010-11-26 19:04:53 +00:00
parent 56d3466bc1
commit 3616bdf92d
3 changed files with 37 additions and 3 deletions

View File

@ -13,6 +13,7 @@
#include "texmanager.h"
#include "astro.h"
#include "body.h"
#include "celmath/mathlib.h"
#include <Eigen/Core>
#include <algorithm>
#include <cassert>
@ -24,7 +25,9 @@ using namespace std;
SensorGeometry::SensorGeometry() :
m_observer(NULL),
m_target(NULL),
m_range(0.0)
m_range(0.0),
m_horizontalFov(degToRad(5.0)),
m_verticalFov(degToRad(5.0))
{
}
@ -41,6 +44,14 @@ SensorGeometry::pick(const Ray3d& /* r */, double& /* distance */) const
}
void
SensorGeometry::setFOVs(double horizontalFov, double verticalFov)
{
m_horizontalFov = horizontalFov;
m_verticalFov = verticalFov;
}
void
SensorGeometry::render(RenderContext& rc, double tsec)
{
@ -61,12 +72,25 @@ SensorGeometry::render(RenderContext& rc, double tsec)
pos = pos.normalized() * m_range;
}
Quaterniond q = m_observer->getOrientation(jd);
unsigned int sectionCount = 24;
glDisable(GL_LIGHTING);
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glBegin(GL_LINES);
glVertex3d(0.0, 0.0, 0.0);
glVertex3dv(pos.data());
for (unsigned int i = 0; i < sectionCount; ++i)
{
double t = double(i) / double(sectionCount);
double theta = t * PI * 2.0;
Vector3d v = Vector3d(cos(theta) * m_horizontalFov, sin(theta) * m_verticalFov, 1.0).normalized();
glVertex3d(0.0, 0.0, 0.0);
glVertex3dv(v.data());
}
glEnd();
glEnable(GL_LIGHTING);

View File

@ -60,10 +60,14 @@ class SensorGeometry : public Geometry
m_range = range;
}
void setFOVs(double horizontalFov, double verticalFov);
private:
Body* m_observer;
Body* m_target;
double m_range;
double m_horizontalFov;
double m_verticalFov;
};
#endif // !_CELENGINE_SENSOR_GEOMETRY_H_

View File

@ -921,6 +921,12 @@ static Body* CreateBody(const string& name,
cerr << "No target specified for sensor.\n";
}
double horizontalFov = 5.0;
double verticalFov = 5.0;
sensorData->getNumber("HorizontalFOV", horizontalFov);
sensorData->getNumber("VerticalFOV", verticalFov);
sensor->setFOVs(degToRad(horizontalFov), degToRad(verticalFov));
sensor->setRange(30000.0);
string resName = string("sensor") + targetName + body->getName();