29 #include <osg/MatrixTransform>
31 #include "../common/math/linearAlgebra/WPosition.h"
32 #include "core/common/WLogger.h"
34 #include "WGETexture.h"
35 #include "shaders/WGEShader.h"
36 #include "WGEGeodeUtils.h"
40 osg::ref_ptr< osg::Vec3Array >
wge::osgVec3Array(
const std::vector< WPosition >& posArray )
42 osg::ref_ptr< osg::Vec3Array > result = osg::ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
43 result->reserve( posArray.size() );
44 std::vector< WPosition >::const_iterator cit;
45 for( cit = posArray.begin(); cit != posArray.end(); ++cit )
47 result->push_back( *cit );
54 return screen * osg::Matrix::inverse( camera->getViewMatrix() * camera->getProjectionMatrix() * camera->getViewport()->computeWindowMatrix() );
59 return screen * osg::Matrix::inverse( camera->getViewMatrix() * camera->getProjectionMatrix() * camera->getViewport()->computeWindowMatrix() );
71 return WColor( 0.0, 0.0, 0.0, 1.0 );
74 if( ( index & 1 ) == 1 )
78 if( ( index & 2 ) == 2 )
82 if( ( index & 4 ) == 4 )
86 if( ( index & 8 ) == 8 )
89 if( r < 1.0 && g < 1.0 && b < 1.0 )
95 if( ( index & 16 ) == 16 )
98 if( r < 1.0 && g < 1.0 && b < 1.0 )
104 if( ( index & 32 ) == 32 )
107 if( r < 1.0 && g < 1.0 && b < 1.0 )
113 if( ( index & 64 ) == 64 )
116 if( r < 1.0 && g < 1.0 && b < 1.0 )
121 if( ( index & 128 ) == 128 )
124 if( r < 1.0 && g < 1.0 && b < 1.0 )
133 return WColor( r, g, b, 1.0 );
141 float f = (
static_cast<float>( h ) / 60.0 ) - hi;
143 float p = v * ( 1.0 - s );
144 float q = v * ( 1.0 - s * f );
145 float t = v * ( 1.0 - s * ( 1.0 - f ) );
150 return WColor( v, t, p, 1.0 );
152 return WColor( q, v, p, 1.0 );
154 return WColor( p, v, t, 1.0 );
156 return WColor( p, q, v, 1.0 );
158 return WColor( t, p, v, 1.0 );
160 return WColor( v, p, q, 1.0 );
162 return WColor( v, t, p, 1.0 );
164 return WColor( v, t, p, 1.0 );
191 if( ( n & 16 ) == 16 )
195 if( ( n & 32 ) == 32 )
199 if( ( n & 64 ) == 64 )
203 if( ( n & 128 ) == 128 )
207 if( ( n & 256 ) == 256 )
217 osg::StateSet* state = node->getOrCreateStateSet();
220 state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
223 state->setMode( GL_DEPTH_TEST, osg::StateAttribute::ON );
233 state->setMode( GL_BLEND, osg::StateAttribute::ON );
242 cullProxy->asTransform()->getChild( 0 )->setName(
"_Cull Proxy Cube" );
246 osg::ref_ptr< WGEShader > cullProxyShader =
new WGEShader(
"WGECullProxyShader" );
247 cullProxyShader->apply( cullProxy );
274 virtual void operator()( osg::Node* node, osg::NodeVisitor* nv )
276 osg::MatrixTransform* m =
static_cast< osg::MatrixTransform*
>( node );
278 osg::BoundingSphere s =
m_node->getBound();
282 osg::Matrix matrix = osg::Matrix::scale( osg::Vec3d( s.radius(), s.radius(), s.radius() ) ) * osg::Matrix::translate( s.center() );
284 m->setMatrix( matrix );
286 traverse( node, nv );
303 osg::ref_ptr< osg::MatrixTransform > mt(
new osg::MatrixTransform() );
306 mt->addChild( proxyUnitCube );
Update matrix transform according to bounds of some node.
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
Callback method called by the NodeVisitor when visiting a node.
BoundsCallback(osg::ref_ptr< osg::Node > node)
Create and init.
osg::ref_ptr< osg::Node > m_node
The node to use as template for the resulting bbox.
osg::BoundingBoxImpl< osg::Vec3 >::vec_type vec_type
Vertex type for min and max positions of this box.
Class encapsulating the OSG Program class for a more convenient way of adding and modifying shader.
WColor getNthHSVColor(int n)
creates the nth color of a partition of the hsv color circle
void enableTransparency(osg::ref_ptr< osg::Node > node)
Enable transparency for the given node.
WColor createColorFromHSV(int h, float s=1.0, float v=1.0)
creates a rgb WColor from a HSV value
osg::ref_ptr< osg::Node > generateCullProxy(const WBoundingBox &bbox)
Generate a proxy cube, which ensures OSG does proper near-far plane calculation and culling.
osg::Vec3 unprojectFromScreen(const osg::Vec3 screen, osg::ref_ptr< WGECamera > camera)
Converts screen coordinates into Camera coordinates.
osg::ref_ptr< osg::Node > generateSolidBoundingBoxNode(const WBoundingBox &bb, const WColor &color, bool threeDTexCoords=true)
Generates an OSG node for the specified bounding box.
WColor createColorFromIndex(int index)
creates the same color as the atlas colormap shader from the index
osg::ref_ptr< osg::Node > generateDynamicCullProxy(osg::ref_ptr< osg::Node > node)
Generate a proxy cube, which ensures OSG does proper near-far plane calculation and culling.
osg::ref_ptr< osg::Vec3Array > osgVec3Array(const std::vector< WPosition > &posArray)
Converts a whole vector of WPositions into an osg::Vec3Array.