From 73094265c38e379d06c34e94ca121f43c7c2e38a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 1 Sep 2003 15:46:10 +0000 Subject: [PATCH] Fixes for Win32. --- VisualStudio/VisualStudio.dsw | 3 + .../osgspheresegment/osgspheresegment.cpp | 2 +- include/osgSim/ColorRange | 14 +- include/osgSim/LightPoint | 6 +- include/osgSim/LightPointNode | 6 +- include/osgSim/ScalarBar | 236 +++--- include/osgSim/ScalarsToColors | 10 +- include/osgSim/SphereSegment | 288 +++---- src/osgSim/ScalarBar.cpp | 8 +- src/osgSim/SphereSegment.cpp | 762 +++++++++--------- 10 files changed, 669 insertions(+), 666 deletions(-) diff --git a/VisualStudio/VisualStudio.dsw b/VisualStudio/VisualStudio.dsw index 13e946e59..e80de36e1 100644 --- a/VisualStudio/VisualStudio.dsw +++ b/VisualStudio/VisualStudio.dsw @@ -149,6 +149,9 @@ Package=<4> Begin Project Dependency Project_Dep_Name Core osgDB End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgText + End Project Dependency }}} ############################################################################### diff --git a/examples/osgspheresegment/osgspheresegment.cpp b/examples/osgspheresegment/osgspheresegment.cpp index a83ed927e..3e8e81e8f 100644 --- a/examples/osgspheresegment/osgspheresegment.cpp +++ b/examples/osgspheresegment/osgspheresegment.cpp @@ -83,7 +83,7 @@ osg::Node* createSphereSegment() osg::DegreesToRadians(45.0f), 60); ss->setAllColors(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); - ss->setPlaneColor(osg::Vec4(0.0f,0.0f,1.0f,0.1f)); + ss->setSideColor(osg::Vec4(0.0f,0.0f,1.0f,0.1f)); //ss->setDrawMask(SphereSegment::DrawMask(SphereSegment::SPOKES | SphereSegment::EDGELINE)); //ss->setUpdateCallback(new MyNodeCallback); diff --git a/include/osgSim/ColorRange b/include/osgSim/ColorRange index 115804aa6..d1dcbc67b 100644 --- a/include/osgSim/ColorRange +++ b/include/osgSim/ColorRange @@ -33,21 +33,21 @@ class OSGSIM_EXPORT ColorRange: public ScalarsToColors public: /** Constructor for a ColorRange - @param min minimum scalar value - @param max maximum scalar value - @param colors optional range of colors, defaulting to Red-Yellow-Green-Blue-Cyan - */ + @param min minimum scalar value + @param max maximum scalar value + @param colors optional range of colors, defaulting to Red-Yellow-Green-Blue-Cyan + */ ColorRange(float min, float max, const std::vector& colors = std::vector()); - /** Set the range of colors. */ + /** Set the range of colors. */ void setColors(const std::vector& colors); - /** Get the color for a given scalar value. */ + /** Get the color for a given scalar value. */ osg::Vec4 getColor(float scalar) const; private: - // Default assignment and copy construction are OK. + // Default assignment and copy construction are OK. std::vector _colors; }; diff --git a/include/osgSim/LightPoint b/include/osgSim/LightPoint index 346c57ec3..4aa39bdff 100644 --- a/include/osgSim/LightPoint +++ b/include/osgSim/LightPoint @@ -40,7 +40,7 @@ class OSGSIM_EXPORT LightPoint LightPoint(const osg::Vec3& position, const osg::Vec4& color); - LightPoint(bool on, + LightPoint(bool on, const osg::Vec3& position, const osg::Vec4& color, float intensity=1.0f, @@ -55,7 +55,7 @@ class OSGSIM_EXPORT LightPoint LightPoint& operator = (const LightPoint& lp); - bool _on; + bool _on; osg::Vec3 _position; osg::Vec4 _color; float _intensity; @@ -64,7 +64,7 @@ class OSGSIM_EXPORT LightPoint osg::ref_ptr _sector; osg::ref_ptr _blinkSequence; - BlendingMode _blendingMode; + BlendingMode _blendingMode; }; } diff --git a/include/osgSim/LightPointNode b/include/osgSim/LightPointNode index 3d87236ac..bb77d7abd 100644 --- a/include/osgSim/LightPointNode +++ b/include/osgSim/LightPointNode @@ -49,13 +49,13 @@ class OSGSIM_EXPORT LightPointNode : public osg::Node unsigned int addLightPoint(const LightPoint& lp); - + void removeLightPoint(unsigned int pos); - LightPoint& getLightPoint(unsigned int pos) { return _lightPointList[pos]; } + LightPoint& getLightPoint(unsigned int pos) { return _lightPointList[pos]; } - const LightPoint& getLightPoint(unsigned int pos) const { return _lightPointList[pos]; } + const LightPoint& getLightPoint(unsigned int pos) const { return _lightPointList[pos]; } void setLightPointList(const LightPointList& lpl) { _lightPointList=lpl; } diff --git a/include/osgSim/ScalarBar b/include/osgSim/ScalarBar index b93370489..e583f94af 100644 --- a/include/osgSim/ScalarBar +++ b/include/osgSim/ScalarBar @@ -33,7 +33,7 @@ In summary, the main configurables on the ScalarBar are: -# The range of scalars represented by the bar, and the colors corresponding to this range - these are specified by the - ScalarsToColors object. + ScalarsToColors object. -# The number of colors used when rendering the bar geometry - this may be thought of as the bar 'density'. -# The number of text labels to be used when displaying the bar. @@ -48,167 +48,167 @@ public: /** ScalarBar orientation specification. */ enum Orientation{ HORIZONTAL, ///< a horizontally ascending scalar bar (x-axis) - VERTICAL ///< a vertically ascending scalar bar (y-axis) - }; + VERTICAL ///< a vertically ascending scalar bar (y-axis) + }; - /** + /** Users may provide their own ScalarPrinter by deriving from this base class and - overriding the printScalar() method. Users may map the scalar float passed in - to any string they wish. - */ + overriding the printScalar() method. Users may map the scalar float passed in + to any string they wish. + */ struct ScalarPrinter: public osg::Referenced - { - virtual std::string printScalar(float scalar); - }; + { + virtual std::string printScalar(float scalar); + }; - /** + /** TextProperties allows users to specify a number of properties for the - text used to display the labels & title on the ScalarBar. Specifiying a character - size of 0 will cause the ScalarBar to estimate an appropriate size. Note that + text used to display the labels & title on the ScalarBar. Specifiying a character + size of 0 will cause the ScalarBar to estimate an appropriate size. Note that the attributes are public, and may be set directly. - */ + */ struct TextProperties - { + { std::string _fontFile; - std::pair _fontResolution; - int _characterSize; - osg::Vec4 _color; + std::pair _fontResolution; + int _characterSize; + osg::Vec4 _color; - TextProperties(): + TextProperties(): _fontFile("fonts/arial.ttf"), - _fontResolution(40,40), - _characterSize(0), - _color(1.0f,1.0f,1.0f,1.0f) - { - } - }; + _fontResolution(40,40), + _characterSize(0), + _color(1.0f,1.0f,1.0f,1.0f) + { + } + }; /** Default constructor. */ ScalarBar(): osg::Geode(), - _numColors(256), - _numLabels(11), - _stc(new ColorRange(0.0f,1.0f)), - _title("Scalar Bar"), - _orientation(HORIZONTAL), - _aspectRatio(0.03), - _sp(new ScalarPrinter) - { - createDrawables(); - } - - /** - Construct a ScalarBar with the supplied parameters. - @param numColors Specify the number of colors in the scalar bar. Color - interpolation occurs where necessary. - @param stc The ScalarsToColors defining the range of scalars - and the colors they map to. - @param title The title to be used when displaying the ScalarBar. - Specify "" for no title. - @param orientation The orientation of the ScalarBar. @see Orientation. - @param apectRatio The aspect ration (y/x) for the displayed bar. Bear in mind you - may want to change this if you change the orientation. - @param sp A ScalarPrinter object for the ScalarBar. For every displayed - ScalarBar label, the scalar value will be passed to the - ScalarPrinter object to turn it into a string. Users may - override the default ScalarPrinter object to map scalars to - whatever strings they wish. @see ScalarPrinter - */ - ScalarBar(int numColors, int numLabels, ScalarsToColors* stc, - const std::string& title, - Orientation orientation = HORIZONTAL, - float aspectRatio=0.25, - ScalarPrinter* sp=new ScalarPrinter): - osg::Geode(), - _numColors(numColors), - _numLabels(numLabels), - _stc(stc), - _title(title), - _orientation(orientation), - _aspectRatio(aspectRatio), - _sp(sp) - { + _numColors(256), + _numLabels(11), + _stc(new ColorRange(0.0f,1.0f)), + _title("Scalar Bar"), + _orientation(HORIZONTAL), + _aspectRatio(0.03), + _sp(new ScalarPrinter) + { createDrawables(); - } + } - /** Copy constructor */ - ScalarBar(const ScalarBar& rhs, const osg::CopyOp& co): osg::Geode(rhs,co), - _numColors(rhs._numColors), - _numLabels(rhs._numLabels), - _stc(rhs._stc), // Consider clone for deep copy? - _title(rhs._title), - _orientation(rhs._orientation), - _aspectRatio(rhs._aspectRatio), - _sp(rhs._sp), // Consider clone for deep copy? - _textProperties(rhs._textProperties) - { - } + /** + Construct a ScalarBar with the supplied parameters. + @param numColors Specify the number of colors in the scalar bar. Color + interpolation occurs where necessary. + @param stc The ScalarsToColors defining the range of scalars + and the colors they map to. + @param title The title to be used when displaying the ScalarBar. + Specify "" for no title. + @param orientation The orientation of the ScalarBar. @see Orientation. + @param apectRatio The aspect ration (y/x) for the displayed bar. Bear in mind you + may want to change this if you change the orientation. + @param sp A ScalarPrinter object for the ScalarBar. For every displayed + ScalarBar label, the scalar value will be passed to the + ScalarPrinter object to turn it into a string. Users may + override the default ScalarPrinter object to map scalars to + whatever strings they wish. @see ScalarPrinter + */ + ScalarBar(int numColors, int numLabels, ScalarsToColors* stc, + const std::string& title, + Orientation orientation = HORIZONTAL, + float aspectRatio=0.25, + ScalarPrinter* sp=new ScalarPrinter): + osg::Geode(), + _numColors(numColors), + _numLabels(numLabels), + _stc(stc), + _title(title), + _orientation(orientation), + _aspectRatio(aspectRatio), + _sp(sp) + { + createDrawables(); + } - /** Set the number of distinct colours on the ScalarBar. */ - void setNumColors(int numColors); + /** Copy constructor */ + ScalarBar(const ScalarBar& rhs, const osg::CopyOp& co): osg::Geode(rhs,co), + _numColors(rhs._numColors), + _numLabels(rhs._numLabels), + _stc(rhs._stc), // Consider clone for deep copy? + _title(rhs._title), + _orientation(rhs._orientation), + _aspectRatio(rhs._aspectRatio), + _sp(rhs._sp), // Consider clone for deep copy? + _textProperties(rhs._textProperties) + { + } - /** Get the number of distinct colours on the ScalarBar. */ - int getNumColors() const; + /** Set the number of distinct colours on the ScalarBar. */ + void setNumColors(int numColors); - /** Set the number of labels to display along the ScalarBar. There - will be one label at each end point, and evenly distributed labels - in between. */ - void setNumLabels(int numLabels); + /** Get the number of distinct colours on the ScalarBar. */ + int getNumColors() const; - /** Get the number of labels displayed along the ScalarBar. */ - int getNumLabels() const; + /** Set the number of labels to display along the ScalarBar. There + will be one label at each end point, and evenly distributed labels + in between. */ + void setNumLabels(int numLabels); + + /** Get the number of labels displayed along the ScalarBar. */ + int getNumLabels() const; /** Set the ScalarsToColors mapping object for the ScalarBar. */ - void setScalarsToColors(ScalarsToColors* stc); + void setScalarsToColors(ScalarsToColors* stc); - /** Get the ScalarsToColors mapping object from the ScalarBar. */ + /** Get the ScalarsToColors mapping object from the ScalarBar. */ const ScalarsToColors* getScalarsToColors() const; - /** Set the title for the ScalarBar, set "" for no title. */ + /** Set the title for the ScalarBar, set "" for no title. */ void setTitle(const std::string& title); - /** Get the title for the ScalarBar. */ - std::string getTitle() const; + /** Get the title for the ScalarBar. */ + std::string getTitle() const; - /** Set the orientation of the ScalarBar. @see Orientation */ + /** Set the orientation of the ScalarBar. @see Orientation */ void setOrientation(ScalarBar::Orientation orientation); - /** Get the orientation of the ScalarBar. @see Orientation */ - ScalarBar::Orientation getOrientation() const; + /** Get the orientation of the ScalarBar. @see Orientation */ + ScalarBar::Orientation getOrientation() const; - /** Set the aspect ration (y/x) for the displayed bar. Bear in mind you - may want to change this if you change the orientation. */ + /** Set the aspect ration (y/x) for the displayed bar. Bear in mind you + may want to change this if you change the orientation. */ void setAspectRatio(float aspectRatio); - /** Get the aspect ration (y/x) for the displayed bar. */ - float getAspectRatio() const; + /** Get the aspect ration (y/x) for the displayed bar. */ + float getAspectRatio() const; - /** Set a ScalarPrinter object for the ScalarBar. For every displayed - ScalarBar label, the scalar value will be passed to the ScalarPrinter - object to turn it into a string. Users may override the default ScalarPrinter - object to map scalars to whatever strings they wish. @see ScalarPrinter */ + /** Set a ScalarPrinter object for the ScalarBar. For every displayed + ScalarBar label, the scalar value will be passed to the ScalarPrinter + object to turn it into a string. Users may override the default ScalarPrinter + object to map scalars to whatever strings they wish. @see ScalarPrinter */ void setScalarPrinter(ScalarPrinter* sp); - /** Get the ScalarPrinter object */ - const ScalarPrinter* getScalarPrinter() const; + /** Get the ScalarPrinter object */ + const ScalarPrinter* getScalarPrinter() const; - /** Set the TextProperties for the labels & title. @see TextProperties */ + /** Set the TextProperties for the labels & title. @see TextProperties */ void setTextProperties(const TextProperties& tp); - /** Get the TextProperties for the labels & title. @see TextProperties */ - const TextProperties& getTextProperties() const; + /** Get the TextProperties for the labels & title. @see TextProperties */ + const TextProperties& getTextProperties() const; - META_Node(osgSim, ScalarBar); + META_Node(osgSim, ScalarBar); private: int _numColors; - int _numLabels; - osg::ref_ptr _stc; - std::string _title; - Orientation _orientation; - float _aspectRatio; + int _numLabels; + osg::ref_ptr _stc; + std::string _title; + Orientation _orientation; + float _aspectRatio; osg::ref_ptr _sp; - TextProperties _textProperties; + TextProperties _textProperties; void createDrawables(); diff --git a/include/osgSim/ScalarsToColors b/include/osgSim/ScalarsToColors index 97ed3b4a1..dd7f989ca 100644 --- a/include/osgSim/ScalarsToColors +++ b/include/osgSim/ScalarsToColors @@ -32,16 +32,16 @@ class OSGSIM_EXPORT ScalarsToColors: public osg::Referenced public: ScalarsToColors(float scalarMin, float scalarMax); - virtual ~ScalarsToColors() {} + virtual ~ScalarsToColors() {} - /** Get the color for a given scalar value. */ + /** Get the color for a given scalar value. */ virtual osg::Vec4 getColor(float scalar) const; - /** Get the minimum scalar value. */ + /** Get the minimum scalar value. */ float getMin() const; - /** Get the maximum scalar value. */ - float getMax() const; + /** Get the maximum scalar value. */ + float getMax() const; private: diff --git a/include/osgSim/SphereSegment b/include/osgSim/SphereSegment index fbf823b17..688af4862 100644 --- a/include/osgSim/SphereSegment +++ b/include/osgSim/SphereSegment @@ -32,167 +32,167 @@ may be rendered various components switched on or off: - The specified area of the sphere surface. - An edge line around the boundary of the specified area - of the sphere surface. + of the sphere surface. - Four spokes, where a spoke is the line from the sphere's centre to a corner of the rendered area. - - Four planar areas, where the planar areas are formed - between the spokes. + - Four planar areas, where the planar areas are formed + between the spokes. Caveats: - It's worth noting that the line through the sphere's poles is parallel to the z axis. This has implications when specifying the area to be rendered, and specifying areas where the centre of - the rendered area is the Z axis may lead to unexpected - geometry. + the rendered area is the Z axis may lead to unexpected + geometry. - - It's possible to render the whole sphere by specifying elevation - and azimuth ranges round the full 360 degrees. When doing - so you may consider switching the planes, spokes, and edge lines - off, to avoid rendering artefacts, e.g. the upper and lower - planes will be coincident. + - It's possible to render the whole sphere by specifying elevation + and azimuth ranges round the full 360 degrees. When doing + so you may consider switching the planes, spokes, and edge lines + off, to avoid rendering artefacts, e.g. the upper and lower + planes will be coincident. */ class OSGSIM_EXPORT SphereSegment: public osg::Geode { public: - /** - DrawMask represents a bit field, the values of which may be OR'ed together - to specify which parts of the sphere segment should be drawn. E.g. - \code - sphereSegment->setDrawMask(SphereSegment::DrawMask(SphereSegment::SURFACE|SphereSegment::SPOKES)); - \endcode - */ - enum DrawMask{ + /** + DrawMask represents a bit field, the values of which may be OR'ed together + to specify which parts of the sphere segment should be drawn. E.g. + \code + sphereSegment->setDrawMask(SphereSegment::DrawMask(SphereSegment::SURFACE|SphereSegment::SPOKES)); + \endcode + */ + enum DrawMask{ SURFACE = 0x00000001, ///< Draw the specified area on the sphere's surface - SPOKES = 0x00000002, ///< Draw the spokes from the sphere's centre to the surface's corners - EDGELINE = 0x00000008, ///< Draw the line round the edge of the area on the sphere's surface - PLANES = 0x00000010, ///< Draw the planes from the sphere's centre to the edge of the sphere's surface - ALL = 0xffffffff ///< Draw every part of the sphere segment - }; + SPOKES = 0x00000002, ///< Draw the spokes from the sphere's centre to the surface's corners + EDGELINE = 0x00000008, ///< Draw the line round the edge of the area on the sphere's surface + SIDES = 0x00000010, ///< Draw the planes from the sphere's centre to the edge of the sphere's surface + ALL = 0xffffffff ///< Draw every part of the sphere segment + }; /** Default constructor. */ SphereSegment():Geode(), - _centre(0.0f,0.0f,0.0f), _radius(1.0f), - _azMin(0.0f), _azMax(osg::PI/2.0f), - _elevMin(0.0f), _elevMax(osg::PI/2.0f), - _density(10), - _drawMask(DrawMask(ALL)) - {} + _centre(0.0f,0.0f,0.0f), _radius(1.0f), + _azMin(0.0f), _azMax(osg::PI/2.0f), + _elevMin(0.0f), _elevMax(osg::PI/2.0f), + _density(10), + _drawMask(DrawMask(ALL)) + {} - /** - Construct by angle ranges. Note that the azimuth 'zero' is the Y axis; specifying - an azimuth range from azMin -osg::PI/2.0f to azMax osg::PI/2.0f will cover the - 'top half' of the circle in the XY plane. The elev angles are 'out' of the 'zero' - XY plane with +ve angles above the plane, and -ve angles below. - @param centre sphere centre + /** + Construct by angle ranges. Note that the azimuth 'zero' is the Y axis; specifying + an azimuth range from azMin -osg::PI/2.0f to azMax osg::PI/2.0f will cover the + 'top half' of the circle in the XY plane. The elev angles are 'out' of the 'zero' + XY plane with +ve angles above the plane, and -ve angles below. + @param centre sphere centre @param radius radius of sphere - @param azMin azimuth minimum - @param azMin azimuth maximum - @param elevMin elevation minimum - @param elevMax elevation maximum - @param density number of units to divide the azimuth and elevation ranges into - */ + @param azMin azimuth minimum + @param azMin azimuth maximum + @param elevMin elevation minimum + @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): - Geode(), - _centre(centre), _radius(radius), - _azMin(azMin), _azMax(azMax), - _elevMin(elevMin), _elevMax(elevMax), - _density(density), + float elevMin, float elevMax, int density): + Geode(), + _centre(centre), _radius(radius), + _azMin(azMin), _azMax(azMax), + _elevMin(elevMin), _elevMax(elevMax), + _density(density), _drawMask(DrawMask(ALL)) - { - init(); - } + { + init(); + } - /** - Construct by vector. - @param centre sphere centre + /** + Construct by vector. + @param centre sphere centre @param radius radius of sphere - @param vec vector pointing from sphere centre to centre point - of rendered area on sphere surface - @param azRange azimuth range in radians (with centre along vec) - @param elevRange elevation range in radians (with centre along vec) - @param density number of units to divide the azimuth and elevation ranges into - */ + @param vec vector pointing from sphere centre to centre point + of rendered area on sphere surface + @param azRange azimuth range in radians (with centre along vec) + @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); + float elevRange, int density); - /** Copy constructor */ - SphereSegment(const SphereSegment& rhs, const osg::CopyOp& co): - 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(); - } + /** Copy constructor */ + SphereSegment(const SphereSegment& rhs, const osg::CopyOp& co): + 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(); + } - /** Set the centre point of the SphereSegment */ + /** Set the centre point of the SphereSegment */ void setCentre(const osg::Vec3& c); - /** Get the centre point of the SphereSegment */ - const osg::Vec3& getCentre() const; + /** Get the centre point of the SphereSegment */ + const osg::Vec3& getCentre() const; - /** Set the radius of the SphereSegment */ + /** Set the radius of the SphereSegment */ void setRadius(float r); - /** Get the radius of the SphereSegment */ - float getRadius() const; + /** Get the radius of the SphereSegment */ + float getRadius() const; - /** Set the area of the sphere segment + /** Set the area of the sphere segment - @param vec vector pointing from sphere centre to centre point - of rendered area on sphere surface - @param azRange azimuth range in radians (with centre along vec) - @param elevRange elevation range in radians (with centre along vec) - */ - void setArea(const osg::Vec3& v, float azRange, float elevRange); + @param vec vector pointing from sphere centre to centre point + of rendered area on sphere surface + @param azRange azimuth range in radians (with centre along vec) + @param elevRange elevation range in radians (with centre along vec) + */ + void setArea(const osg::Vec3& v, float azRange, float elevRange); - /** Get the area of the sphere segment + /** Get the area of the sphere segment - @param vec vector pointing from sphere centre to centre point - of rendered area on sphere surface (normalized) - @param azRange azimuth range in radians (with centre along vec) - @param elevRange elevation range in radians (with centre along vec) - */ + @param vec vector pointing from sphere centre to centre point + of rendered area on sphere surface (normalized) + @param azRange azimuth range in radians (with centre along vec) + @param elevRange elevation range in radians (with centre along vec) + */ void getArea(osg::Vec3& v, float& azRange, float& elevRange) const; - /** Set the density of the sphere segment */ - void setDensity(int d); + /** Set the density of the sphere segment */ + void setDensity(int d); /** Get the density of the sphere segment */ - int getDensity() const; + int getDensity() const; - /** - Specify the DrawMask. - @param dm Bitmask specifying which parts of the sphere segment should be drawn. - @see DrawMask - */ + /** + Specify the DrawMask. + @param dm Bitmask specifying which parts of the sphere segment should be drawn. + @see DrawMask + */ void setDrawMask(DrawMask dm); - /** Set the color of the surface. */ + /** Set the color of the surface. */ void setSurfaceColor(const osg::Vec4& c); - /** Set the color of the spokes. */ - void setSpokeColor(const osg::Vec4& c); + /** Set the color of the spokes. */ + void setSpokeColor(const osg::Vec4& c); - /** Set the color of the edge line. */ - void setEdgeLineColor(const osg::Vec4& c); + /** Set the color of the edge line. */ + void setEdgeLineColor(const osg::Vec4& c); - /** Set the color of the planes. */ - void setPlaneColor(const osg::Vec4& c); + /** Set the color of the planes. */ + void setSideColor(const osg::Vec4& c); - /** Set color of all components. */ - void setAllColors(const osg::Vec4& c); + /** Set color of all components. */ + void setAllColors(const osg::Vec4& c); - META_Node(osgSim, SphereSegment) + META_Node(osgSim, SphereSegment) private: @@ -201,57 +201,57 @@ private: 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 + // 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. + // 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; + 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; + 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 Plane class? Because we can't forward - enum PlaneOrientation{AZIM,ELEV}; // declare enums, Plane is in the .cpp, and this is tidier... - class Plane; - friend class Plane; - bool Plane_computeBound(osg::BoundingBox&, PlaneOrientation, BoundaryAngle) const; - void Plane_drawImplementation(osg::State&, PlaneOrientation, BoundaryAngle) 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; + class Spoke; + friend class Spoke; + bool Spoke_computeBound(osg::BoundingBox&, BoundaryAngle, BoundaryAngle) const; + void Spoke_drawImplementation(osg::State&, BoundaryAngle, BoundaryAngle) const; // Sphere segment geometry details osg::Vec3 _centre; - float _radius; + float _radius; float _azMin, _azMax, _elevMin, _elevMax; - int _density; + int _density; - // Draw details - DrawMask _drawMask; + // Draw details + DrawMask _drawMask; osg::Vec4 _surfaceColor; - osg::Vec4 _spokeColor; - osg::Vec4 _edgeLineColor; - osg::Vec4 _planeColor; + osg::Vec4 _spokeColor; + osg::Vec4 _edgeLineColor; + osg::Vec4 _planeColor; }; } diff --git a/src/osgSim/ScalarBar.cpp b/src/osgSim/ScalarBar.cpp index 702e9795b..7b3cc358b 100644 --- a/src/osgSim/ScalarBar.cpp +++ b/src/osgSim/ScalarBar.cpp @@ -246,8 +246,8 @@ void ScalarBar::createDrawables() // vertical alignment depending on the letters used in the labels. E.g. a 'y' has a dangling tail. if(_orientation == HORIZONTAL) { - std::vector::iterator maxYIt = max_element(texts.begin(), texts.end(), MaxCoordLess(MaxCoordLess::Y_AXIS)); - for_each(texts.begin(), texts.end(), AlignCentreOnYValue((*maxYIt)->getBound().center().y())); + std::vector::iterator maxYIt = std::max_element(texts.begin(), texts.end(), MaxCoordLess(MaxCoordLess::Y_AXIS)); + std::for_each(texts.begin(), texts.end(), AlignCentreOnYValue((*maxYIt)->getBound().center().y())); } // 3. And finally the title @@ -268,7 +268,7 @@ void ScalarBar::createDrawables() // Need to move the title above any labels, using maximum y value of the // existing text objects - std::vector::iterator maxYIt = max_element(texts.begin(), texts.end(), MaxCoordLess(MaxCoordLess::Y_AXIS)); + std::vector::iterator maxYIt = std::max_element(texts.begin(), texts.end(), MaxCoordLess(MaxCoordLess::Y_AXIS)); float titleY; if(maxYIt != texts.end()) titleY = (*maxYIt)->getBound().yMax() * 1.1f; @@ -284,7 +284,7 @@ void ScalarBar::createDrawables() // Need to move the title out beyond any labels, using the maximum x value of the // existing text objects - std::vector::iterator maxXIt = max_element(texts.begin(), texts.end(), MaxCoordLess(MaxCoordLess::X_AXIS)); + std::vector::iterator maxXIt = std::max_element(texts.begin(), texts.end(), MaxCoordLess(MaxCoordLess::X_AXIS)); float titleX; if(maxXIt != texts.end()) titleX = (*maxXIt)->getBound().xMax() * 1.1f; diff --git a/src/osgSim/SphereSegment.cpp b/src/osgSim/SphereSegment.cpp index 0a32bfcd7..ae09ab59a 100644 --- a/src/osgSim/SphereSegment.cpp +++ b/src/osgSim/SphereSegment.cpp @@ -13,19 +13,19 @@ sphere's surface. class SphereSegment::Surface: public osg::Drawable { public: - Surface(SphereSegment* ss): Drawable(), _ss(ss) {} + Surface(SphereSegment* ss): Drawable(), _ss(ss) {} - Surface():_ss(0) - { - osg::notify(osg::WARN)<< - "Warning: unexpected call to osgSim::SphereSegment::Surface() default constructor"<Plane_drawImplementation(state, _planeOrientation, _BoundaryAngle); + _ss->Side_drawImplementation(state, _planeOrientation, _BoundaryAngle); } -bool SphereSegment::Plane::computeBound() const +bool SphereSegment::Side::computeBound() const { - _bbox_computed = _ss->Plane_computeBound(_bbox, _planeOrientation, _BoundaryAngle); + _bbox_computed = _ss->Side_computeBound(_bbox, _planeOrientation, _BoundaryAngle); return _bbox_computed; } @@ -155,20 +155,20 @@ SphereSegment::Spoke is a Drawable which represents a spoke. class SphereSegment::Spoke: public osg::Drawable { public: - Spoke(SphereSegment* ss, SphereSegment::BoundaryAngle azAngle, SphereSegment::BoundaryAngle elevAngle): - Drawable(), _ss(ss), _azAngle(azAngle), _elevAngle(elevAngle) {} + Spoke(SphereSegment* ss, SphereSegment::BoundaryAngle azAngle, SphereSegment::BoundaryAngle elevAngle): + Drawable(), _ss(ss), _azAngle(azAngle), _elevAngle(elevAngle) {} - Spoke():_ss(0) - { - osg::notify(osg::WARN)<< - "Warning: unexpected call to osgSim::SphereSegment::Spoke() default constructor"<& dptr) - { + { dptr->dirtyDisplayList(); - } + } }; } void SphereSegment::dirtyAllDrawableDisplayLists() { - for_each(_drawables.begin(), _drawables.end(), DirtyDisplayList()); + std::for_each(_drawables.begin(), _drawables.end(), DirtyDisplayList()); } namespace @@ -324,325 +324,325 @@ namespace struct DirtyBound { void operator()(osg::ref_ptr& dptr) - { + { dptr->dirtyBound(); - } + } }; } void SphereSegment::dirtyAllDrawableBounds() { - for_each(_drawables.begin(), _drawables.end(), DirtyBound()); + std::for_each(_drawables.begin(), _drawables.end(), DirtyBound()); } void SphereSegment::Surface_drawImplementation(osg::State& /* state */) const { - const float azIncr = (_azMax - _azMin)/_density; - const float elevIncr = (_elevMax - _elevMin)/_density; + const float azIncr = (_azMax - _azMin)/_density; + const float elevIncr = (_elevMax - _elevMin)/_density; - // Draw the area on the sphere surface if needed - // --------------------------------------------- + // Draw the area on the sphere surface if needed + // --------------------------------------------- if(_drawMask & SURFACE) - { - glColor4fv(_surfaceColor.ptr()); + { + glColor4fv(_surfaceColor.ptr()); - for(int i=0; i+1<=_density; i++) - { - // Because we're drawing quad strips, we need to work out - // two azimuth values, to form each edge of the (z-vertical) - // strips - float az1 = _azMin + (i*azIncr); - float az2 = _azMin + ((i+1)*azIncr); + for(int i=0; i+1<=_density; i++) + { + // Because we're drawing quad strips, we need to work out + // two azimuth values, to form each edge of the (z-vertical) + // strips + float az1 = _azMin + (i*azIncr); + float az2 = _azMin + ((i+1)*azIncr); - glBegin(GL_QUAD_STRIP); - for (int j=0; j<=_density; j++) - { - float elev = _elevMin + (j*elevIncr); + glBegin(GL_QUAD_STRIP); + for (int j=0; j<=_density; j++) + { + float elev = _elevMin + (j*elevIncr); - // QuadStrip Edge formed at az1 - // ---------------------------- + // QuadStrip Edge formed at az1 + // ---------------------------- - // Work out the sphere normal - float x = cos(elev)*sin(az1); - float y = cos(elev)*cos(az1); - float z = sin(elev); + // Work out the sphere normal + float x = cos(elev)*sin(az1); + float y = cos(elev)*cos(az1); + float z = sin(elev); - glNormal3f(x, y, z); - glVertex3f(_centre.x() + _radius*x, - _centre.y() + _radius*y, - _centre.z() + _radius*z); + glNormal3f(x, y, z); + glVertex3f(_centre.x() + _radius*x, + _centre.y() + _radius*y, + _centre.z() + _radius*z); - // QuadStrip Edge formed at az2 - // ---------------------------- + // QuadStrip Edge formed at az2 + // ---------------------------- - // Work out the sphere normal - x = cos(elev)*sin(az2); - y = cos(elev)*cos(az2); - // z = sin(elev); z doesn't change + // Work out the sphere normal + x = cos(elev)*sin(az2); + y = cos(elev)*cos(az2); + // z = sin(elev); z doesn't change - glNormal3f(x, y, z); - glVertex3f(_centre.x() + _radius*x, - _centre.y() + _radius*y, - _centre.z() + _radius*z); - } - glEnd(); - } - } + glNormal3f(x, y, z); + glVertex3f(_centre.x() + _radius*x, + _centre.y() + _radius*y, + _centre.z() + _radius*z); + } + glEnd(); + } + } } bool SphereSegment::Surface_computeBound(osg::BoundingBox& bbox) const { - bbox.init(); + bbox.init(); - float azIncr = (_azMax - _azMin)/_density; - float elevIncr = (_elevMax - _elevMin)/_density; + float azIncr = (_azMax - _azMin)/_density; + float elevIncr = (_elevMax - _elevMin)/_density; - for(int i=0; i<=_density; i++){ + for(int i=0; i<=_density; i++){ - float az = _azMin + (i*azIncr); + float az = _azMin + (i*azIncr); - for(int j=0; j<=_density; j++){ + for(int j=0; j<=_density; j++){ - float elev = _elevMin + (j*elevIncr); + float elev = _elevMin + (j*elevIncr); - bbox.expandBy( - osg::Vec3(_centre.x() + _radius*cos(elev)*sin(az), - _centre.y() + _radius*cos(elev)*cos(az), - _centre.z() + _radius*sin(elev)) - ); - } - } - return true; + bbox.expandBy( + osg::Vec3(_centre.x() + _radius*cos(elev)*sin(az), + _centre.y() + _radius*cos(elev)*cos(az), + _centre.z() + _radius*sin(elev)) + ); + } + } + return true; } void SphereSegment::EdgeLine_drawImplementation(osg::State& /* state */) const { // FIXME: Disable lighting for this draw routine - const float azIncr = (_azMax - _azMin)/_density; - const float elevIncr = (_elevMax - _elevMin)/_density; + const float azIncr = (_azMax - _azMin)/_density; + const float elevIncr = (_elevMax - _elevMin)/_density; - // Draw the edgeline if necessary - // ------------------------------ + // Draw the edgeline if necessary + // ------------------------------ if(_drawMask & EDGELINE) - { - glColor4fv(_edgeLineColor.ptr()); + { + glColor4fv(_edgeLineColor.ptr()); // Top edge - glBegin(GL_LINE_STRIP); - for(int i=0; i<=_density; i++) - { - float az = _azMin + (i*azIncr); - glVertex3f( - _centre.x() + _radius*cos(_elevMax)*sin(az), - _centre.y() + _radius*cos(_elevMax)*cos(az), - _centre.z() + _radius*sin(_elevMax)); + glBegin(GL_LINE_STRIP); + for(int i=0; i<=_density; i++) + { + float az = _azMin + (i*azIncr); + glVertex3f( + _centre.x() + _radius*cos(_elevMax)*sin(az), + _centre.y() + _radius*cos(_elevMax)*cos(az), + _centre.z() + _radius*sin(_elevMax)); } - glEnd(); + glEnd(); - // Bottom edge - glBegin(GL_LINE_STRIP); - for(int i=0; i<=_density; i++) - { - float az = _azMin + (i*azIncr); - glVertex3f( - _centre.x() + _radius*cos(_elevMin)*sin(az), - _centre.y() + _radius*cos(_elevMin)*cos(az), - _centre.z() + _radius*sin(_elevMin)); - } - glEnd(); + // Bottom edge + glBegin(GL_LINE_STRIP); + for(int i=0; i<=_density; i++) + { + float az = _azMin + (i*azIncr); + glVertex3f( + _centre.x() + _radius*cos(_elevMin)*sin(az), + _centre.y() + _radius*cos(_elevMin)*cos(az), + _centre.z() + _radius*sin(_elevMin)); + } + glEnd(); - // Left edge - glBegin(GL_LINE_STRIP); - for(int j=0; j<=_density; j++) - { - float elev = _elevMin + (j*elevIncr); - glVertex3f( - _centre.x() + _radius*cos(elev)*sin(_azMin), - _centre.y() + _radius*cos(elev)*cos(_azMin), - _centre.z() + _radius*sin(elev)); - } - glEnd(); + // Left edge + glBegin(GL_LINE_STRIP); + for(int j=0; j<=_density; j++) + { + float elev = _elevMin + (j*elevIncr); + glVertex3f( + _centre.x() + _radius*cos(elev)*sin(_azMin), + _centre.y() + _radius*cos(elev)*cos(_azMin), + _centre.z() + _radius*sin(elev)); + } + glEnd(); - // Right edge - glBegin(GL_LINE_STRIP); - for(int j=0; j<=_density; j++) - { - float elev = _elevMin + (j*elevIncr); - glVertex3f( - _centre.x() + _radius*cos(elev)*sin(_azMax), - _centre.y() + _radius*cos(elev)*cos(_azMax), - _centre.z() + _radius*sin(elev)); - } - glEnd(); - } + // Right edge + glBegin(GL_LINE_STRIP); + for(int j=0; j<=_density; j++) + { + float elev = _elevMin + (j*elevIncr); + glVertex3f( + _centre.x() + _radius*cos(elev)*sin(_azMax), + _centre.y() + _radius*cos(elev)*cos(_azMax), + _centre.z() + _radius*sin(elev)); + } + glEnd(); + } } bool SphereSegment::EdgeLine_computeBound(osg::BoundingBox& bbox) const { - bbox.init(); + bbox.init(); - float azIncr = (_azMax - _azMin)/_density; - float elevIncr = (_elevMax - _elevMin)/_density; + float azIncr = (_azMax - _azMin)/_density; + float elevIncr = (_elevMax - _elevMin)/_density; - // Top edge - for(int i=0; i<=_density; i++) - { - float az = _azMin + (i*azIncr); - bbox.expandBy( - _centre.x() + _radius*cos(_elevMax)*sin(az), - _centre.y() + _radius*cos(_elevMax)*cos(az), - _centre.z() + _radius*sin(_elevMax)); - } + // Top edge + for(int i=0; i<=_density; i++) + { + float az = _azMin + (i*azIncr); + bbox.expandBy( + _centre.x() + _radius*cos(_elevMax)*sin(az), + _centre.y() + _radius*cos(_elevMax)*cos(az), + _centre.z() + _radius*sin(_elevMax)); + } - // Bottom edge - for(int i=0; i<=_density; i++) - { - float az = _azMin + (i*azIncr); - bbox.expandBy( - _centre.x() + _radius*cos(_elevMin)*sin(az), - _centre.y() + _radius*cos(_elevMin)*cos(az), - _centre.z() + _radius*sin(_elevMin)); - } + // Bottom edge + for(int i=0; i<=_density; i++) + { + float az = _azMin + (i*azIncr); + bbox.expandBy( + _centre.x() + _radius*cos(_elevMin)*sin(az), + _centre.y() + _radius*cos(_elevMin)*cos(az), + _centre.z() + _radius*sin(_elevMin)); + } - // Left edge - for(int j=0; j<=_density; j++) - { - float elev = _elevMin + (j*elevIncr); - bbox.expandBy( - _centre.x() + _radius*cos(elev)*sin(_azMin), - _centre.y() + _radius*cos(elev)*cos(_azMin), - _centre.z() + _radius*sin(elev)); - } + // Left edge + for(int j=0; j<=_density; j++) + { + float elev = _elevMin + (j*elevIncr); + bbox.expandBy( + _centre.x() + _radius*cos(elev)*sin(_azMin), + _centre.y() + _radius*cos(elev)*cos(_azMin), + _centre.z() + _radius*sin(elev)); + } - // Right edge - for(int j=0; j<=_density; j++) - { - float elev = _elevMin + (j*elevIncr); - bbox.expandBy( - _centre.x() + _radius*cos(elev)*sin(_azMax), - _centre.y() + _radius*cos(elev)*cos(_azMax), - _centre.z() + _radius*sin(elev)); - } + // Right edge + for(int j=0; j<=_density; j++) + { + float elev = _elevMin + (j*elevIncr); + bbox.expandBy( + _centre.x() + _radius*cos(elev)*sin(_azMax), + _centre.y() + _radius*cos(elev)*cos(_azMax), + _centre.z() + _radius*sin(elev)); + } - return true; + return true; } -void SphereSegment::Plane_drawImplementation(osg::State& /* state */, - SphereSegment::PlaneOrientation orientation, +void SphereSegment::Side_drawImplementation(osg::State& /* state */, + SphereSegment::SideOrientation orientation, SphereSegment::BoundaryAngle boundaryAngle) const { - // Draw the planes if necessary - // ---------------------------- - if(_drawMask & PLANES) - { - if(orientation == AZIM) // This is a plane at a given azimuth - { - const float az = (boundaryAngle==MIN?_azMin:_azMax); - const float elevIncr = (_elevMax - _elevMin)/_density; + // Draw the planes if necessary + // ---------------------------- + if(_drawMask & SIDES) + { + if(orientation == AZIM) // This is a plane at a given azimuth + { + const float az = (boundaryAngle==MIN?_azMin:_azMax); + const float elevIncr = (_elevMax - _elevMin)/_density; - // Normal - osg::Vec3 normal = osg::Vec3(cos(_elevMin)*sin(az), cos(_elevMin)*cos(az), sin(_elevMin)) - ^ osg::Vec3(cos(_elevMax)*sin(az), cos(_elevMax)*cos(az), sin(_elevMax)); - if(boundaryAngle==MIN) normal = -normal; // Make sure normals orientationint 'outwards' - glNormal3fv(normal.ptr()); + // Normal + osg::Vec3 normal = osg::Vec3(cos(_elevMin)*sin(az), cos(_elevMin)*cos(az), sin(_elevMin)) + ^ osg::Vec3(cos(_elevMax)*sin(az), cos(_elevMax)*cos(az), sin(_elevMax)); + if(boundaryAngle==MIN) normal = -normal; // Make sure normals orientationint 'outwards' + glNormal3fv(normal.ptr()); - // Tri fan - glBegin(GL_TRIANGLE_FAN); - glVertex3fv(_centre.ptr()); - for (int j=0; j<=_density; j++) - { - float elev = _elevMin + (j*elevIncr); - glVertex3f( _centre.x() + _radius*cos(elev)*sin(az), - _centre.y() + _radius*cos(elev)*cos(az), - _centre.z() + _radius*sin(elev)); - } - glEnd(); - } - else if(orientation == ELEV) // This is a plane at a given elevation - { - const float elev = (boundaryAngle==MIN?_elevMin:_elevMax); - const float azIncr = (_azMax - _azMin)/_density; + // Tri fan + glBegin(GL_TRIANGLE_FAN); + glVertex3fv(_centre.ptr()); + for (int j=0; j<=_density; j++) + { + float elev = _elevMin + (j*elevIncr); + glVertex3f( _centre.x() + _radius*cos(elev)*sin(az), + _centre.y() + _radius*cos(elev)*cos(az), + _centre.z() + _radius*sin(elev)); + } + glEnd(); + } + else if(orientation == ELEV) // This is a plane at a given elevation + { + const float elev = (boundaryAngle==MIN?_elevMin:_elevMax); + const float azIncr = (_azMax - _azMin)/_density; - // Normal - osg::Vec3 normal = osg::Vec3(cos(elev)*sin(_azMax), cos(elev)*cos(_azMax), sin(elev)) - ^ osg::Vec3(cos(elev)*sin(_azMin), cos(elev)*cos(_azMin), sin(elev)); - if(boundaryAngle==MIN) normal = -normal; // Make sure normals orientationint 'outwards' - glNormal3fv(normal.ptr()); + // Normal + osg::Vec3 normal = osg::Vec3(cos(elev)*sin(_azMax), cos(elev)*cos(_azMax), sin(elev)) + ^ osg::Vec3(cos(elev)*sin(_azMin), cos(elev)*cos(_azMin), sin(elev)); + if(boundaryAngle==MIN) normal = -normal; // Make sure normals orientationint 'outwards' + glNormal3fv(normal.ptr()); - // Tri fan - glBegin(GL_TRIANGLE_FAN); - glVertex3fv(_centre.ptr()); - for(int i=0; i<=_density; i++) - { - float az = _azMin + (i*azIncr); - glVertex3f( _centre.x() + _radius*cos(elev)*sin(az), - _centre.y() + _radius*cos(elev)*cos(az), - _centre.z() + _radius*sin(elev)); - } - glEnd(); - } - } + // Tri fan + glBegin(GL_TRIANGLE_FAN); + glVertex3fv(_centre.ptr()); + for(int i=0; i<=_density; i++) + { + float az = _azMin + (i*azIncr); + glVertex3f( _centre.x() + _radius*cos(elev)*sin(az), + _centre.y() + _radius*cos(elev)*cos(az), + _centre.z() + _radius*sin(elev)); + } + glEnd(); + } + } } -bool SphereSegment::Plane_computeBound(osg::BoundingBox& bbox, - SphereSegment::PlaneOrientation orientation, +bool SphereSegment::Side_computeBound(osg::BoundingBox& bbox, + SphereSegment::SideOrientation orientation, SphereSegment::BoundaryAngle boundaryAngle) const { - bbox.init(); - bbox.expandBy(_centre); + bbox.init(); + bbox.expandBy(_centre); if(orientation == AZIM) // This is a plane at a given azimuth - { - const float az = (boundaryAngle==MIN?_azMin:_azMax); - const float elevIncr = (_elevMax - _elevMin)/_density; + { + const float az = (boundaryAngle==MIN?_azMin:_azMax); + const float elevIncr = (_elevMax - _elevMin)/_density; - for (int j=0; j<=_density; j++) - { - float elev = _elevMin + (j*elevIncr); - bbox.expandBy( - _centre.x() + _radius*cos(elev)*sin(az), - _centre.y() + _radius*cos(elev)*cos(az), - _centre.z() + _radius*sin(elev)); - } - } - else if(orientation == ELEV) // This is a plane at a given elevation - { + for (int j=0; j<=_density; j++) + { + float elev = _elevMin + (j*elevIncr); + bbox.expandBy( + _centre.x() + _radius*cos(elev)*sin(az), + _centre.y() + _radius*cos(elev)*cos(az), + _centre.z() + _radius*sin(elev)); + } + } + else if(orientation == ELEV) // This is a plane at a given elevation + { const float elev = (boundaryAngle==MIN?_elevMin:_elevMax); - const float azIncr = (_azMax - _azMin)/_density; + const float azIncr = (_azMax - _azMin)/_density; - for(int i=0; i<=_density; i++) - { - float az = _azMin + (i*azIncr); - bbox.expandBy( - _centre.x() + _radius*cos(elev)*sin(az), - _centre.y() + _radius*cos(elev)*cos(az), - _centre.z() + _radius*sin(elev)); - } - } + for(int i=0; i<=_density; i++) + { + float az = _azMin + (i*azIncr); + bbox.expandBy( + _centre.x() + _radius*cos(elev)*sin(az), + _centre.y() + _radius*cos(elev)*cos(az), + _centre.z() + _radius*sin(elev)); + } + } - return true; + return true; } void SphereSegment::Spoke_drawImplementation(osg::State&, BoundaryAngle azAngle, BoundaryAngle elevAngle) const { // FIXME: Disable lighting for this draw routine - if(_drawMask & SPOKES){ + if(_drawMask & SPOKES){ - glColor4fv(_spokeColor.ptr()); + glColor4fv(_spokeColor.ptr()); - const float az = (azAngle==MIN?_azMin:_azMax); + const float az = (azAngle==MIN?_azMin:_azMax); const float elev = (elevAngle==MIN?_elevMin:_elevMax); - glBegin(GL_LINES); - glVertex3fv(_centre.ptr()); - glVertex3f( _centre.x() + _radius*cos(elev)*sin(az), - _centre.y() + _radius*cos(elev)*cos(az), - _centre.z() + _radius*sin(elev)); - glEnd(); - } + glBegin(GL_LINES); + glVertex3fv(_centre.ptr()); + glVertex3f( _centre.x() + _radius*cos(elev)*sin(az), + _centre.y() + _radius*cos(elev)*cos(az), + _centre.z() + _radius*sin(elev)); + glEnd(); + } } bool SphereSegment::Spoke_computeBound(osg::BoundingBox& bbox, BoundaryAngle azAngle, BoundaryAngle elevAngle) const @@ -650,20 +650,20 @@ bool SphereSegment::Spoke_computeBound(osg::BoundingBox& bbox, BoundaryAngle azA const float az = (azAngle==MIN?_azMin:_azMax); const float elev = (elevAngle==MIN?_elevMin:_elevMax); - bbox.expandBy(_centre); - bbox.expandBy( _centre.x() + _radius*cos(elev)*sin(az), + bbox.expandBy(_centre); + bbox.expandBy( _centre.x() + _radius*cos(elev)*sin(az), _centre.y() + _radius*cos(elev)*cos(az), - _centre.z() + _radius*sin(elev)); + _centre.z() + _radius*sin(elev)); - return true; + return true; } void SphereSegment::setDrawMask(DrawMask dm) { _drawMask=dm; - dirtyAllDrawableDisplayLists(); - dirtyAllDrawableBounds(); - dirtyBound(); + dirtyAllDrawableDisplayLists(); + dirtyAllDrawableBounds(); + dirtyBound(); } namespace{ @@ -673,25 +673,25 @@ struct ActivateTransparencyOnType ActivateTransparencyOnType(const std::type_info& t): _t(t) {} void operator()(osg::ref_ptr& dptr) const - { + { if(typeid(*dptr)==_t) - { - osg::StateSet* ss = dptr->getStateSet(); - if(!ss) - { - ss = new osg::StateSet(); - dptr->setStateSet(ss); - } - ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); + { + osg::StateSet* ss = dptr->getStateSet(); + if(!ss) + { + ss = new osg::StateSet(); + dptr->setStateSet(ss); + } + ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - osg::BlendFunc* trans = new osg::BlendFunc; - trans->setFunction(osg::BlendFunc::ONE,osg::BlendFunc::ONE); + osg::BlendFunc* trans = new osg::BlendFunc; + trans->setFunction(osg::BlendFunc::ONE,osg::BlendFunc::ONE); - ss->setAttributeAndModes(trans,osg::StateAttribute::ON); + ss->setAttributeAndModes(trans,osg::StateAttribute::ON); - dptr->dirtyDisplayList(); - } - } + dptr->dirtyDisplayList(); + } + } const std::type_info& _t; }; @@ -701,15 +701,15 @@ struct DeactivateTransparencyOnType DeactivateTransparencyOnType(const std::type_info& t): _t(t) {} void operator()(osg::ref_ptr& dptr) const - { + { if(typeid(*dptr)==_t) - { - osg::StateSet* ss = dptr->getStateSet(); - if(ss) ss->setRenderingHint(osg::StateSet::OPAQUE_BIN); + { + osg::StateSet* ss = dptr->getStateSet(); + if(ss) ss->setRenderingHint(osg::StateSet::OPAQUE_BIN); - dptr->dirtyDisplayList(); - } - } + dptr->dirtyDisplayList(); + } + } const std::type_info& _t; }; @@ -718,40 +718,40 @@ struct DeactivateTransparencyOnType void SphereSegment::setSurfaceColor(const osg::Vec4& c) { - _surfaceColor=c; + _surfaceColor=c; - if(c.w() != 1.0) for_each(_drawables.begin(), _drawables.end(), ActivateTransparencyOnType(typeid(Surface))); - else for_each(_drawables.begin(), _drawables.end(), DeactivateTransparencyOnType(typeid(Surface))); + if(c.w() != 1.0) std::for_each(_drawables.begin(), _drawables.end(), ActivateTransparencyOnType(typeid(Surface))); + else std::for_each(_drawables.begin(), _drawables.end(), DeactivateTransparencyOnType(typeid(Surface))); } void SphereSegment::setSpokeColor(const osg::Vec4& c) { - _spokeColor=c; + _spokeColor=c; - if(c.w() != 1.0) for_each(_drawables.begin(), _drawables.end(), ActivateTransparencyOnType(typeid(Spoke))); - else for_each(_drawables.begin(), _drawables.end(), DeactivateTransparencyOnType(typeid(Spoke))); + if(c.w() != 1.0) std::for_each(_drawables.begin(), _drawables.end(), ActivateTransparencyOnType(typeid(Spoke))); + else std::for_each(_drawables.begin(), _drawables.end(), DeactivateTransparencyOnType(typeid(Spoke))); } void SphereSegment::setEdgeLineColor(const osg::Vec4& c) { - _edgeLineColor=c; + _edgeLineColor=c; - if(c.w() != 1.0) for_each(_drawables.begin(), _drawables.end(), ActivateTransparencyOnType(typeid(EdgeLine))); - else for_each(_drawables.begin(), _drawables.end(), DeactivateTransparencyOnType(typeid(EdgeLine))); + if(c.w() != 1.0) std::for_each(_drawables.begin(), _drawables.end(), ActivateTransparencyOnType(typeid(EdgeLine))); + else std::for_each(_drawables.begin(), _drawables.end(), DeactivateTransparencyOnType(typeid(EdgeLine))); } -void SphereSegment::setPlaneColor(const osg::Vec4& c) +void SphereSegment::setSideColor(const osg::Vec4& c) { - _planeColor=c; + _planeColor=c; - if(c.w() != 1.0) for_each(_drawables.begin(), _drawables.end(), ActivateTransparencyOnType(typeid(Plane))); - else for_each(_drawables.begin(), _drawables.end(), DeactivateTransparencyOnType(typeid(Plane))); + if(c.w() != 1.0) std::for_each(_drawables.begin(), _drawables.end(), ActivateTransparencyOnType(typeid(Side))); + else std::for_each(_drawables.begin(), _drawables.end(), DeactivateTransparencyOnType(typeid(Side))); } void SphereSegment::setAllColors(const osg::Vec4& c) { setSurfaceColor(c); - setSpokeColor(c); - setEdgeLineColor(c); - setPlaneColor(c); + setSpokeColor(c); + setEdgeLineColor(c); + setSideColor(c); }