Refactored osgSim::SphereSegment so that it no longer uses GLBeginEndAdapter

This commit is contained in:
Robert Osfield
2016-08-25 10:28:37 +01:00
parent a1ab1a0ecc
commit 7c432fbe11
3 changed files with 448 additions and 884 deletions

View File

@@ -366,7 +366,6 @@ public:
float azRange, elevRange;
ss->getArea(direction_vec, azRange, elevRange);
OSG_NOTICE<<std::endl<<"AdjustSphereSegmentCallback : scaling azRange"<<azRange<<", scale="<<scale<<std::endl;
ss->setArea(direction_vec, azRange*scale, elevRange*scale);
}

View File

@@ -21,6 +21,7 @@
#include <osg/Geode>
#include <osg/Matrixd>
#include <osg/BlendFunc>
#include <osg/Geometry>
namespace osgSim{
@@ -100,17 +101,7 @@ public:
@param elevMax elevation maximum
@param density number of units to divide the azimuth and elevation ranges into
*/
SphereSegment(const osg::Vec3& centre, float radius, float azMin, float azMax,
float elevMin, float elevMax, int density):
osg::Geode(),
_centre(centre), _radius(radius),
_azMin(azMin), _azMax(azMax),
_elevMin(elevMin), _elevMax(elevMax),
_density(density),
_drawMask(DrawMask(ALL))
{
init();
}
SphereSegment(const osg::Vec3& centre, float radius, float azMin, float azMax, float elevMin, float elevMax, int density);
/**
Construct by vector.
@@ -122,20 +113,12 @@ public:
@param elevRange elevation range in radians (with centre along vec)
@param density number of units to divide the azimuth and elevation ranges into
*/
SphereSegment(const osg::Vec3& centre, float radius, const osg::Vec3& vec, float azRange,
float elevRange, int density);
SphereSegment(const osg::Vec3& centre, float radius, const osg::Vec3& vec, float azRange, float elevRange, int density);
/** Copy constructor */
SphereSegment(const SphereSegment& rhs, const osg::CopyOp& co):
osg::Geode(rhs,co),
_centre(rhs._centre), _radius(rhs._radius),
_azMin(rhs._azMin), _azMax(rhs._azMax),
_elevMin(rhs._elevMin), _elevMax(rhs._elevMax),
_density(rhs._density),
_drawMask(rhs._drawMask)
{
init();
}
SphereSegment(const SphereSegment& rhs, const osg::CopyOp& co);
void traverse(osg::NodeVisitor& nv);
/** Set the centre point of the SphereSegment */
void setCentre(const osg::Vec3& c);
@@ -203,25 +186,25 @@ public:
void setSurfaceColor(const osg::Vec4& c);
/** Get the color of the surface. */
const osg::Vec4& getSurfaceColor() const { return _surfaceColor; }
const osg::Vec4& getSurfaceColor() const { return (*_surfaceColor)[0]; }
/** Set the color of the spokes. */
void setSpokeColor(const osg::Vec4& c);
/** Get the color of the spokes. */
const osg::Vec4& getSpokeColor() const { return _spokeColor; }
const osg::Vec4& getSpokeColor() const { return (*_spokeColor)[0]; }
/** Set the color of the edge line. */
void setEdgeLineColor(const osg::Vec4& c);
/** Get the color of the edge line. */
const osg::Vec4& getEdgeLineColor() const { return _edgeLineColor; }
const osg::Vec4& getEdgeLineColor() const { return (*_edgeLineColor)[0]; }
/** Set the color of the planes. */
void setSideColor(const osg::Vec4& c);
/** Get the color of the planes. */
const osg::Vec4& getSideColor() const { return _planeColor; }
const osg::Vec4& getSideColor() const { return (*_sideColor)[0]; }
/** Set color of all components. */
void setAllColors(const osg::Vec4& c);
@@ -251,52 +234,19 @@ public:
* The resulting intersections are in the coordinate frame of the sphere segment. */
osg::Node* computeIntersectionSubgraph(const osg::Matrixd& matrix, osg::Drawable* drawable);
/** recompute the vertex positions of the rendering meshes/lines thtat represent the sphere segment.*/
void updatePositions();
/** recompute the primitives rendering meshes/lines thtat represent the sphere segment.*/
void updatePrimitives();
virtual osg::BoundingSphere computeBound() const;
private:
void init(); // Shared constructor code, generates the drawables
void dirtyAllDrawableDisplayLists(); // Force re-calling of gl functions
void dirtyAllDrawableBounds(); // Force recalculation of bound geometry
// SphereSegment is actually made up of a number of Drawable classes,
// all of which are nested private classes, as declared below. These
// classes are defined in the .cpp for minimum visibility and physical
// coupling. (Reduces time spent compiling! :-)
//
// Each of the nested classes holds a pointer to the SphereSegment
// 'parent', which stores the geometry details, and performs any
// work required. The nested classes are lightweight objects which
// just pass the work on.
//
// Why are things done with these sub-Drawables? Alpha-blended
// Drawables need to be drawn last, depth sorted, and the various
// components of a SphereSegment also need to be depth sorted
// against one another (they may all be drawn with alpha blending).
// Making these Drawables allows us to get the OSG to depth sort
// for us.
class Surface;
friend class Surface;
bool Surface_computeBound(osg::BoundingBox&) const;
void Surface_drawImplementation(osg::State&) const;
class EdgeLine;
friend class EdgeLine;
bool EdgeLine_computeBound(osg::BoundingBox&) const;
void EdgeLine_drawImplementation(osg::State&) const;
enum BoundaryAngle{MIN,MAX}; // Why here and not in Side class? Because we can't forward
enum SideOrientation{AZIM,ELEV}; // declare enums, Side is in the .cpp, and this is tidier...
class Side;
friend class Side;
bool Side_computeBound(osg::BoundingBox&, SideOrientation, BoundaryAngle) const;
void Side_drawImplementation(osg::State&, SideOrientation, BoundaryAngle) const;
class Spoke;
friend class Spoke;
bool Spoke_computeBound(osg::BoundingBox&, BoundaryAngle, BoundaryAngle) const;
void Spoke_drawImplementation(osg::State&, BoundaryAngle, BoundaryAngle) const;
void dirty(); // Force re-calling of gl functions and bounding boxes
// Sphere segment geometry details
osg::Vec3 _centre;
@@ -306,10 +256,27 @@ private:
// Draw details
int _drawMask;
osg::Vec4 _surfaceColor;
osg::Vec4 _spokeColor;
osg::Vec4 _edgeLineColor;
osg::Vec4 _planeColor;
osg::ref_ptr<osg::Vec4Array> _surfaceColor;
osg::ref_ptr<osg::Vec4Array> _spokeColor;
osg::ref_ptr<osg::Vec4Array> _edgeLineColor;
osg::ref_ptr<osg::Vec4Array> _sideColor;
osg::ref_ptr<osg::Vec3Array> _vertices;
osg::ref_ptr<osg::Vec3Array> _normals;
osg::ref_ptr<osg::Geometry> _surfaceGeometry;
osg::ref_ptr<osg::Geometry> _spokesGeometry;
osg::ref_ptr<osg::Geometry> _edgeLineGeometry;
osg::ref_ptr<osg::Geometry> _sidesGeometry;
osg::ref_ptr<osg::StateSet> _litOpaqueState;
osg::ref_ptr<osg::StateSet> _unlitOpaqueState;
osg::ref_ptr<osg::StateSet> _litTransparentState;
osg::ref_ptr<osg::StateSet> _unlitTransparentState;
osg::StateSet* getLitStateSet(const osg::Vec4& color) { return (color.a()<1.0) ? _litTransparentState.get() : _litOpaqueState.get(); }
osg::StateSet* getUnlitStateSet(const osg::Vec4& color) { return (color.a()<1.0) ? _unlitTransparentState.get() : _unlitOpaqueState.get(); }
};
}

File diff suppressed because it is too large Load Diff