00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "ManipulatedMeshVertex.h"
00013 #include "assertions.h"
00014 #include <GL/glut.h>
00015
00016 namespace animal {
00017
00018 namespace octree {
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 ManipulatedMeshVertex::ManipulatedMeshVertex( X3DTK::X3D::DeformableOctreeNode *dosn, const X3DTK::SFVec3f *meshVertex ) :
00031 _dosn(dosn)
00032 {
00033 Octree *octree = dosn->getOctree();
00034
00035 Require( octree );
00036
00037 _vertex = NULL;
00038
00039
00040 Cell *cell = octree->root();
00041
00042 if( cell->isLeaf() )
00043 {
00044 OctreeDataPoints::iterator it;
00045 for( it = cell->getData()._points.begin() ;
00046 it != cell->getData()._points.end() ;
00047 ++it )
00048 {
00049 if( (*it)->getSFVec3f() == meshVertex)
00050 {
00051 _vertex = *it;
00052 break;
00053 }
00054 }
00055 Require( _vertex );
00056 }
00057 else
00058 {
00059 while( !cell->isLeaf() )
00060 {
00061 std::cerr << "Searching from cell : " << *cell << "\n";
00062
00063
00064 unsigned int i;
00065 _vertex = NULL;
00066 Cell *child = NULL;
00067 for( i=0 ; i<8 ; ++i )
00068 {
00069 child = cell->child(i);
00070
00071 OctreeDataPoints::iterator it;
00072 for( it = child->getData()._points.begin() ;
00073 it != child->getData()._points.end() ;
00074 ++it )
00075 {
00076 if( (*it)->getSFVec3f() == meshVertex)
00077 {
00078 _vertex = *it;
00079 break;
00080 }
00081 }
00082 if( it != child->getData()._points.end() )
00083 {
00084
00085 break;
00086 }
00087
00088 }
00089
00090 Require( i!=8 );
00091 cell = child;
00092
00093 }
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 _initPos = Vec3d( (*meshVertex)[0], (*meshVertex)[1], (*meshVertex)[2] );
00108
00109
00110
00111 Ensure( _vertex );
00112
00113 }
00114
00115 ManipulatedMeshVertex::~ManipulatedMeshVertex()
00116 {
00117 Require( _octree );
00118 _dosn->updateGL();
00119 }
00120
00122 void ManipulatedMeshVertex::getPoint( float& x, float& y, float& z ) const
00123 {
00124
00125 x = _initPos[0];
00126 y = _initPos[1];
00127 z = _initPos[2];
00128 }
00129
00130
00131 void ManipulatedMeshVertex::moveTo( float x, float y, float z )
00132 {
00133
00134 Require( _octree );
00135 Require( _vertex );
00136 _dosn->getOctree()->directManipulation( _vertex, Vec3d(x,y,z) );
00137 _dosn->getOctree()->movedRecLeaves( _dosn->getOctree()->root() );
00138 _dosn->updateGL();
00139
00140
00141
00142
00143
00144
00145 }
00146
00147
00148 bool ManipulatedMeshVertex::operator==( const ConstrainedItem* mmv ) const
00149 {
00150 const ManipulatedMeshVertex* p = dynamic_cast<const ManipulatedMeshVertex*>(mmv);
00151 return p && (_dosn == p->_dosn) && (_vertex == p->_vertex);
00152 }
00153
00154 void ManipulatedMeshVertex::draw()
00155 {
00156 glPushAttrib( GL_ALL_ATTRIB_BITS );
00157
00158 glDisable( GL_LIGHTING );
00159 glPolygonMode ( GL_FRONT_AND_BACK, GL_LINE );
00160 glEnable (GL_BLEND);
00161 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00162
00163 glPushMatrix();
00164 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
00165 glEnable( GL_CULL_FACE );
00166
00167 X3DTK::SFVec3f pos = *_vertex->getSFVec3f();
00168 glTranslatef( pos[0], pos[1], pos[2] );
00169 glColor4f( 0.0, 0.0 , 1.0, 0.5 );
00170 glutSolidSphere( _dosn->getToolsSize(), 10, 10 );
00171
00172 glPopMatrix();
00173 glPopAttrib();
00174
00175 }
00176
00177 };
00178
00179 };