29 #include <osg/Geometry>
30 #include <osg/LineWidth>
31 #include <osg/MatrixTransform>
32 #include <osg/ShapeDrawable>
34 #include <osg/LightModel>
35 #include <osg/Material>
37 #include "../common/math/linearAlgebra/WLinearAlgebra.h"
38 #include "../common/WPathHelper.h"
39 #include "../common/math/WMath.h"
40 #include "WGESubdividedPlane.h"
41 #include "WGEGeodeUtils.h"
42 #include "WGEGeometryUtils.h"
44 #include "WGEGroupNode.h"
45 #include "shaders/WGEShader.h"
46 #include "widgets/labeling/WGELabel.h"
53 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!" );
55 ref_ptr< osg::Vec3Array > vertices = ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
56 ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
57 ref_ptr< osg::Geometry > geometry = ref_ptr< osg::Geometry >(
new osg::Geometry );
59 vertices->push_back( osg::Vec3( pos1[0], pos1[1], pos1[2] ) );
60 vertices->push_back( osg::Vec3( pos2[0], pos1[1], pos1[2] ) );
61 vertices->push_back( osg::Vec3( pos2[0], pos2[1], pos1[2] ) );
62 vertices->push_back( osg::Vec3( pos1[0], pos2[1], pos1[2] ) );
63 vertices->push_back( osg::Vec3( pos1[0], pos1[1], pos1[2] ) );
64 vertices->push_back( osg::Vec3( pos1[0], pos1[1], pos2[2] ) );
65 vertices->push_back( osg::Vec3( pos2[0], pos1[1], pos2[2] ) );
66 vertices->push_back( osg::Vec3( pos2[0], pos2[1], pos2[2] ) );
67 vertices->push_back( osg::Vec3( pos1[0], pos2[1], pos2[2] ) );
68 vertices->push_back( osg::Vec3( pos1[0], pos1[1], pos2[2] ) );
70 geometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, vertices->size() ) );
72 vertices->push_back( osg::Vec3( pos1[0], pos2[1], pos1[2] ) );
73 vertices->push_back( osg::Vec3( pos1[0], pos2[1], pos2[2] ) );
74 vertices->push_back( osg::Vec3( pos2[0], pos2[1], pos1[2] ) );
75 vertices->push_back( osg::Vec3( pos2[0], pos2[1], pos2[2] ) );
76 vertices->push_back( osg::Vec3( pos2[0], pos1[1], pos1[2] ) );
77 vertices->push_back( osg::Vec3( pos2[0], pos1[1], pos2[2] ) );
79 geometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINES, vertices->size() - 6, 6 ) );
81 geometry->setVertexArray( vertices );
82 colors->push_back( color );
83 geometry->setColorArray( colors );
84 geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
85 osg::ref_ptr< osg::Geode > geode = osg::ref_ptr< osg::Geode >(
new osg::Geode );
86 geode->addDrawable( geometry );
89 osg::StateSet* state = geode->getOrCreateStateSet();
90 state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
98 osg::ref_ptr< osg::Geometry > cube =
new osg::Geometry();
99 osg::ref_ptr< osg::Vec3Array > vertices = osg::ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
100 osg::ref_ptr< osg::Vec3Array > normals = osg::ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
101 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
104 vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
105 vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
106 vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
107 vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
108 normals->push_back( osg::Vec3( 0.0, 0.0, -1.0 ) );
111 vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
112 vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
113 vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
114 vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
115 normals->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
118 vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
119 vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
120 vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
121 vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
122 normals->push_back( osg::Vec3( -1.0, 0.0, 0.0 ) );
125 vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
126 vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
127 vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
128 vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
129 normals->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
132 vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
133 vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
134 vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
135 vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
136 normals->push_back( osg::Vec3( 0.0, -1.0, 0.0 ) );
139 vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
140 vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
141 vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
142 vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
143 normals->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
146 cube->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0, vertices->size() ) );
147 cube->setVertexArray( vertices );
150 cube->setTexCoordArray( 0, vertices );
153 cube->setNormalArray( normals );
154 cube->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE );
157 colors->push_back( color );
158 cube->setColorArray( colors );
159 cube->setColorBinding( osg::Geometry::BIND_OVERALL );
167 osg::ref_ptr< osg::Geometry > cube =
new osg::Geometry();
168 osg::ref_ptr< osg::Vec3Array > vertices = osg::ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
169 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
171 vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
172 vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
173 vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
174 vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
175 vertices->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
176 vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
177 vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
178 vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
179 vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
180 vertices->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
182 cube->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, vertices->size() ) );
184 vertices->push_back( osg::Vec3( 0.0, 1.0, 0.0 ) );
185 vertices->push_back( osg::Vec3( 0.0, 1.0, 1.0 ) );
186 vertices->push_back( osg::Vec3( 1.0, 0.0, 0.0 ) );
187 vertices->push_back( osg::Vec3( 1.0, 0.0, 1.0 ) );
188 vertices->push_back( osg::Vec3( 1.0, 1.0, 0.0 ) );
189 vertices->push_back( osg::Vec3( 1.0, 1.0, 1.0 ) );
191 cube->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINES, vertices->size() - 6, 6 ) );
194 cube->setVertexArray( vertices );
197 cube->setTexCoordArray( 0, vertices );
200 colors->push_back( color );
201 cube->setColorArray( colors );
202 cube->setColorBinding( osg::Geometry::BIND_OVERALL );
209 WAssert( bb.valid(),
"Invalid bounding box!" );
212 osg::ref_ptr< osg::Geode > cube =
new osg::Geode();
213 cube->setName(
"Solid Bounding Box" );
214 if( threeDTexCoords )
220 osg::ref_ptr< osg::ShapeDrawable > cubeDrawable =
new osg::ShapeDrawable(
new osg::Box( osg::Vec3( 0.5, 0.5, 0.5 ), 1.0 ) );
221 cubeDrawable->setColor( color );
222 cube->addDrawable( cubeDrawable );
226 osg::Matrixd transformM;
228 transformM.makeTranslate( bb.
getMin() );
232 osg::ref_ptr< osg::MatrixTransform > transform =
new osg::MatrixTransform();
233 transform->setMatrix( scaleM * transformM );
234 transform->addChild( cube );
237 osg::StateSet* state = cube->getOrCreateStateSet();
238 state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
244 const WColor& defaultColor,
249 osg::ref_ptr< osg::Geometry> geometry(
new osg::Geometry );
250 geometry->setVertexArray( mesh->getVertexArray() );
252 osg::DrawElementsUInt* surfaceElement;
254 surfaceElement =
new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );
256 std::vector< size_t > tris = mesh->getTriangles();
257 surfaceElement->reserve( tris.size() );
259 for(
unsigned int vertId = 0; vertId < tris.size(); ++vertId )
261 surfaceElement->push_back( tris[vertId] );
263 geometry->addPrimitiveSet( surfaceElement );
266 if( mesh->getVertexColorArray() && useMeshColor )
268 geometry->setColorArray( mesh->getVertexColorArray() );
269 geometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
273 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
274 colors->push_back( defaultColor );
275 geometry->setColorArray( colors );
276 geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
283 geometry->setNormalArray( mesh->getVertexNormalArray() );
284 geometry->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
289 osg::StateSet* state = geometry->getOrCreateStateSet();
290 osg::ref_ptr<osg::LightModel> lightModel =
new osg::LightModel();
291 lightModel->setTwoSided(
true );
292 state->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
293 state->setMode( GL_BLEND, osg::StateAttribute::ON );
295 osg::ref_ptr< osg::Material > material =
new osg::Material();
296 material->setDiffuse( osg::Material::FRONT, osg::Vec4( 1.0, 1.0, 1.0, 1.0 ) );
297 material->setSpecular( osg::Material::FRONT, osg::Vec4( 0.0, 0.0, 0.0, 1.0 ) );
298 material->setAmbient( osg::Material::FRONT, osg::Vec4( 0.1, 0.1, 0.1, 1.0 ) );
299 material->setEmission( osg::Material::FRONT, osg::Vec4( 0.0, 0.0, 0.0, 1.0 ) );
300 material->setShininess( osg::Material::FRONT, 25.0 );
301 state->setAttribute( material );
307 geometry->setUseDisplayList(
false );
308 geometry->setUseVertexBufferObjects(
true );
314 bool includeNormals,
bool lighting )
316 osg::Geometry* geometry =
convertToOsgGeometry( mesh, defaultColor, includeNormals, lighting,
false );
320 osg::ref_ptr< osg::Vec4Array > colors = osg::ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
321 for(
size_t i = 0; i < mesh->vertSize(); ++i )
323 colors->push_back( defaultColor );
325 for( std::map< size_t, WColor >::const_iterator vc = colorMap.
getData().begin(); vc != colorMap.
getData().end(); ++vc )
328 if( vc->first < colors->size() )
330 colors->at( vc->first ) = vc->second;
334 geometry->setColorArray( colors );
335 geometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
343 ref_ptr< osg::Vec3Array > vertices = ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
344 ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
345 ref_ptr< osg::Geometry > geometry = ref_ptr< osg::Geometry >(
new osg::Geometry );
347 for(
size_t i = 1; i < line.
size(); ++i )
349 vertices->push_back( osg::Vec3( line[i-1][0], line[i-1][1], line[i-1][2] ) );
352 vertices->push_back( osg::Vec3( line.
back()[0], line.
back()[1], line.
back()[2] ) );
353 colors->push_back( colors->back() );
355 geometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, line.
size() ) );
356 geometry->setVertexArray( vertices );
358 if( color != WColor( 0, 0, 0, 0 ) )
361 colors->push_back( color );
362 geometry->setColorArray( colors );
363 geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
367 geometry->setColorArray( colors );
368 geometry->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
372 osg::StateSet* stateset = geometry->getOrCreateStateSet();
373 stateset->setAttributeAndModes(
new osg::LineWidth( thickness ), osg::StateAttribute::ON );
374 stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
376 osg::ref_ptr< osg::Geode > geode = osg::ref_ptr< osg::Geode >(
new osg::Geode );
377 geode->addDrawable( geometry );
381 osg::ref_ptr< osg::PositionAttitudeTransform >
wge::addLabel( osg::Vec3 position, std::string text )
383 osg::ref_ptr< osgText::Text > label = osg::ref_ptr< osgText::Text >(
new osgText::Text() );
384 osg::ref_ptr< osg::Geode > labelGeode = osg::ref_ptr< osg::Geode >(
new osg::Geode() );
386 labelGeode->addDrawable( label );
390 label->setBackdropType( osgText::Text::OUTLINE );
391 label->setCharacterSize( 6 );
393 label->setText( text );
394 label->setAxisAlignment( osgText::Text::SCREEN );
395 label->setDrawMode( osgText::Text::TEXT );
396 label->setAlignment( osgText::Text::CENTER_TOP );
397 label->setPosition( osg::Vec3( 0.0, 0.0, 0.0 ) );
398 label->setColor( osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ) );
400 osg::ref_ptr< osg::PositionAttitudeTransform > labelXform =
401 osg::ref_ptr< osg::PositionAttitudeTransform >(
new osg::PositionAttitudeTransform() );
402 labelXform->setPosition( position );
404 labelXform->addChild( labelGeode );
411 std::string label =
"(" + boost::lexical_cast< std::string >( position[0] ) +
"," +
412 boost::lexical_cast< std::string >( position[1] ) +
"," + boost::lexical_cast< std::string >( position[2] ) +
")";
413 return (
addLabel( position, label ) );
419 ref_ptr< osg::Vec3Array > vertices = ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
420 ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
421 ref_ptr< osg::Geometry > geometry = ref_ptr< osg::Geometry >(
new osg::Geometry );
423 colors->push_back( color );
430 geometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0, 4 ) );
431 geometry->setVertexArray( vertices );
432 geometry->setColorArray( colors );
433 geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
435 osg::StateSet* stateset =
new osg::StateSet;
436 stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
437 geometry->setStateSet( stateset );
439 osg::ref_ptr< osg::Geode > geode = osg::ref_ptr< osg::Geode >(
new osg::Geode );
440 geode->addDrawable( geometry );
444 vertices->push_back( vertices->front() );
445 ref_ptr< osg::Geometry > borderGeom = ref_ptr< osg::Geometry >(
new osg::Geometry );
446 borderGeom->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, 4 ) );
447 borderGeom->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 3, 2 ) );
448 ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >(
new osg::Vec4Array );
449 colors->push_back( inverseColor( color ) );
450 borderGeom->setColorArray( colors );
451 borderGeom->setColorBinding( osg::Geometry::BIND_OVERALL );
452 borderGeom->setVertexArray( vertices );
453 geode->addDrawable( borderGeom );
458 osg::ref_ptr< osg::Geode >
wge::genFinitePlane( osg::Vec3
const& base, osg::Vec3
const& a, osg::Vec3
const& b )
461 osg::ref_ptr< osg::Vec3Array > vertices =
new osg::Vec3Array;
462 osg::ref_ptr< osg::Vec3Array > texcoords0 =
new osg::Vec3Array;
463 osg::ref_ptr< osg::Vec3Array > normals =
new osg::Vec3Array;
464 osg::ref_ptr< osg::Vec4Array > colors =
new osg::Vec4Array;
466 osg::Vec3 aPlusB = a + b;
468 vertices->push_back( base );
469 vertices->push_back( base + a );
470 vertices->push_back( base + aPlusB );
471 vertices->push_back( base + b );
473 osg::Vec3 aCrossB = a ^ b;
480 normals->push_back( aCrossB );
481 colors->push_back( osg::Vec4( 1.0, 1.0, 1.0, 1.0 ) );
482 texcoords0->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
483 texcoords0->push_back( aNorm );
484 texcoords0->push_back( aNorm + bNorm );
485 texcoords0->push_back( bNorm );
488 osg::ref_ptr< osg::Geometry > geometry =
new osg::Geometry();
489 geometry->setVertexArray( vertices );
490 geometry->setTexCoordArray( 0, texcoords0 );
491 geometry->setNormalBinding( osg::Geometry::BIND_OVERALL );
492 geometry->setColorBinding( osg::Geometry::BIND_OVERALL );
493 geometry->setNormalArray( normals );
494 geometry->setColorArray( colors );
495 geometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0, 4 ) );
497 osg::ref_ptr< osg::Geode > geode =
new osg::Geode();
498 geode->addDrawable( geometry );
504 WAssert( resX > 0 && resY > 0,
"A Plane with no quad is not supported, use another datatype for that!" );
505 double dx = ( resX > 1 ? 1.0 / ( resX - 1 ) : 1.0 );
506 double dy = ( resY > 1 ? 1.0 / ( resY - 1 ) : 1.0 );
508 size_t numQuads = resX * resY;
511 ref_ptr< osg::Vec3Array > vertices = ref_ptr< osg::Vec3Array >(
new osg::Vec3Array( numQuads * 4 ) );
512 ref_ptr< osg::Vec3Array > centers = ref_ptr< osg::Vec3Array >(
new osg::Vec3Array( numQuads ) );
513 ref_ptr< osg::Vec4Array > colors = ref_ptr< osg::Vec4Array >(
new osg::Vec4Array( numQuads ) );
515 for(
size_t yQuad = 0; yQuad < resY; ++yQuad )
517 for(
size_t xQuad = 0; xQuad < resX; ++xQuad )
519 size_t qIndex = yQuad * resX + xQuad;
520 size_t vIndex = qIndex * 4;
521 vertices->at( vIndex ) = osg::Vec3( xQuad * dx + spacing, yQuad * dy + spacing, 0.0 );
522 vertices->at( vIndex + 1 ) = osg::Vec3( xQuad * dx + dx - spacing, yQuad * dy + spacing, 0.0 );
523 vertices->at( vIndex + 2 ) = osg::Vec3( xQuad * dx + dx - spacing, yQuad * dy + dy - spacing, 0.0 );
524 vertices->at( vIndex + 3 ) = osg::Vec3( xQuad * dx + spacing, yQuad * dy + dy - spacing, 0.0 );
525 centers->at( qIndex ) = osg::Vec3( xQuad * dx + dx / 2.0, yQuad * dy + dy / 2.0, 0.0 );
526 colors->at( qIndex ) = osg::Vec4( 0.1 + static_cast< double >( qIndex ) / numQuads * 0.6,
527 0.1 + static_cast< double >( qIndex ) / numQuads * 0.6,
532 ref_ptr< osg::Geometry > geometry = ref_ptr< osg::Geometry >(
new osg::Geometry );
533 geometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0, vertices->size() ) );
534 geometry->setVertexArray( vertices );
535 geometry->setColorArray( colors );
536 geometry->setColorBinding( osg::Geometry::BIND_PER_PRIMITIVE );
538 ref_ptr< osg::Vec3Array > normals = ref_ptr< osg::Vec3Array >(
new osg::Vec3Array );
539 normals->push_back( osg::Vec3( 0.0, 0.0, 1.0 ) );
540 geometry->setNormalArray( normals );
541 geometry->setNormalBinding( osg::Geometry::BIND_OVERALL );
542 osg::ref_ptr< WGESubdividedPlane > geode = osg::ref_ptr< WGESubdividedPlane >(
new WGESubdividedPlane );
543 geode->addDrawable( geometry );
544 geode->setCenterArray( centers );
547 osg::StateSet* state = geode->getOrCreateStateSet();
548 state->setMode( GL_BLEND, osg::StateAttribute::ON );
549 state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED );
561 osg::ref_ptr< WGEGroupNode >groupNode =
new WGEGroupNode();
562 osg::ref_ptr< WGEShader > shaderCoordinateSystem(
new WGEShader(
"WGECoordinateSystem" ) );
564 osg::ref_ptr< osg::Geode > graphX(
new osg::Geode );
565 osg::ref_ptr< osg::Geode > graphY(
new osg::Geode );
566 osg::ref_ptr< osg::Geode > graphZ(
new osg::Geode );
568 osg::ref_ptr< osg::Geode > graphXCylinder(
new osg::Geode );
569 osg::ref_ptr< osg::Geode > graphYCylinder(
new osg::Geode );
570 osg::ref_ptr< osg::Geode > graphZCylinder(
new osg::Geode );
573 osg::ref_ptr< osg::ShapeDrawable > cylinderX =
new osg::ShapeDrawable(
new osg::Cylinder(
574 middle, 1, sizeX + ( sizeX * 0.5 )
576 osg::ref_ptr< osg::ShapeDrawable > cylinderXEnd =
new osg::ShapeDrawable(
new osg::Cylinder(
577 osg::Vec3( middle.x(), middle.y(), middle.z() - ( sizeX + ( sizeX * 0.5 ) ) / 2.0 ), 1.0, 1.0
579 osg::ref_ptr< osg::ShapeDrawable > coneX =
new osg::ShapeDrawable(
new osg::Cone(
580 osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeX + ( sizeX * 0.5 ) ) / 2.0 ), 2.0, 5.0
582 cylinderXEnd->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
583 graphXCylinder->addDrawable( cylinderX );
584 graphX->addDrawable( coneX );
585 graphX->addDrawable( cylinderXEnd );
587 osg::ref_ptr< osg::Material > matX =
new osg::Material();
588 matX->setDiffuse( osg::Material::FRONT, WColor( 1.0, 0.0, 0.0, 1.0 ) );
589 cylinderX->getOrCreateStateSet()->setAttribute( matX, osg::StateAttribute::ON );
590 coneX->getOrCreateStateSet()->setAttribute( matX, osg::StateAttribute::ON );
593 osg::ref_ptr< osg::ShapeDrawable > cylinderY =
new osg::ShapeDrawable(
new osg::Cylinder(
594 middle, 1, sizeY + ( sizeY * 0.5 )
596 osg::ref_ptr< osg::ShapeDrawable > cylinderYEnd =
new osg::ShapeDrawable(
new osg::Cylinder(
597 osg::Vec3( middle.x(), middle.y(), middle.z() - ( sizeY + ( sizeY * 0.5 ) ) / 2.0 ), 1.0, 1.0
599 osg::ref_ptr< osg::ShapeDrawable > coneY =
new osg::ShapeDrawable(
new osg::Cone(
600 osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeY + ( sizeY * 0.5 ) ) / 2.0 ), 2.0, 5.0
602 cylinderYEnd->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
604 graphYCylinder->addDrawable( cylinderY );
605 graphY->addDrawable( coneY );
606 graphY->addDrawable( cylinderYEnd );
608 osg::ref_ptr< osg::Material > matY =
new osg::Material();
609 matY->setDiffuse( osg::Material::FRONT, WColor( 0.0, 1.0, 0.0, 1.0 ) );
610 cylinderY->getOrCreateStateSet()->setAttribute( matY, osg::StateAttribute::ON );
611 coneY->getOrCreateStateSet()->setAttribute( matY, osg::StateAttribute::ON );
615 osg::ref_ptr< osg::ShapeDrawable > cylinderZ =
new osg::ShapeDrawable(
new osg::Cylinder(
616 middle, 1, sizeZ + ( sizeZ * 0.5 )
618 osg::ref_ptr< osg::ShapeDrawable > cylinderZEnd =
new osg::ShapeDrawable(
new osg::Cylinder(
619 osg::Vec3( middle.x(), middle.y(), middle.z() - ( sizeZ + ( sizeZ * 0.5 ) ) / 2.0 ), 1.0, 1.0
621 osg::ref_ptr< osg::ShapeDrawable > coneZ =
new osg::ShapeDrawable(
new osg::Cone(
622 osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeZ + ( sizeZ * 0.5 ) ) / 2.0 ), 2.0, 5.0
624 cylinderZEnd->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
626 graphZCylinder->addDrawable( cylinderZ );
627 graphZ->addDrawable( coneZ );
628 graphZ->addDrawable( cylinderZEnd );
630 osg::ref_ptr< osg::Material > matZ =
new osg::Material();
631 matZ->setDiffuse( osg::Material::FRONT, WColor( 0.0, 0.0, 1.0, 1.0 ) );
632 cylinderZ->getOrCreateStateSet()->setAttribute( matZ, osg::StateAttribute::ON );
633 coneZ->getOrCreateStateSet()->setAttribute( matZ, osg::StateAttribute::ON );
635 shaderCoordinateSystem->apply( graphXCylinder );
636 shaderCoordinateSystem->apply( graphYCylinder );
637 shaderCoordinateSystem->apply( graphZCylinder );
639 osg::ref_ptr< WGELabel > graphXLabel =
new WGELabel();
640 graphXLabel->setText(
"X" );
641 graphXLabel->setCharacterSize( 10 );
642 graphXLabel->setPosition( osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeX + ( sizeX * 0.5 ) ) / 2.0 + 5.0 ) );
643 graphXLabel->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
644 graphX->addDrawable( graphXLabel );
646 osg::ref_ptr< WGELabel > graphYLabel =
new WGELabel();
647 graphYLabel->setText(
"Y" );
648 graphYLabel->setCharacterSize( 10 );
649 graphYLabel->setPosition( osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeY + ( sizeY * 0.5 ) ) / 2.0 + 5.0 ) );
650 graphYLabel->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
651 graphY->addDrawable( graphYLabel );
653 osg::ref_ptr< WGELabel > graphZLabel =
new WGELabel();
654 graphZLabel->setText(
"Z" );
655 graphZLabel->setCharacterSize( 10 );
656 graphZLabel->setPosition( osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeZ + ( sizeZ * 0.5 ) ) / 2.0 + 5.0 ) );
657 graphZLabel->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
658 graphZ->addDrawable( graphZLabel );
661 osg::ref_ptr< osg::MatrixTransform > graphXTransform =
new osg::MatrixTransform();
662 graphXTransform->addChild( graphX );
663 graphXTransform->addChild( graphXCylinder );
664 osg::ref_ptr< osg::MatrixTransform > graphYTransform =
new osg::MatrixTransform();
665 graphYTransform->addChild( graphY );
666 graphYTransform->addChild( graphYCylinder );
667 osg::ref_ptr< osg::MatrixTransform > graphZTransform =
new osg::MatrixTransform();
668 graphZTransform->addChild( graphZ );
669 graphZTransform->addChild( graphZCylinder );
671 osg::Matrixd matrixTranslateTo0 = osg::Matrixd::translate( -middle.x(), -middle.y(), -middle.z() );
672 osg::Matrixd matrixTranslateFrom0 = osg::Matrixd::translate( middle.x(), middle.y(), middle.z() );
674 graphXTransform->setMatrix( matrixTranslateTo0 * osg::Matrixd::rotate(
675 90.0 * piDouble / 180.0,
676 osg::Vec3f( 0.0, 1.0, 0.0 ) ) * matrixTranslateFrom0
678 graphYTransform->setMatrix( matrixTranslateTo0 * osg::Matrixd::rotate(
679 -90.0 * piDouble / 180.0,
680 osg::Vec3f( 1.0, 0.0, 0.0 ) ) * matrixTranslateFrom0
683 groupNode->insert( graphXTransform );
684 groupNode->insert( graphYTransform );
685 groupNode->insert( graphZTransform );