Commit 78c56118 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[ADD] - added nice utility to create sophisticated coordinate system...

[ADD] - added nice utility to create sophisticated coordinate system representations with the WGE. This work was done by David Geistert.
parent c8c8235c
...@@ -36,11 +36,14 @@ ...@@ -36,11 +36,14 @@
#include "../common/math/linearAlgebra/WLinearAlgebra.h" #include "../common/math/linearAlgebra/WLinearAlgebra.h"
#include "../common/WPathHelper.h" #include "../common/WPathHelper.h"
#include "../common/math/WMath.h"
#include "WGESubdividedPlane.h" #include "WGESubdividedPlane.h"
#include "WGEGeodeUtils.h" #include "WGEGeodeUtils.h"
#include "WGEGeometryUtils.h" #include "WGEGeometryUtils.h"
#include "WGEUtils.h" #include "WGEUtils.h"
#include "WGEGroupNode.h"
#include "shaders/WGEShader.h"
#include "widgets/labeling/WGELabel.h"
osg::ref_ptr< osg::Geode > wge::generateBoundingBoxGeode( const WBoundingBox& bb, const WColor& color ) osg::ref_ptr< osg::Geode > wge::generateBoundingBoxGeode( const WBoundingBox& bb, const WColor& color )
{ {
...@@ -307,8 +310,8 @@ osg::ref_ptr< osg::Geometry > wge::convertToOsgGeometry( WTriangleMesh::SPtr mes ...@@ -307,8 +310,8 @@ osg::ref_ptr< osg::Geometry > wge::convertToOsgGeometry( WTriangleMesh::SPtr mes
return geometry; return geometry;
} }
osg::ref_ptr< osg::Geometry > wge::convertToOsgGeometry( WTriangleMesh::SPtr mesh, const WColoredVertices& colorMap, osg::ref_ptr< osg::Geometry > wge::convertToOsgGeometry( WTriangleMesh::SPtr mesh, const WColoredVertices& colorMap, const WColor& defaultColor,
const WColor& defaultColor, bool includeNormals, bool lighting ) bool includeNormals, bool lighting )
{ {
osg::Geometry* geometry = convertToOsgGeometry( mesh, defaultColor, includeNormals, lighting, false ); osg::Geometry* geometry = convertToOsgGeometry( mesh, defaultColor, includeNormals, lighting, false );
...@@ -551,3 +554,138 @@ osg::ref_ptr< WGESubdividedPlane > wge::genUnitSubdividedPlane( size_t resX, siz ...@@ -551,3 +554,138 @@ osg::ref_ptr< WGESubdividedPlane > wge::genUnitSubdividedPlane( size_t resX, siz
return geode; return geode;
} }
osg::ref_ptr< osg::Group > wge::creatCoordinateSystem(
osg::Vec3 middle,
double sizeX,
double sizeY,
double sizeZ
)
{
osg::ref_ptr< WGEGroupNode >groupNode = new WGEGroupNode();
osg::ref_ptr< WGEShader > shaderCoordinateSystem( new WGEShader( "WGECoordinateSystem" ) );
osg::ref_ptr< osg::Geode > graphX( new osg::Geode );
osg::ref_ptr< osg::Geode > graphY( new osg::Geode );
osg::ref_ptr< osg::Geode > graphZ( new osg::Geode );
osg::ref_ptr< osg::Geode > graphXCylinder( new osg::Geode );
osg::ref_ptr< osg::Geode > graphYCylinder( new osg::Geode );
osg::ref_ptr< osg::Geode > graphZCylinder( new osg::Geode );
// X
osg::ref_ptr< osg::ShapeDrawable > cylinderX = new osg::ShapeDrawable( new osg::Cylinder(
middle, 1, sizeX + ( sizeX * 0.5 )
) );
osg::ref_ptr< osg::ShapeDrawable > cylinderXEnd = new osg::ShapeDrawable( new osg::Cylinder(
osg::Vec3( middle.x(), middle.y(), middle.z() - ( sizeX + ( sizeX * 0.5 ) ) / 2.0 ), 1.0, 1.0
) );
osg::ref_ptr< osg::ShapeDrawable > coneX = new osg::ShapeDrawable( new osg::Cone(
osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeX + ( sizeX * 0.5 ) ) / 2.0 ), 2.0, 5.0
) );
cylinderXEnd->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
graphXCylinder->addDrawable( cylinderX );
graphX->addDrawable( coneX );
graphX->addDrawable( cylinderXEnd );
osg::ref_ptr< osg::Material > matX = new osg::Material();
matX->setDiffuse( osg::Material::FRONT, WColor( 1.0, 0.0, 0.0, 1.0 ) );
cylinderX->getOrCreateStateSet()->setAttribute( matX, osg::StateAttribute::ON );
coneX->getOrCreateStateSet()->setAttribute( matX, osg::StateAttribute::ON );
// Y
osg::ref_ptr< osg::ShapeDrawable > cylinderY = new osg::ShapeDrawable( new osg::Cylinder(
middle, 1, sizeY + ( sizeY * 0.5 )
) );
osg::ref_ptr< osg::ShapeDrawable > cylinderYEnd = new osg::ShapeDrawable( new osg::Cylinder(
osg::Vec3( middle.x(), middle.y(), middle.z() - ( sizeY + ( sizeY * 0.5 ) ) / 2.0 ), 1.0, 1.0
) );
osg::ref_ptr< osg::ShapeDrawable > coneY = new osg::ShapeDrawable( new osg::Cone(
osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeY + ( sizeY * 0.5 ) ) / 2.0 ), 2.0, 5.0
) );
cylinderYEnd->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
graphYCylinder->addDrawable( cylinderY );
graphY->addDrawable( coneY );
graphY->addDrawable( cylinderYEnd );
osg::ref_ptr< osg::Material > matY = new osg::Material();
matY->setDiffuse( osg::Material::FRONT, WColor( 0.0, 1.0, 0.0, 1.0 ) );
cylinderY->getOrCreateStateSet()->setAttribute( matY, osg::StateAttribute::ON );
coneY->getOrCreateStateSet()->setAttribute( matY, osg::StateAttribute::ON );
// Z
osg::ref_ptr< osg::ShapeDrawable > cylinderZ = new osg::ShapeDrawable( new osg::Cylinder(
middle, 1, sizeZ + ( sizeZ * 0.5 )
) );
osg::ref_ptr< osg::ShapeDrawable > cylinderZEnd = new osg::ShapeDrawable( new osg::Cylinder(
osg::Vec3( middle.x(), middle.y(), middle.z() - ( sizeZ + ( sizeZ * 0.5 ) ) / 2.0 ), 1.0, 1.0
) );
osg::ref_ptr< osg::ShapeDrawable > coneZ = new osg::ShapeDrawable( new osg::Cone(
osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeZ + ( sizeZ * 0.5 ) ) / 2.0 ), 2.0, 5.0
) );
cylinderZEnd->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
graphZCylinder->addDrawable( cylinderZ );
graphZ->addDrawable( coneZ );
graphZ->addDrawable( cylinderZEnd );
osg::ref_ptr< osg::Material > matZ = new osg::Material();
matZ->setDiffuse( osg::Material::FRONT, WColor( 0.0, 0.0, 1.0, 1.0 ) );
cylinderZ->getOrCreateStateSet()->setAttribute( matZ, osg::StateAttribute::ON );
coneZ->getOrCreateStateSet()->setAttribute( matZ, osg::StateAttribute::ON );
shaderCoordinateSystem->apply( graphXCylinder );
shaderCoordinateSystem->apply( graphYCylinder );
shaderCoordinateSystem->apply( graphZCylinder );
osg::ref_ptr< WGELabel > graphXLabel = new WGELabel();
graphXLabel->setText( "X" );
graphXLabel->setCharacterSize( 10 );
graphXLabel->setPosition( osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeX + ( sizeX * 0.5 ) ) / 2.0 + 5.0 ) );
graphXLabel->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
graphX->addDrawable( graphXLabel );
osg::ref_ptr< WGELabel > graphYLabel = new WGELabel();
graphYLabel->setText( "Y" );
graphYLabel->setCharacterSize( 10 );
graphYLabel->setPosition( osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeY + ( sizeY * 0.5 ) ) / 2.0 + 5.0 ) );
graphYLabel->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
graphY->addDrawable( graphYLabel );
osg::ref_ptr< WGELabel > graphZLabel = new WGELabel();
graphZLabel->setText( "Z" );
graphZLabel->setCharacterSize( 10 );
graphZLabel->setPosition( osg::Vec3( middle.x(), middle.y(), middle.z() + ( sizeZ + ( sizeZ * 0.5 ) ) / 2.0 + 5.0 ) );
graphZLabel->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
graphZ->addDrawable( graphZLabel );
osg::ref_ptr< osg::MatrixTransform > graphXTransform = new osg::MatrixTransform();
graphXTransform->addChild( graphX );
graphXTransform->addChild( graphXCylinder );
osg::ref_ptr< osg::MatrixTransform > graphYTransform = new osg::MatrixTransform();
graphYTransform->addChild( graphY );
graphYTransform->addChild( graphYCylinder );
osg::ref_ptr< osg::MatrixTransform > graphZTransform = new osg::MatrixTransform();
graphZTransform->addChild( graphZ );
graphZTransform->addChild( graphZCylinder );
osg::Matrixd matrixTranslateTo0 = osg::Matrixd::translate( -middle.x(), -middle.y(), -middle.z() );
osg::Matrixd matrixTranslateFrom0 = osg::Matrixd::translate( middle.x(), middle.y(), middle.z() );
graphXTransform->setMatrix( matrixTranslateTo0 * osg::Matrixd::rotate(
90.0 * piDouble / 180.0,
osg::Vec3f( 0.0, 1.0, 0.0 ) ) * matrixTranslateFrom0
);
graphYTransform->setMatrix( matrixTranslateTo0 * osg::Matrixd::rotate(
-90.0 * piDouble / 180.0,
osg::Vec3f( 1.0, 0.0, 0.0 ) ) * matrixTranslateFrom0
);
groupNode->insert( graphXTransform );
groupNode->insert( graphYTransform );
groupNode->insert( graphZTransform );
return groupNode;
}
...@@ -175,6 +175,24 @@ namespace wge ...@@ -175,6 +175,24 @@ namespace wge
const WColor& color = WColor( 0.0, 0.7, 0.7, 1.0 ), const WColor& color = WColor( 0.0, 0.7, 0.7, 1.0 ),
bool border = false ); bool border = false );
/**
* Create a coordinate system. The coordinate system is build from cylinders and cones and includes a positive-to-negative
* color gradient.
*
* \param middle osg::Vec3( middleX, middleY, middleZ ) middle points of X, Y, Z
* \param sizeX whole lenght of X
* \param sizeY whole lenght of Y
* \param sizeZ whole lenght of Z
*
* \return Group Node
*/
osg::ref_ptr< osg::Group > creatCoordinateSystem(
osg::Vec3 middle,
double sizeX,
double sizeY,
double sizeZ
);
/** /**
* Generates a geode out of two vectors and an origin position. * Generates a geode out of two vectors and an origin position.
* *
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#version 120
#include "WGEShadingTools.glsl"
/**
* The normal.
*/
varying vec3 v_normal;
void main()
{
vec4 col = gl_FrontMaterial.diffuse;
vec4 white = vec4( 1, 1, 1, 1 );
// calculate lighting
float light = blinnPhongIlluminationIntensity( normalize( v_normal ) );
col *= light;
// use texture coordinate to mix along the cylinder
gl_FragColor = mix( white, col, gl_TexCoord[0].t + 0.2 );
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#version 120
/**
* The normal.
*/
varying vec3 v_normal;
void main()
{
// parameterizes the cylinder's surface
gl_TexCoord[0] = gl_MultiTexCoord0;
// get normal
v_normal = gl_NormalMatrix * gl_Normal;
// apply standard pipeline
gl_FrontColor = gl_Color;
gl_Position = ftransform();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment