31 #include <osg/Geometry>
32 #include <osg/LightModel>
33 #include <osg/LineWidth>
34 #include <osg/Material>
35 #include <osg/MatrixTransform>
36 #include <osg/ShapeDrawable>
39 #include "../common/math/linearAlgebra/WLinearAlgebra.h"
40 #include "../common/math/WMath.h"
41 #include "../common/WPathHelper.h"
42 #include "../common/WStringUtils.h"
44 #include "shaders/WGEShader.h"
45 #include "WGEGeodeUtils.h"
46 #include "WGEGeometryUtils.h"
47 #include "WGEGroupNode.h"
48 #include "WGESubdividedPlane.h"
50 #include "widgets/labeling/WGELabel.h"
57 WAssert( pos1[0] <= pos2[0] && pos1[1] <= pos2[1] && pos1[2] <= pos2[2],
"pos1 does not seem to be the frontLowerLeft corner of the BB!" );
59 ref_ptr< osg::Vec3Array > vertices = ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
60 ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
61 ref_ptr< osg::Geometry > geometry = ref_ptr< osg::Geometry >(
new osg::Geometry );
63 vertices->push_back( osg::Vec3( pos1[0], pos1[1], pos1[2] ) );
64 vertices->push_back( osg::Vec3( pos2[0], pos1[1], pos1[2] ) );
65 vertices->push_back( osg::Vec3( pos2[0], pos2[1], pos1[2] ) );
66 vertices->push_back( osg::Vec3( pos1[0], pos2[1], pos1[2] ) );
67 vertices->push_back( osg::Vec3( pos1[0], pos1[1], pos1[2] ) );
68 vertices->push_back( osg::Vec3( pos1[0], pos1[1], pos2[2] ) );
69 vertices->push_back( osg::Vec3( pos2[0], pos1[1], pos2[2] ) );
70 vertices->push_back( osg::Vec3( pos2[0], pos2[1], pos2[2] ) );
71 vertices->push_back( osg::Vec3( pos1[0], pos2[1], pos2[2] ) );
72 vertices->push_back( osg::Vec3( pos1[0], pos1[1], pos2[2] ) );
74 geometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, vertices->size() ) );
76 vertices->push_back( osg::Vec3( pos1[0], pos2[1], pos1[2] ) );
77 vertices->push_back( osg::Vec3( pos1[0], pos2[1], pos2[2] ) );
78 vertices->push_back( osg::Vec3( pos2[0], pos2[1], pos1[2] ) );
79 vertices->push_back( osg::Vec3( pos2[0], pos2[1], pos2[2] ) );
80 vertices->push_back( osg::Vec3( pos2[0], pos1[1], pos1[2] ) );
81 vertices->push_back( osg::Vec3( pos2[0], pos1[1], pos2[2] ) );
83 geometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINES, vertices->size() - 6, 6 ) );
85 geometry->setVertexArray( vertices );
86 colors->push_back( color );
87 geometry->setColorArray( colors );
88 geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
89 osg::ref_ptr< osg::Geode > geode = osg::ref_ptr< osg::Geode >(
new osg::Geode );
90 geode->addDrawable( geometry );
93 osg::StateSet* state = geode->getOrCreateStateSet();
94 state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
102 osg::ref_ptr< osg::Geometry > cube =
new osg::Geometry();
103 osg::ref_ptr< osg::Vec3Array > vertices = osg::ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
104 osg::ref_ptr< osg::Vec3Array > normals = osg::ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
105 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
108 vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
109 vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
110 vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
111 vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
112 normals->push_back( osg::Vec3( 0.0, 0.0, -1.0 ) );
115 vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
116 vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
117 vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
118 vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
119 normals->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
122 vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
123 vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
124 vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
125 vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
126 normals->push_back( osg::Vec3( -1.0, 0.0, 0.0 ) );
129 vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
130 vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
131 vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
132 vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
133 normals->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
136 vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
137 vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
138 vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
139 vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
140 normals->push_back( osg::Vec3( 0.0, -1.0, 0.0 ) );
143 vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
144 vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
145 vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
146 vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
147 normals->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
150 cube->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0, vertices->size() ) );
151 cube->setVertexArray( vertices );
154 cube->setTexCoordArray( 0, vertices );
157 cube->setNormalArray( normals );
158 cube->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE );
161 colors->push_back( color );
162 cube->setColorArray( colors );
163 cube->setColorBinding( osg::Geometry::BIND_OVERALL );
171 osg::ref_ptr< osg::Geometry > cube =
new osg::Geometry();
172 osg::ref_ptr< osg::Vec3Array > vertices = osg::ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
173 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
175 vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
176 vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
177 vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
178 vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
179 vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
180 vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
181 vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
182 vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
183 vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
184 vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
186 cube->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, vertices->size() ) );
188 vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
189 vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
190 vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
191 vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
192 vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
193 vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
195 cube->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINES, vertices->size() - 6, 6 ) );
198 cube->setVertexArray( vertices );
201 cube->setTexCoordArray( 0, vertices );
204 colors->push_back( color );
205 cube->setColorArray( colors );
206 cube->setColorBinding( osg::Geometry::BIND_OVERALL );
213 WAssert( bb.valid(),
"Invalid bounding box!" );
216 osg::ref_ptr< osg::Geode > cube =
new osg::Geode();
217 cube->setName(
"Solid Bounding Box" );
218 if( threeDTexCoords )
224 osg::ref_ptr< osg::ShapeDrawable > cubeDrawable =
new osg::ShapeDrawable(
new osg::Box( osg::Vec3( 0.5, 0.5, 0.5 ), 1.0 ) );
225 cubeDrawable->setColor( color );
226 cube->addDrawable( cubeDrawable );
230 osg::Matrixd transformM;
232 transformM.makeTranslate( bb.
getMin() );
236 osg::ref_ptr< osg::MatrixTransform > transform =
new osg::MatrixTransform();
237 transform->setMatrix( scaleM * transformM );
238 transform->addChild( cube );
241 osg::StateSet* state = cube->getOrCreateStateSet();
242 state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
248 const WColor& defaultColor,
253 osg::ref_ptr< osg::Geometry> geometry(
new osg::Geometry );
254 geometry->setVertexArray( mesh->getVertexArray() );
256 osg::DrawElementsUInt* surfaceElement;
258 surfaceElement =
new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );
260 std::vector< size_t > tris = mesh->getTriangles();
261 surfaceElement->reserve( tris.size() );
263 for(
unsigned int vertId = 0; vertId < tris.size(); ++vertId )
265 surfaceElement->push_back( tris[vertId] );
267 geometry->addPrimitiveSet( surfaceElement );
270 if( mesh->getVertexColorArray() && useMeshColor )
272 geometry->setColorArray( mesh->getVertexColorArray() );
273 geometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
277 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
278 colors->push_back( defaultColor );
279 geometry->setColorArray( colors );
280 geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
287 geometry->setNormalArray( mesh->getVertexNormalArray() );
288 geometry->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
293 osg::StateSet* state = geometry->getOrCreateStateSet();
294 osg::ref_ptr<osg::LightModel> lightModel =
new osg::LightModel();
295 lightModel->setTwoSided(
true );
296 state->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
297 state->setMode( GL_BLEND, osg::StateAttribute::ON );
299 osg::ref_ptr< osg::Material > material =
new osg::Material();
300 material->setDiffuse( osg::Material::FRONT, osg::Vec4( 1.0, 1.0, 1.0, 1.0 ) );
301 material->setSpecular( osg::Material::FRONT, osg::Vec4( 0.0, 0.0, 0.0, 1.0 ) );
302 material->setAmbient( osg::Material::FRONT, osg::Vec4( 0.1, 0.1, 0.1, 1.0 ) );
303 material->setEmission( osg::Material::FRONT, osg::Vec4( 0.0, 0.0, 0.0, 1.0 ) );
304 material->setShininess( osg::Material::FRONT, 25.0 );
305 state->setAttribute( material );
311 geometry->setUseDisplayList(
false );
312 geometry->setUseVertexBufferObjects(
true );
318 bool includeNormals,
bool lighting )
320 osg::Geometry* geometry =
convertToOsgGeometry( mesh, defaultColor, includeNormals, lighting,
false );
324 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
325 for(
size_t i = 0; i < mesh->vertSize(); ++i )
327 colors->push_back( defaultColor );
329 for( std::map< size_t, WColor >::const_iterator vc = colorMap.
getData().begin(); vc != colorMap.
getData().end(); ++vc )
332 if( vc->first < colors->size() )
334 colors->at( vc->first ) = vc->second;
338 geometry->setColorArray( colors );
339 geometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
345 const WColor& defaultColor,
348 osg::ref_ptr< osg::Geometry > geometry(
new osg::Geometry );
349 geometry->setVertexArray( mesh->getVertexArray() );
351 osg::DrawElementsUInt* meshElement;
353 meshElement =
new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 );
355 std::vector< size_t > tris = mesh->getTriangles();
356 meshElement->reserve( tris.size() * 3 );
358 for(
unsigned int triId = 0; triId < tris.size() / 3.; ++triId )
360 for(
size_t edgeId = 0; edgeId < 3; ++edgeId )
362 meshElement->push_back( tris[triId*3 + edgeId] );
363 meshElement->push_back( tris[triId*3 + ( edgeId + 1 ) % 3] );
366 geometry->addPrimitiveSet( meshElement );
369 if( mesh->getVertexColorArray() && useMeshColor )
371 geometry->setColorArray( mesh->getVertexColorArray() );
372 geometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
376 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
377 colors->push_back( defaultColor );
378 geometry->setColorArray( colors );
379 geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
382 osg::StateSet* stateset = geometry->getOrCreateStateSet();
383 stateset->setAttributeAndModes(
new osg::LineWidth( 1 ), osg::StateAttribute::ON );
384 stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
392 ref_ptr< osg::Vec3Array > vertices = ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
393 ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
394 ref_ptr< osg::Geometry > geometry = ref_ptr< osg::Geometry >(
new osg::Geometry );
396 for(
size_t i = 1; i < line.
size(); ++i )
398 vertices->push_back( osg::Vec3( line[i-1][0], line[i-1][1], line[i-1][2] ) );
401 vertices->push_back( osg::Vec3( line.
back()[0], line.
back()[1], line.
back()[2] ) );
402 colors->push_back( colors->back() );
404 geometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, line.
size() ) );
405 geometry->setVertexArray( vertices );
407 if( color != WColor( 0, 0, 0, 0 ) )
410 colors->push_back( color );
411 geometry->setColorArray( colors );
412 geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
416 geometry->setColorArray( colors );
417 geometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
421 osg::StateSet* stateset = geometry->getOrCreateStateSet();
422 stateset->setAttributeAndModes(
new osg::LineWidth( thickness ), osg::StateAttribute::ON );
423 stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
425 osg::ref_ptr< osg::Geode > geode = osg::ref_ptr< osg::Geode >(
new osg::Geode );
426 geode->addDrawable( geometry );
430 osg::ref_ptr< osg::PositionAttitudeTransform >
wge::addLabel( osg::Vec3 position, std::string text )
432 osg::ref_ptr< osgText::Text > label = osg::ref_ptr< osgText::Text >(
new osgText::Text() );
433 osg::ref_ptr< osg::Geode > labelGeode = osg::ref_ptr< osg::Geode >(
new osg::Geode() );
435 labelGeode->addDrawable( label );
439 label->setBackdropType( osgText::Text::OUTLINE );
440 label->setCharacterSize( 6 );
442 label->setText( text );
443 label->setAxisAlignment( osgText::Text::SCREEN );
444 label->setDrawMode( osgText::Text::TEXT );
445 label->setAlignment( osgText::Text::CENTER_TOP );
446 label->setPosition( osg::Vec3( 0.0, 0.0, 0.0 ) );
447 label->setColor( osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ) );
449 osg::ref_ptr< osg::PositionAttitudeTransform > labelXform =
450 osg::ref_ptr< osg::PositionAttitudeTransform >(
new osg::PositionAttitudeTransform() );
451 labelXform->setPosition( position );
453 labelXform->addChild( labelGeode );
462 return (
addLabel( position, label ) );
468 ref_ptr< osg::Vec3Array > vertices = ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
469 ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
470 ref_ptr< osg::Geometry > geometry = ref_ptr< osg::Geometry >(
new osg::Geometry );
472 colors->push_back( color );
479 geometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0, 4 ) );
480 geometry->setVertexArray( vertices );
481 geometry->setColorArray( colors );
482 geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
484 osg::StateSet* stateset =
new osg::StateSet;
485 stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
486 geometry->setStateSet( stateset );
488 osg::ref_ptr< osg::Geode > geode = osg::ref_ptr< osg::Geode >(
new osg::Geode );
489 geode->addDrawable( geometry );
493 vertices->push_back( vertices->front() );
494 ref_ptr< osg::Geometry > borderGeom = ref_ptr< osg::Geometry >(
new osg::Geometry );
495 borderGeom->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, 4 ) );
496 borderGeom->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 3, 2 ) );
497 ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
498 colors->push_back( inverseColor( color ) );
499 borderGeom->setColorArray( colors );
500 borderGeom->setColorBinding( osg::Geometry::BIND_OVERALL );
501 borderGeom->setVertexArray( vertices );
502 geode->addDrawable( borderGeom );
507 osg::ref_ptr< osg::Geode >
wge::genFinitePlane( osg::Vec3
const& base, osg::Vec3
const& a, osg::Vec3
const& b )
510 osg::ref_ptr< osg::Vec3Array > vertices =
new osg::Vec3Array;
511 osg::ref_ptr< osg::Vec3Array > texcoords0 =
new osg::Vec3Array;
512 osg::ref_ptr< osg::Vec3Array > normals =
new osg::Vec3Array;
513 osg::ref_ptr< osg::Vec4Array > colors =
new osg::Vec4Array;
515 osg::Vec3 aPlusB = a + b;
517 vertices->push_back( base );
518 vertices->push_back( base + a );
519 vertices->push_back( base + aPlusB );
520 vertices->push_back( base + b );
522 osg::Vec3 aCrossB = a ^ b;
529 normals->push_back( aCrossB );
530 colors->push_back( osg::Vec4( 1.0, 1.0, 1.0, 1.0 ) );
531 texcoords0->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
532 texcoords0->push_back( aNorm );
533 texcoords0->push_back( aNorm + bNorm );
534 texcoords0->push_back( bNorm );
537 osg::ref_ptr< osg::Geometry > geometry =
new osg::Geometry();
538 geometry->setVertexArray( vertices );
539 geometry->setTexCoordArray( 0, texcoords0 );
540 geometry->setNormalBinding( osg::Geometry::BIND_OVERALL );
541 geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
542 geometry->setNormalArray( normals );
543 geometry->setColorArray( colors );
544 geometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0, 4 ) );
546 osg::ref_ptr< osg::Geode > geode =
new osg::Geode();
547 geode->addDrawable( geometry );
553 WAssert( resX > 0 && resY > 0,
"A Plane with no quad is not supported, use another datatype for that!" );
554 double dx = ( resX > 1 ? 1.0 / ( resX - 1 ) : 1.0 );
555 double dy = ( resY > 1 ? 1.0 / ( resY - 1 ) : 1.0 );
557 size_t numQuads = resX * resY;
560 ref_ptr< osg::Vec3Array > vertices = ref_ptr< osg::Vec3Array >(
new osg::Vec3Array( numQuads * 4 ) );
561 ref_ptr< osg::Vec3Array > centers = ref_ptr< osg::Vec3Array >(
new osg::Vec3Array( numQuads ) );
562 ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >(
new osg::Vec4Array( numQuads ) );
564 for(
size_t yQuad = 0; yQuad < resY; ++yQuad )
566 for(
size_t xQuad = 0; xQuad < resX; ++xQuad )
568 size_t qIndex = yQuad * resX + xQuad;
569 size_t vIndex = qIndex * 4;
570 vertices->at( vIndex ) = osg::Vec3( xQuad * dx + spacing, yQuad * dy + spacing, 0.0 );
571 vertices->at( vIndex + 1 ) = osg::Vec3( xQuad * dx + dx - spacing, yQuad * dy + spacing, 0.0 );
572 vertices->at( vIndex + 2 ) = osg::Vec3( xQuad * dx + dx - spacing, yQuad * dy + dy - spacing, 0.0 );
573 vertices->at( vIndex + 3 ) = osg::Vec3( xQuad * dx + spacing, yQuad * dy + dy - spacing, 0.0 );
574 centers->at( qIndex ) = osg::Vec3( xQuad * dx + dx / 2.0, yQuad * dy + dy / 2.0, 0.0 );
575 colors->at( qIndex ) = osg::Vec4( 0.1 + static_cast< double >( qIndex ) / numQuads * 0.6,
576 0.1 + static_cast< double >( qIndex ) / numQuads * 0.6,
581 ref_ptr< osg::Geometry > geometry = ref_ptr< osg::Geometry >(
new osg::Geometry );
582 geometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0, vertices->size() ) );
583 geometry->setVertexArray( vertices );
584 geometry->setColorArray( colors );
585 geometry->setColorBinding( osg::Geometry::BIND_PER_PRIMITIVE );
587 ref_ptr< osg::Vec3Array > normals = ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
588 normals->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
589 geometry->setNormalArray( normals );
590 geometry->setNormalBinding( osg::Geometry::BIND_OVERALL );
591 osg::ref_ptr< WGESubdividedPlane > geode = osg::ref_ptr< WGESubdividedPlane >(
new WGESubdividedPlane );
592 geode->addDrawable( geometry );
593 geode->setCenterArray( centers );
596 osg::StateSet* state = geode->getOrCreateStateSet();
597 state->setMode( GL_BLEND, osg::StateAttribute::ON );
598 state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
610 osg::ref_ptr< WGEGroupNode >groupNode =
new WGEGroupNode();
611 osg::ref_ptr< WGEShader > shaderCoordinateSystem(
new WGEShader(
"WGECoordinateSystem" ) );
613 osg::ref_ptr< osg::Geode > graphX(
new osg::Geode );
614 osg::ref_ptr< osg::Geode > graphY(
new osg::Geode );
615 osg::ref_ptr< osg::Geode > graphZ(
new osg::Geode );
617 osg::ref_ptr< osg::Geode > graphXCylinder(
new osg::Geode );
618 osg::ref_ptr< osg::Geode > graphYCylinder(
new osg::Geode );
619 osg::ref_ptr< osg::Geode > graphZCylinder(
new osg::Geode );
622 osg::ref_ptr< osg::ShapeDrawable > cylinderX =
new osg::ShapeDrawable(
new osg::Cylinder(
623 middle, 1, sizeX + ( sizeX * 0.5 )
625 osg::ref_ptr< osg::ShapeDrawable > cylinderXEnd =
new osg::ShapeDrawable(
new osg::Cylinder(
626 osg::Vec3( middle.x(), middle.y(), middle.z() - ( sizeX + ( sizeX * 0.5 ) ) / 2.0 ), 1.0, 1.0
628 osg::ref_ptr< osg::ShapeDrawable > coneX =
new osg::ShapeDrawable(
new osg::Cone(
629 osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeX + ( sizeX * 0.5 ) ) / 2.0 ), 2.0, 5.0
631 cylinderXEnd->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
632 graphXCylinder->addDrawable( cylinderX );
633 graphX->addDrawable( coneX );
634 graphX->addDrawable( cylinderXEnd );
636 osg::ref_ptr< osg::Material > matX =
new osg::Material();
637 matX->setDiffuse( osg::Material::FRONT, WColor( 1.0, 0.0, 0.0, 1.0 ) );
638 cylinderX->getOrCreateStateSet()->setAttribute( matX, osg::StateAttribute::ON );
639 coneX->getOrCreateStateSet()->setAttribute( matX, osg::StateAttribute::ON );
642 osg::ref_ptr< osg::ShapeDrawable > cylinderY =
new osg::ShapeDrawable(
new osg::Cylinder(
643 middle, 1, sizeY + ( sizeY * 0.5 )
645 osg::ref_ptr< osg::ShapeDrawable > cylinderYEnd =
new osg::ShapeDrawable(
new osg::Cylinder(
646 osg::Vec3( middle.x(), middle.y(), middle.z() - ( sizeY + ( sizeY * 0.5 ) ) / 2.0 ), 1.0, 1.0
648 osg::ref_ptr< osg::ShapeDrawable > coneY =
new osg::ShapeDrawable(
new osg::Cone(
649 osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeY + ( sizeY * 0.5 ) ) / 2.0 ), 2.0, 5.0
651 cylinderYEnd->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
653 graphYCylinder->addDrawable( cylinderY );
654 graphY->addDrawable( coneY );
655 graphY->addDrawable( cylinderYEnd );
657 osg::ref_ptr< osg::Material > matY =
new osg::Material();
658 matY->setDiffuse( osg::Material::FRONT, WColor( 0.0, 1.0, 0.0, 1.0 ) );
659 cylinderY->getOrCreateStateSet()->setAttribute( matY, osg::StateAttribute::ON );
660 coneY->getOrCreateStateSet()->setAttribute( matY, osg::StateAttribute::ON );
664 osg::ref_ptr< osg::ShapeDrawable > cylinderZ =
new osg::ShapeDrawable(
new osg::Cylinder(
665 middle, 1, sizeZ + ( sizeZ * 0.5 )
667 osg::ref_ptr< osg::ShapeDrawable > cylinderZEnd =
new osg::ShapeDrawable(
new osg::Cylinder(
668 osg::Vec3( middle.x(), middle.y(), middle.z() - ( sizeZ + ( sizeZ * 0.5 ) ) / 2.0 ), 1.0, 1.0
670 osg::ref_ptr< osg::ShapeDrawable > coneZ =
new osg::ShapeDrawable(
new osg::Cone(
671 osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeZ + ( sizeZ * 0.5 ) ) / 2.0 ), 2.0, 5.0
673 cylinderZEnd->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
675 graphZCylinder->addDrawable( cylinderZ );
676 graphZ->addDrawable( coneZ );
677 graphZ->addDrawable( cylinderZEnd );
679 osg::ref_ptr< osg::Material > matZ =
new osg::Material();
680 matZ->setDiffuse( osg::Material::FRONT, WColor( 0.0, 0.0, 1.0, 1.0 ) );
681 cylinderZ->getOrCreateStateSet()->setAttribute( matZ, osg::StateAttribute::ON );
682 coneZ->getOrCreateStateSet()->setAttribute( matZ, osg::StateAttribute::ON );
684 shaderCoordinateSystem->apply( graphXCylinder );
685 shaderCoordinateSystem->apply( graphYCylinder );
686 shaderCoordinateSystem->apply( graphZCylinder );
688 osg::ref_ptr< WGELabel > graphXLabel =
new WGELabel();
689 graphXLabel->setText(
"X" );
690 graphXLabel->setCharacterSize( 10 );
691 graphXLabel->setPosition( osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeX + ( sizeX * 0.5 ) ) / 2.0 + 5.0 ) );
692 graphXLabel->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
693 graphX->addDrawable( graphXLabel );
695 osg::ref_ptr< WGELabel > graphYLabel =
new WGELabel();
696 graphYLabel->setText(
"Y" );
697 graphYLabel->setCharacterSize( 10 );
698 graphYLabel->setPosition( osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeY + ( sizeY * 0.5 ) ) / 2.0 + 5.0 ) );
699 graphYLabel->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
700 graphY->addDrawable( graphYLabel );
702 osg::ref_ptr< WGELabel > graphZLabel =
new WGELabel();
703 graphZLabel->setText(
"Z" );
704 graphZLabel->setCharacterSize( 10 );
705 graphZLabel->setPosition( osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeZ + ( sizeZ * 0.5 ) ) / 2.0 + 5.0 ) );
706 graphZLabel->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
707 graphZ->addDrawable( graphZLabel );
710 osg::ref_ptr< osg::MatrixTransform > graphXTransform =
new osg::MatrixTransform();
711 graphXTransform->addChild( graphX );
712 graphXTransform->addChild( graphXCylinder );
713 osg::ref_ptr< osg::MatrixTransform > graphYTransform =
new osg::MatrixTransform();
714 graphYTransform->addChild( graphY );
715 graphYTransform->addChild( graphYCylinder );
716 osg::ref_ptr< osg::MatrixTransform > graphZTransform =
new osg::MatrixTransform();
717 graphZTransform->addChild( graphZ );
718 graphZTransform->addChild( graphZCylinder );
720 osg::Matrixd matrixTranslateTo0 = osg::Matrixd::translate( -middle.x(), -middle.y(), -middle.z() );
721 osg::Matrixd matrixTranslateFrom0 = osg::Matrixd::translate( middle.x(), middle.y(), middle.z() );
723 graphXTransform->setMatrix( matrixTranslateTo0 * osg::Matrixd::rotate(
724 90.0 * piDouble / 180.0,
725 osg::Vec3f( 0.0, 1.0, 0.0 ) ) * matrixTranslateFrom0
727 graphYTransform->setMatrix( matrixTranslateTo0 * osg::Matrixd::rotate(
728 -90.0 * piDouble / 180.0,
729 osg::Vec3f( 1.0, 0.0, 0.0 ) ) * matrixTranslateFrom0
732 groupNode->insert( graphXTransform );
733 groupNode->insert( graphYTransform );
734 groupNode->insert( graphZTransform );