Added script command to set and query visibility of named geometry components.
Currently, just the sensor geometry exposes components.sensor-dev
parent
7512d65311
commit
4b0350b9e3
|
@ -65,6 +65,27 @@ public:
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Set the visibility flag for the named component of this geometry.
|
||||
* Subclasses of Geometry should customize this method if they have
|
||||
* components with visibility that can be controlled independently.
|
||||
* The default implementation does nothing.
|
||||
*/
|
||||
virtual void setPartVisible(const std::string& partName, bool visible)
|
||||
{
|
||||
}
|
||||
|
||||
/** Check the visibility flag for the named component of this geometry.
|
||||
* Subclasses of Geometry should customize this method if they have
|
||||
* components with visibility that can be controlled independently.
|
||||
* The default implementation always returns false. Implementations
|
||||
* of isPartVisible by subclasses should also return false for
|
||||
* non-existent parts.
|
||||
*/
|
||||
virtual bool isPartVisible(const std::string& partName) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _CELENGINE_GEOMETRY_H_
|
||||
|
|
|
@ -34,7 +34,9 @@ SensorGeometry::SensorGeometry() :
|
|||
m_frustumBaseColor(1.0f, 1.0f, 1.0f),
|
||||
m_frustumOpacity(0.25f),
|
||||
m_gridOpacity(1.0f),
|
||||
m_shape(EllipticalShape)
|
||||
m_shape(EllipticalShape),
|
||||
m_frustumVisible(true),
|
||||
m_frustumBaseVisible(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -159,70 +161,79 @@ SensorGeometry::render(RenderContext& rc, double tsec)
|
|||
}
|
||||
|
||||
// Draw the frustum
|
||||
glColor4f(m_frustumColor.red(), m_frustumColor.green(), m_frustumColor.blue(), m_frustumOpacity);
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glVertex3d(0.0, 0.0, 0.0);
|
||||
for (unsigned int i = 0; i < sectionCount; ++i)
|
||||
if (m_frustumVisible)
|
||||
{
|
||||
glVertex3dv(footprint[i].data());
|
||||
glColor4f(m_frustumColor.red(), m_frustumColor.green(), m_frustumColor.blue(), m_frustumOpacity);
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glVertex3d(0.0, 0.0, 0.0);
|
||||
for (unsigned int i = 0; i < sectionCount; ++i)
|
||||
{
|
||||
glVertex3dv(footprint[i].data());
|
||||
}
|
||||
glVertex3dv(footprint[0].data());
|
||||
glEnd();
|
||||
}
|
||||
glVertex3dv(footprint[0].data());
|
||||
glEnd();
|
||||
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
|
||||
// Draw the footprint outline
|
||||
glColor4f(m_frustumBaseColor.red(), m_frustumBaseColor.green(), m_frustumBaseColor.blue(), m_gridOpacity);
|
||||
glLineWidth(2.0f);
|
||||
glBegin(GL_LINE_LOOP);
|
||||
for (unsigned int i = 0; i < sectionCount; ++i)
|
||||
if (m_frustumBaseVisible)
|
||||
{
|
||||
glVertex3dv(footprint[i].data());
|
||||
}
|
||||
glEnd();
|
||||
glLineWidth(1.0f);
|
||||
|
||||
glColor4f(m_frustumColor.red(), m_frustumColor.green(), m_frustumColor.blue(), m_frustumOpacity);
|
||||
for (unsigned int slice = 1; slice < sliceCount; ++slice)
|
||||
{
|
||||
// Linear arrangement of slices
|
||||
//double t = double(slice) / double(sliceCount);
|
||||
|
||||
// Exponential arrangement looks better
|
||||
double t = pow(2.0, -double(slice));
|
||||
|
||||
glColor4f(m_frustumBaseColor.red(), m_frustumBaseColor.green(), m_frustumBaseColor.blue(), m_gridOpacity);
|
||||
glLineWidth(2.0f);
|
||||
glBegin(GL_LINE_LOOP);
|
||||
for (unsigned int i = 0; i < sectionCount; ++i)
|
||||
{
|
||||
Vector3d v = footprint[i] * t;
|
||||
glVertex3dv(v.data());
|
||||
glVertex3dv(footprint[i].data());
|
||||
}
|
||||
glEnd();
|
||||
glLineWidth(1.0f);
|
||||
}
|
||||
|
||||
if (m_frustumVisible)
|
||||
{
|
||||
glColor4f(m_frustumColor.red(), m_frustumColor.green(), m_frustumColor.blue(), m_frustumOpacity);
|
||||
for (unsigned int slice = 1; slice < sliceCount; ++slice)
|
||||
{
|
||||
// Linear arrangement of slices
|
||||
//double t = double(slice) / double(sliceCount);
|
||||
|
||||
// Exponential arrangement looks better
|
||||
double t = pow(2.0, -double(slice));
|
||||
|
||||
glBegin(GL_LINE_LOOP);
|
||||
for (unsigned int i = 0; i < sectionCount; ++i)
|
||||
{
|
||||
Vector3d v = footprint[i] * t;
|
||||
glVertex3dv(v.data());
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
// NOTE: section count should be evenly divisible by 8
|
||||
glBegin(GL_LINES);
|
||||
if (m_shape == EllipticalShape)
|
||||
{
|
||||
unsigned int rayCount = 8;
|
||||
unsigned int step = sectionCount / rayCount;
|
||||
for (unsigned int i = 0; i < sectionCount; i += step)
|
||||
{
|
||||
glVertex3f(0.0f, 0.0f, 0.0f);
|
||||
glVertex3dv(footprint[i].data());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int step = sectionCount / 4;
|
||||
for (unsigned int i = sectionCount / 8; i < sectionCount; i += step)
|
||||
{
|
||||
glVertex3f(0.0f, 0.0f, 0.0f);
|
||||
glVertex3dv(footprint[i].data());
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
// NOTE: section count should be evenly divisible by 8
|
||||
glBegin(GL_LINES);
|
||||
if (m_shape == EllipticalShape)
|
||||
{
|
||||
unsigned int rayCount = 8;
|
||||
unsigned int step = sectionCount / rayCount;
|
||||
for (unsigned int i = 0; i < sectionCount; i += step)
|
||||
{
|
||||
glVertex3f(0.0f, 0.0f, 0.0f);
|
||||
glVertex3dv(footprint[i].data());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int step = sectionCount / 4;
|
||||
for (unsigned int i = sectionCount / 8; i < sectionCount; i += step)
|
||||
{
|
||||
glVertex3f(0.0f, 0.0f, 0.0f);
|
||||
glVertex3dv(footprint[i].data());
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
|
@ -241,3 +252,36 @@ SensorGeometry::isNormalized() const
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SensorGeometry::setPartVisible(const std::string& partName, bool visible)
|
||||
{
|
||||
std::clog << "setPartVisible: " << partName << std::endl;
|
||||
if (partName == "Frustum")
|
||||
{
|
||||
m_frustumVisible = visible;
|
||||
}
|
||||
else if (partName == "FrustumBase")
|
||||
{
|
||||
m_frustumBaseVisible = visible;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
SensorGeometry::isPartVisible(const std::string& partName) const
|
||||
{
|
||||
if (partName == "Frustum")
|
||||
{
|
||||
return m_frustumVisible;
|
||||
}
|
||||
else if (partName == "FrustumBase")
|
||||
{
|
||||
return m_frustumBaseVisible;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,9 @@ class SensorGeometry : public Geometry
|
|||
return true;
|
||||
}
|
||||
|
||||
virtual void setPartVisible(const std::string& partName, bool visible);
|
||||
virtual bool isPartVisible(const std::string& partName) const;
|
||||
|
||||
Body* observer() const
|
||||
{
|
||||
return m_observer;
|
||||
|
@ -124,6 +127,7 @@ class SensorGeometry : public Geometry
|
|||
|
||||
void setFOVs(double horizontalFov, double verticalFov);
|
||||
|
||||
|
||||
private:
|
||||
Body* m_observer;
|
||||
Body* m_target;
|
||||
|
@ -135,6 +139,8 @@ class SensorGeometry : public Geometry
|
|||
float m_frustumOpacity;
|
||||
float m_gridOpacity;
|
||||
SensorShape m_shape;
|
||||
bool m_frustumVisible;
|
||||
bool m_frustumBaseVisible;
|
||||
};
|
||||
|
||||
#endif // !_CELENGINE_SENSOR_GEOMETRY_H_
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <celengine/axisarrow.h>
|
||||
#include <celengine/visibleregion.h>
|
||||
#include <celengine/planetgrid.h>
|
||||
#include <celengine/meshmanager.h>
|
||||
#include "celestiacore.h"
|
||||
|
||||
using namespace Eigen;
|
||||
|
@ -131,6 +132,56 @@ static int object_setvisible(lua_State* l)
|
|||
}
|
||||
|
||||
|
||||
// Check the visibility flag for an object component; returns false if the object doesn't
|
||||
// have a component with the specified name
|
||||
static int object_partvisible(lua_State* l)
|
||||
{
|
||||
CelxLua celx(l);
|
||||
celx.checkArgs(2, 2, "One argument expected to object:setpartvisible()");
|
||||
|
||||
Selection* sel = this_object(l);
|
||||
string partName = celx.safeGetString(2, AllErrors, "Argument of object:setpartvisible() must be a string");
|
||||
|
||||
bool visible = false;
|
||||
|
||||
if (sel->body() != NULL && sel->body()->getGeometry() != InvalidResource)
|
||||
{
|
||||
Geometry* geom = GetGeometryManager()->find(sel->body()->getGeometry());
|
||||
if (geom)
|
||||
{
|
||||
visible = geom->isPartVisible(partName);
|
||||
}
|
||||
}
|
||||
|
||||
lua_pushboolean(l, visible ? 1 : 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Set the visibility flag for an object component; has no effect if the object doesn't
|
||||
// have any defined components.
|
||||
static int object_setpartvisible(lua_State* l)
|
||||
{
|
||||
CelxLua celx(l);
|
||||
celx.checkArgs(3, 3, "Two argument expected to object:setpartvisible()");
|
||||
|
||||
Selection* sel = this_object(l);
|
||||
string partName = celx.safeGetString(2, AllErrors, "Argument 1 of object:setpartvisible() must be a string");
|
||||
|
||||
bool visible = celx.safeGetBoolean(3, AllErrors, "Argument 2 of object:setpartvisible() must be a boolean");
|
||||
if (sel->body() != NULL && sel->body()->getGeometry() != InvalidResource)
|
||||
{
|
||||
Geometry* geom = GetGeometryManager()->find(sel->body()->getGeometry());
|
||||
if (geom)
|
||||
{
|
||||
geom->setPartVisible(partName, visible);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int object_setorbitcolor(lua_State* l)
|
||||
{
|
||||
CelxLua celx(l);
|
||||
|
@ -1306,6 +1357,8 @@ void CreateObjectMetaTable(lua_State* l)
|
|||
celx.registerMethod("__tostring", object_tostring);
|
||||
celx.registerMethod("visible", object_visible);
|
||||
celx.registerMethod("setvisible", object_setvisible);
|
||||
celx.registerMethod("partvisible", object_partvisible);
|
||||
celx.registerMethod("setpartvisible", object_setpartvisible);
|
||||
celx.registerMethod("orbitcoloroverridden", object_orbitcoloroverridden);
|
||||
celx.registerMethod("setorbitcoloroverridden", object_setorbitcoloroverridden);
|
||||
celx.registerMethod("setorbitcolor", object_setorbitcolor);
|
||||
|
|
Loading…
Reference in New Issue