![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsImplicitObject_Sphere.cpp 00003 ******************************************************************************/ 00007 /****************************************************************************** 00008 SUKITTI PUNAK (10/14/2009) 00009 UPDATE (09/03/2010) 00010 ******************************************************************************/ 00011 #include "TAPsImplicitObject_Sphere.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_Sphere<T>::ImplicitObject_Sphere ( T radius, std::string & name ) 00022 : ImplicitObject<T>( Enum::SPHERE, name ) 00023 , m_Radius( radius ) 00024 {} 00025 00026 00027 // Copy constructor 00028 template <typename T> 00029 ImplicitObject_Sphere<T>::ImplicitObject_Sphere ( ImplicitObject_Sphere<T> const & obj ) 00030 : ImplicitObject<T>( obj ), m_Radius( obj.radius ) 00031 {} 00032 00033 00034 // Destructor 00035 template <typename T> 00036 ImplicitObject_Sphere<T>::~ImplicitObject_Sphere () 00037 {} 00038 00039 00040 // Return this object info as a string 00041 template <typename T> 00042 std::string ImplicitObject_Sphere<T>::StrInfo () const 00043 { 00044 std::ostringstream ss; 00045 ss << "ImplicitObject_Sphere<" << typeid(T).name() << ">\n"; 00046 ss << "ID:\t" << m_ID << "; Name:\t" << m_Name << "\n"; 00047 ss << "Radius:\t" << m_Radius << "\n"; 00048 ss << "Transformation Support: " << m_Trx; 00049 00050 return ss.str(); 00051 } 00052 00053 00054 // Assignment Operator 00055 template <typename T> 00056 inline ImplicitObject_Sphere<T> & ImplicitObject_Sphere<T>::operator= ( ImplicitObject_Sphere<T> const &orig ) 00057 { 00058 m_Name = orig.m_Name; 00059 m_Trx = orig.m_Trx; 00060 m_Radius = orig.m_Radius; 00061 00062 return *this; 00063 } 00064 00065 00066 // Build a BVH tree for this implicit sphere 00067 template <typename T> 00068 void ImplicitObject_Sphere<T>::BuildBVHTree ( int details, Enum::CD treeType ) 00069 { 00070 // m_pBVHTree is inherited from ColDetSupport class 00071 if ( m_pBVHTree ) delete m_pBVHTree; 00072 00073 switch ( treeType ) { 00074 case Enum::BVH_TREE_BINARY_SPHERE: 00075 { 00076 BVHNode<T> * rootNode = new BVHNodeLeaf<T>( Enum::BVH_NODE_LEAF_SPHERE, 0 ); 00077 rootNode->SetCenter( 0, 0, 0 ); 00078 rootNode->SetRadius( m_Radius ); 00079 m_pBVHTree = new BVHTree_BinarySphere<T>( GetTransform(), 1, rootNode ); 00080 } 00081 break; 00082 default: 00083 std::cout << "ImplicitObject_Sphere<T>::BuildBVHTree for Tree Type (" << treeType << ") NOT IMPLEMENTED YET!\n"; 00084 break; 00085 } 00086 } 00087 00088 00089 // Get transformed radius 00090 template <typename T> 00091 T ImplicitObject_Sphere<T>::GetTransformedRadius () const 00092 { 00093 Vector3<T> pt( (m_Trx.RefToMatrixTransform() * Vector4<T>( m_Radius, 0, 0, 1 )).GetVector3() ); 00094 return (pt - GetTransformedCenter()).Length(); 00095 } 00096 00097 00098 //----------------------------------------------------------------------------- 00099 #if defined(__gl_h_) || defined(__GL_H__) 00100 //----------------------------------------------------------------------------- 00101 // Drawn by OpenGL 00102 template <typename T> 00103 void ImplicitObject_Sphere<T>::Draw( GLenum mode, GLint slices, GLint stacks ) 00104 { 00105 #ifdef TAPs_USE_GLSL 00106 //assert( ShaderProgram ); 00107 OpenGL::GlobalGLSLShaderPool::GetShaderProgram( ShaderName )->BeginGLSL(); 00108 OpenGL::GlobalGLSLShaderPool::SetShaderParameters( ShaderName ); 00109 #endif//TAPs_USE_GLSL 00110 00111 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00112 glPushMatrix(); 00113 00114 #ifdef TAPs_SHOW_COLLISION_STATE 00115 static GLfloat color1[] = { 0.75, 0.2, 0.2, 1.0 }; 00116 static GLfloat color2[] = { 0.2, 0.75, 0.2, 1.0 }; 00117 if ( IsCollided ) { 00118 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color1 ); 00119 } 00120 else { 00121 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color2 ); 00122 } 00123 #endif//TAPs_SHOW_COLLISION_STATE 00124 00125 m_Trx.TransformByOpenGLForDrawing(); 00126 switch ( mode ) { 00127 case GL_LINES: 00128 glutWireSphere( m_Radius, slices, stacks ); 00129 break; 00130 default: 00131 glutSolidSphere( m_Radius, slices, stacks ); 00132 break; 00133 } 00134 glPopMatrix(); 00135 glPopAttrib(); 00136 00137 #ifdef TAPs_USE_GLSL 00138 OpenGL::GlobalGLSLShaderPool::GetShaderProgram( ShaderName )->EndGLSL(); 00139 #endif//TAPs_USE_GLSL 00140 } 00141 //----------------------------------------------------------------------------- 00142 #endif // #if defined(__gl_h_) || defined(__GL_H__) 00143 //----------------------------------------------------------------------------- 00144 //============================================================================= 00145 END_NAMESPACE_TAPs 00146 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00147 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----