![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsImplicitObject_Torus.cpp 00003 ******************************************************************************/ 00007 /****************************************************************************** 00008 SUKITTI PUNAK (10/14/2009) 00009 UPDATE (09/03/2010) 00010 ******************************************************************************/ 00011 #include "TAPsImplicitObject_Torus.hpp" 00012 // Using Inclusion Model (i.e. definitions are included in declarations) 00013 // (this name.cpp is included in name.hpp) 00014 // Each friend is defined directly inside its declaration. 00015 00016 BEGIN_NAMESPACE_TAPs 00017 //============================================================================= 00018 00019 // Default constructor 00020 template <typename T> 00021 ImplicitObject_Torus<T>::ImplicitObject_Torus ( T inner_radius, T outer_radius, std::string & name ) 00022 : ImplicitObject<T>( Enum::TORUS, name ) 00023 , m_InnerRadius( inner_radius ) 00024 , m_OuterRadius( outer_radius ) 00025 {} 00026 00027 00028 // Copy constructor 00029 template <typename T> 00030 ImplicitObject_Torus<T>::ImplicitObject_Torus ( ImplicitObject_Torus<T> const & obj ) 00031 : ImplicitObject<T>( obj ) 00032 , m_InnerRadius( obj.inner_radius ) 00033 , m_OuterRadius( obj.outer_radius ) 00034 {} 00035 00036 00037 // Destructor 00038 template <typename T> 00039 ImplicitObject_Torus<T>::~ImplicitObject_Torus () 00040 {} 00041 00042 00043 // Return this object info as a string 00044 template <typename T> 00045 std::string ImplicitObject_Torus<T>::StrInfo () const 00046 { 00047 std::ostringstream ss; 00048 ss << "ImplicitObject_Torus<" << typeid(T).name() << ">\n"; 00049 ss << "ID:\t" << m_ID << "; Name:\t" << m_Name << "\n"; 00050 ss << "Inner radius:\t" << m_InnerRadius << "; "; 00051 ss << "Outer radius:\t" << m_OuterRadius << "\n"; 00052 ss << "Transformation Support: " << m_Trx; 00053 00054 return ss.str(); 00055 } 00056 00057 00058 // Assignment Operator 00059 template <typename T> 00060 inline ImplicitObject_Torus<T> & ImplicitObject_Torus<T>::operator= ( ImplicitObject_Torus<T> const &orig ) 00061 { 00062 m_Name = orig.m_Name; 00063 m_Trx = orig.m_Trx; 00064 m_InnerRadius = orig.m_InnerRadius; 00065 m_OuterRadius = orig.m_OuterRadius; 00066 00067 return *this; 00068 } 00069 00070 00071 // Build a BVH tree for this implicit torus 00072 template <typename T> 00073 void ImplicitObject_Torus<T>::BuildBVHTree ( int details, Enum::CD treeType ) 00074 { 00075 // m_pBVHTree is inherited from ColDetSupport class 00076 if ( m_pBVHTree ) delete m_pBVHTree; 00077 00078 switch ( treeType ) { 00079 case Enum::BVH_TREE_BINARY_SPHERE: 00080 { 00081 BVHNode<T> * rootNode = new BVHNodeLeaf<T>( Enum::BVH_NODE_LEAF_SPHERE, 0 ); 00082 rootNode->SetCenter( 0, 0, 0 ); 00083 rootNode->SetRadius( m_OuterRadius+m_InnerRadius ); 00084 m_pBVHTree = new BVHTree_BinarySphere<T>( GetTransform(), 1, rootNode ); 00085 } 00086 break; 00087 default: 00088 std::cout << "ImplicitObject_Torus<T>::BuildBVHTree for Tree Type (" << treeType << ") NOT IMPLEMENTED YET!\n"; 00089 break; 00090 } 00091 } 00092 00093 00094 // Get transformed radii 00095 template <typename T> 00096 void ImplicitObject_Torus<T>::GetTransformedRadii ( T & inner_radius, T & outer_radius ) const 00097 { 00098 Vector3<T> pt2( (m_Trx.RefToMatrixTransform() * Vector4<T>( m_OuterRadius+m_InnerRadius, 0, 0, 1 )).GetVector3() ); 00099 Vector3<T> pt1( (m_Trx.RefToMatrixTransform() * Vector4<T>( m_OuterRadius, 0, 0, 1 )).GetVector3() ); 00100 inner_radius = (pt2 - pt1).Length(); 00101 outer_radius = (pt1 - GetTransformedCenter()).Length(); 00102 } 00103 00104 00105 // Get transformed axis 00106 template <typename T> 00107 Vector3<T> ImplicitObject_Torus<T>::GetTransformedAxis () const 00108 { 00109 return (m_Trx.RefToMatrixTransform() * Vector4<T>( 0, 0, 1, 1 )).GetVector3() - GetTransformedCenter(); 00110 } 00111 00112 00113 //----------------------------------------------------------------------------- 00114 #if defined(__gl_h_) || defined(__GL_H__) 00115 //----------------------------------------------------------------------------- 00116 // Drawn by OpenGL 00117 template <typename T> 00118 void ImplicitObject_Torus<T>::Draw( GLenum mode, GLint nsides, GLint rings ) 00119 { 00120 #ifdef TAPs_USE_GLSL 00121 assert( ShaderProgram ); 00122 OpenGL::GlobalGLSLShaderPool::GetShaderProgram( ShaderName )->BeginGLSL(); 00123 OpenGL::GlobalGLSLShaderPool::SetShaderParameters( ShaderName ); 00124 #endif//TAPs_USE_GLSL 00125 00126 //GLfloat mat[16]; 00127 //glGetFloatv( GL_MODELVIEW_MATRIX, mat ); 00128 //std::cout << mat[ 0] << "\t" << mat[ 4] << "\t" << mat[ 8] << "\t" << mat[12] << "\n"; 00129 //std::cout << mat[ 1] << "\t" << mat[ 5] << "\t" << mat[ 9] << "\t" << mat[13] << "\n"; 00130 //std::cout << mat[ 2] << "\t" << mat[ 6] << "\t" << mat[10] << "\t" << mat[14] << "\n"; 00131 //std::cout << mat[ 3] << "\t" << mat[ 7] << "\t" << mat[11] << "\t" << mat[15] << "\n"; 00132 00133 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00134 glPushMatrix(); 00135 00136 #ifdef TAPs_SHOW_COLLISION_STATE 00137 static GLfloat color1[] = { 0.75, 0.3, 0.3, 1.0 }; 00138 static GLfloat color2[] = { 0.3, 0.75, 0.3, 1.0 }; 00139 if ( IsCollided ) { 00140 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color1 ); 00141 } 00142 else { 00143 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color2 ); 00144 } 00145 #endif//TAPs_SHOW_COLLISION_STATE 00146 00147 m_Trx.TransformByOpenGLForDrawing(); 00148 switch ( mode ) { 00149 case GL_LINES: 00150 glutWireTorus( m_InnerRadius, m_OuterRadius, nsides, rings ); 00151 break; 00152 default: 00153 glutSolidTorus( m_InnerRadius, m_OuterRadius, nsides, rings ); 00154 break; 00155 } 00156 00157 glPopMatrix(); 00158 00159 /* 00160 // Draw Axis 00161 glLineWidth( 5 ); 00162 glBegin( GL_LINES ); 00163 glVertex3fv( GetTransformedCenter().GetDataFloat() ); 00164 glVertex3fv( (GetTransformedAxis()+GetTransformedCenter()).GetDataFloat() ); 00165 glEnd(); 00166 //*/ 00167 00168 glPopAttrib(); 00169 00170 #ifdef TAPs_USE_GLSL 00171 OpenGL::GlobalGLSLShaderPool::GetShaderProgram( ShaderName )->EndGLSL(); 00172 #endif//TAPs_USE_GLSL 00173 } 00174 //----------------------------------------------------------------------------- 00175 #endif // #if defined(__gl_h_) || defined(__GL_H__) 00176 //----------------------------------------------------------------------------- 00177 //============================================================================= 00178 END_NAMESPACE_TAPs 00179 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00180 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----