Skeleton implementation of sensor geometry. Parsing of Sensor geometry in
ssc files, but code currently currently just draws a line.sensor-dev
parent
40016f7091
commit
56d3466bc1
|
@ -0,0 +1,87 @@
|
|||
// sensorgeometry.cpp
|
||||
//
|
||||
// Copyright (C) 2010, Celestia Development Team
|
||||
// Original version by Chris Laurel <claurel@gmail.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
|
||||
#include "sensorgeometry.h"
|
||||
#include "rendcontext.h"
|
||||
#include "texmanager.h"
|
||||
#include "astro.h"
|
||||
#include "body.h"
|
||||
#include <Eigen/Core>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace std;
|
||||
|
||||
|
||||
SensorGeometry::SensorGeometry() :
|
||||
m_observer(NULL),
|
||||
m_target(NULL),
|
||||
m_range(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SensorGeometry::~SensorGeometry()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
SensorGeometry::pick(const Ray3d& /* r */, double& /* distance */) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SensorGeometry::render(RenderContext& rc, double tsec)
|
||||
{
|
||||
if (m_target == NULL || m_observer == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
double jd = astro::secsToDays(tsec) + astro::J2000;
|
||||
|
||||
UniversalCoord obsPos = m_observer->getPosition(jd);
|
||||
UniversalCoord targetPos = m_target->getPosition(jd);
|
||||
|
||||
Vector3d pos = targetPos.offsetFromKm(obsPos);
|
||||
|
||||
if (pos.norm() > m_range)
|
||||
{
|
||||
pos = pos.normalized() * m_range;
|
||||
}
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
glBegin(GL_LINES);
|
||||
glVertex3d(0.0, 0.0, 0.0);
|
||||
glVertex3dv(pos.data());
|
||||
glEnd();
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
SensorGeometry::isOpaque() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
SensorGeometry::isNormalized() const
|
||||
{
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
// sensorgeometry.h
|
||||
//
|
||||
// Copyright (C) 2010, Celestia Development Team
|
||||
// Original version by Chris Laurel <claurel@gmail.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
|
||||
#ifndef _CELENGINE_SENSOR_GEOMETRY_H_
|
||||
#define _CELENGINE_SENSOR_GEOMETRY_H_
|
||||
|
||||
#include "geometry.h"
|
||||
#include <celutil/resmanager.h>
|
||||
|
||||
class Body;
|
||||
|
||||
class SensorGeometry : public Geometry
|
||||
{
|
||||
public:
|
||||
SensorGeometry();
|
||||
~SensorGeometry();
|
||||
|
||||
virtual bool pick(const Ray3d& r, double& distance) const;
|
||||
|
||||
//! Render the model in the current OpenGL context
|
||||
virtual void render(RenderContext&, double t = 0.0);
|
||||
|
||||
virtual bool isOpaque() const;
|
||||
virtual bool isNormalized() const;
|
||||
|
||||
Body* observer() const
|
||||
{
|
||||
return m_observer;
|
||||
}
|
||||
|
||||
void setObserver(Body* observer)
|
||||
{
|
||||
m_observer = observer;
|
||||
}
|
||||
|
||||
Body* target() const
|
||||
{
|
||||
return m_target;
|
||||
}
|
||||
|
||||
void setTarget(Body* target)
|
||||
{
|
||||
m_target = target;
|
||||
}
|
||||
|
||||
double range() const
|
||||
{
|
||||
return m_range;
|
||||
}
|
||||
|
||||
void setRange(double range)
|
||||
{
|
||||
m_range = range;
|
||||
}
|
||||
|
||||
private:
|
||||
Body* m_observer;
|
||||
Body* m_target;
|
||||
double m_range;
|
||||
};
|
||||
|
||||
#endif // !_CELENGINE_SENSOR_GEOMETRY_H_
|
|
@ -29,6 +29,7 @@
|
|||
#include "parser.h"
|
||||
#include "texmanager.h"
|
||||
#include "meshmanager.h"
|
||||
#include "sensorgeometry.h"
|
||||
#include "universe.h"
|
||||
#include "multitexture.h"
|
||||
#include "parseobject.h"
|
||||
|
@ -894,6 +895,43 @@ static Body* CreateBody(const string& name,
|
|||
body->setGeometry(geometryHandle);
|
||||
body->setGeometryScale(geometryScale);
|
||||
}
|
||||
else if (planetData->getValue("Sensor"))
|
||||
{
|
||||
Hash* sensorData = planetData->getValue("Sensor")->getHash();
|
||||
if (sensorData)
|
||||
{
|
||||
SensorGeometry* sensor = new SensorGeometry();
|
||||
sensor->setObserver(body);
|
||||
|
||||
string targetName;
|
||||
if (sensorData->getString("Target", targetName))
|
||||
{
|
||||
Body* target = universe.findPath(targetName).body();
|
||||
if (target)
|
||||
{
|
||||
sensor->setTarget(target);
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "Can't find target for sensor.\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "No target specified for sensor.\n";
|
||||
}
|
||||
|
||||
sensor->setRange(30000.0);
|
||||
|
||||
string resName = string("sensor") + targetName + body->getName();
|
||||
GeometryInfo info(resName, path, Vector3f::Zero(), 1.0f, false);
|
||||
info.resource = sensor;
|
||||
info.state = ResourceLoaded;
|
||||
ResourceHandle geometryHandle = GetGeometryManager()->getHandle(info);
|
||||
body->setGeometry(geometryHandle);
|
||||
body->setGeometryScale(1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read the atmosphere
|
||||
|
|
Loading…
Reference in New Issue