SphereSegment
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGSIM_SPHERESEGMENT
#define OSGSIM_SPHERESEGMENT 1
#include <osgSim/Export>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Geode>
#include <osg/Matrixd>
#include <osg/BlendFunc>
#include <osg/Geometry>
namespace osgSim{
class OSGSIM_EXPORT SphereSegment: public osg::Geode
{
public:
enum DrawMask{
SURFACE = 0x00000001,
SPOKES = 0x00000002,
EDGELINE = 0x00000008,
SIDES = 0x00000010,
ALL = 0x7fffffff
};
SphereSegment():osg::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))
{
init();
}
SphereSegment(const osg::Vec3& centre, float radius, float azMin, float azMax, float elevMin, float elevMax, int density);
SphereSegment(const osg::Vec3& centre, float radius, const osg::Vec3& vec, float azRange, float elevRange, int density);
SphereSegment(const SphereSegment& rhs, const osg::CopyOp& co);
void traverse(osg::NodeVisitor& nv);
void setCentre(const osg::Vec3& c);
const osg::Vec3& getCentre() const;
void setRadius(float r);
float getRadius() const;
void setArea(const osg::Vec3& vec, float azRange, float elevRange);
void getArea(osg::Vec3& vec, float& azRange, float& elevRange) const;
void setArea(float azMin, float azMax, float elevMin, float elevMax);
void getArea(float &azMin, float &azMax, float &elevMin, float &elevMax) const;
void setDensity(int d);
int getDensity() const;
void setDrawMask(int dm);
int getDrawMask() const { return _drawMask; }
void setSurfaceColor(const osg::Vec4& c);
const osg::Vec4& getSurfaceColor() const { return (*_surfaceColor)[0]; }
void setSpokeColor(const osg::Vec4& c);
const osg::Vec4& getSpokeColor() const { return (*_spokeColor)[0]; }
void setEdgeLineColor(const osg::Vec4& c);
const osg::Vec4& getEdgeLineColor() const { return (*_edgeLineColor)[0]; }
void setSideColor(const osg::Vec4& c);
const osg::Vec4& getSideColor() const { return (*_sideColor)[0]; }
void setAllColors(const osg::Vec4& c);
META_Node(osgSim, SphereSegment);
typedef std::vector< osg::ref_ptr<osg::Vec3Array> > LineList;
LineList computeIntersection(const osg::Matrixd& matrix, osg::Node* subgraph);
LineList computeIntersection(const osg::Matrixd& matrix, osg::Drawable* drawable);
osg::Node* computeIntersectionSubgraph(const osg::Matrixd& matrix, osg::Node* subgraph);
osg::Node* computeIntersectionSubgraph(const osg::Matrixd& matrix, osg::Drawable* drawable);
void updatePositions();
void updatePrimitives();
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(osg::State* state = 0) const;
virtual osg::BoundingSphere computeBound() const;
private:
void init(); // Shared constructor code, generates the drawables
void dirty(); // Force re-calling of gl functions and bounding boxes
// Sphere segment geometry details
osg::Vec3 _centre;
float _radius;
float _azMin, _azMax, _elevMin, _elevMax;
int _density;
// Draw details
int _drawMask;
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(); }
};
}
#endif
BlendFunc
Geode
Geometry
Matrixd
Vec3
Vec4
osgSim::SphereSegment::getSideColor
const osg::Vec4 & getSideColor() const
Definition SphereSegment:207
osgSim::SphereSegment::getArea
void getArea(float &azMin, float &azMax, float &elevMin, float &elevMax) const
osgSim::SphereSegment::getArea
void getArea(osg::Vec3 &vec, float &azRange, float &elevRange) const
osgSim::SphereSegment::META_Node
META_Node(osgSim, SphereSegment)
osgSim::SphereSegment::setCentre
void setCentre(const osg::Vec3 &c)
osgSim::SphereSegment::DrawMask
DrawMask
Definition SphereSegment:71
osgSim::SphereSegment::ALL
@ ALL
Draw every part of the sphere segment.
Definition SphereSegment:76
osgSim::SphereSegment::EDGELINE
@ EDGELINE
Draw the line round the edge of the area on the sphere's surface.
Definition SphereSegment:74
osgSim::SphereSegment::SIDES
@ SIDES
Draw the planes from the sphere's centre to the edge of the sphere's surface.
Definition SphereSegment:75
osgSim::SphereSegment::SPOKES
@ SPOKES
Draw the spokes from the sphere's centre to the surface's corners.
Definition SphereSegment:73
osgSim::SphereSegment::SURFACE
@ SURFACE
Draw the specified area on the sphere's surface.
Definition SphereSegment:72
osgSim::SphereSegment::updatePositions
void updatePositions()
osgSim::SphereSegment::setArea
void setArea(const osg::Vec3 &vec, float azRange, float elevRange)
osgSim::SphereSegment::setDensity
void setDensity(int d)
osgSim::SphereSegment::releaseGLObjects
virtual void releaseGLObjects(osg::State *state=0) const
osgSim::SphereSegment::setSurfaceColor
void setSurfaceColor(const osg::Vec4 &c)
osgSim::SphereSegment::setDrawMask
void setDrawMask(int dm)
osgSim::SphereSegment::setArea
void setArea(float azMin, float azMax, float elevMin, float elevMax)
osgSim::SphereSegment::getDensity
int getDensity() const
osgSim::SphereSegment::setSpokeColor
void setSpokeColor(const osg::Vec4 &c)
osgSim::SphereSegment::setAllColors
void setAllColors(const osg::Vec4 &c)
osgSim::SphereSegment::computeIntersectionSubgraph
osg::Node * computeIntersectionSubgraph(const osg::Matrixd &matrix, osg::Node *subgraph)
osgSim::SphereSegment::SphereSegment
SphereSegment()
Definition SphereSegment:81
osgSim::SphereSegment::setSideColor
void setSideColor(const osg::Vec4 &c)
osgSim::SphereSegment::computeIntersection
LineList computeIntersection(const osg::Matrixd &matrix, osg::Node *subgraph)
osgSim::SphereSegment::getSurfaceColor
const osg::Vec4 & getSurfaceColor() const
Definition SphereSegment:189
osgSim::SphereSegment::getRadius
float getRadius() const
osgSim::SphereSegment::SphereSegment
SphereSegment(const SphereSegment &rhs, const osg::CopyOp &co)
osgSim::SphereSegment::resizeGLObjectBuffers
virtual void resizeGLObjectBuffers(unsigned int maxSize)
osgSim::SphereSegment::getDrawMask
int getDrawMask() const
Definition SphereSegment:183
osgSim::SphereSegment::LineList
std::vector< osg::ref_ptr< osg::Vec3Array > > LineList
Definition SphereSegment:215
osgSim::SphereSegment::updatePrimitives
void updatePrimitives()
osgSim::SphereSegment::getEdgeLineColor
const osg::Vec4 & getEdgeLineColor() const
Definition SphereSegment:201
osgSim::SphereSegment::setEdgeLineColor
void setEdgeLineColor(const osg::Vec4 &c)
osgSim::SphereSegment::computeIntersectionSubgraph
osg::Node * computeIntersectionSubgraph(const osg::Matrixd &matrix, osg::Drawable *drawable)
osgSim::SphereSegment::SphereSegment
SphereSegment(const osg::Vec3 &centre, float radius, const osg::Vec3 &vec, float azRange, float elevRange, int density)
osgSim::SphereSegment::getCentre
const osg::Vec3 & getCentre() const
osgSim::SphereSegment::computeIntersection
LineList computeIntersection(const osg::Matrixd &matrix, osg::Drawable *drawable)
osgSim::SphereSegment::setRadius
void setRadius(float r)
osgSim::SphereSegment::traverse
void traverse(osg::NodeVisitor &nv)
osgSim::SphereSegment::SphereSegment
SphereSegment(const osg::Vec3 &centre, float radius, float azMin, float azMax, float elevMin, float elevMax, int density)
osgSim::SphereSegment::computeBound
virtual osg::BoundingSphere computeBound() const
osgSim::SphereSegment::getSpokeColor
const osg::Vec4 & getSpokeColor() const
Definition SphereSegment:195
osg::CopyOp
Definition CopyOp:41
osg::Drawable
Definition Drawable:89
osg::Geode
Definition Geode:29
osg::Geode::Geode
Geode()
osg::Matrixd
Definition Matrixd:27
osg::NodeVisitor
Definition NodeVisitor:82
osg::Node
Definition Node:72
osg::StateSet
Definition StateSet:46
osg::State
Definition State:80
osg::Vec4f::a
value_type & a()
Definition Vec4f:100
osg::ref_ptr
Definition ref_ptr:32
osg::ref_ptr::get
T * get() const
Definition ref_ptr:117
osgSim
Definition BlinkSequence:27
osg
Definition AlphaFunc:19
osg::Vec3
Vec3f Vec3
Definition Vec3:21
osg::BoundingSphere
BoundingSphered BoundingSphere
Definition BoundingSphere:314
osg::Vec4
Vec4f Vec4
Definition Vec4:21
Export
OSGSIM_EXPORT
#define OSGSIM_EXPORT
Definition osgSim/Export:38