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 );