00001 #pragma warning ( disable : 4786 )
00002
00003 #include "math/math2.h"
00004 #include "IGS_Controller.h"
00005 #include "IGS_Circle.h"
00006 #include "math/Matrix4x4.h"
00007 #include "math.h"
00008 #include "opengl/glos.h"
00009 #include <gl/gl.h>
00010
00011
00012 std::map< double, IGS_Circle::VertexList > IGS_Circle::g_VertexLists;
00013
00014
00015
00016
00017
00018
00019 IGS_Circle::IGS_Circle()
00020 :
00021 Circle( 0.1 ),
00022 m_VertexList( NULL ),
00023 m_RenderFilled( false )
00024 {
00025 }
00026
00027
00028
00029
00030
00031
00032 IGS_Circle::IGS_Circle( const double radius )
00033 :
00034 Circle( radius ),
00035 m_VertexList( NULL )
00036 {
00037 }
00038
00039
00040
00041
00042
00043
00044
00045 void IGS_Circle::Prepare( const IGS_Controller& controller )
00046 {
00047 if( this->PreparationComplete() )
00048 {
00049 return;
00050 }
00051
00052
00053 std::map< double, VertexList >::iterator it = g_VertexLists.find( m_Radius );
00054 if( it != g_VertexLists.end() )
00055 {
00056 IGS_Object::Prepare( controller );
00057 this->m_VertexList = &( *it ).second;
00058 return;
00059 }
00060
00061
00062 VertexList vertexList;
00063
00064
00065 int i;
00066 const int steps = 33 - 1;
00067 for( i = 0; i < steps; i++ )
00068 {
00069 double theta = M_PI * 2 * i / steps;
00070 double x = ::sin( theta ) * m_Radius;
00071 double y = ::cos( theta ) * m_Radius;
00072 vertexList.vertices[ i ][ 0 ] = x;
00073 vertexList.vertices[ i ][ 1 ] = y;
00074 vertexList.vertices[ i ][ 2 ] = 0;
00075 }
00076
00077 double theta = M_PI * 2 * 0 / steps;
00078 double x = ::sin( theta ) * m_Radius;
00079 double y = ::cos( theta ) * m_Radius;
00080 vertexList.vertices[ 32 ][ 0 ] = x;
00081 vertexList.vertices[ 32 ][ 1 ] = y;
00082 vertexList.vertices[ 32 ][ 2 ] = 0;
00083 g_VertexLists.insert( std::map< double, VertexList >::value_type( m_Radius, vertexList ) );
00084
00085
00086 this->Prepare( controller );
00087 }
00088
00089
00090
00091
00092
00093
00094 double IGS_Circle::Radius() const
00095 {
00096 return this->m_Radius;
00097 }
00098
00099
00100
00101
00102
00103
00104 void IGS_Circle::Render( const IGS_Controller& controller ) const
00105 {
00106 ::CheckGlErrorCode();
00107 glPushMatrix();
00108 ::CheckGlErrorCode();
00109 glTranslatef( m_Center[ 0 ], m_Center[ 1 ], 0.0 );
00110 ::CheckGlErrorCode();
00111
00112
00113 if( m_VertexList == NULL )
00114 {
00115 IJG_Assert( m_VertexList != NULL );
00116 return;
00117 }
00118 if( m_RenderFilled )
00119 {
00120 ::glBegin( GL_TRIANGLE_FAN );
00121 }
00122 else
00123 {
00124 ::glBegin( GL_LINE_STRIP );
00125 }
00126 int i;
00127 for( i = 0; i < 33; i++ )
00128 {
00129 ::glVertex3dv( m_VertexList->vertices[ i ] );
00130 }
00131
00132 ::glEnd();
00133
00134 ::CheckGlErrorCode();
00135 glPopMatrix();
00136 }
00137
00138
00139
00140
00141
00142
00143 void IGS_Circle::SetCenter( const Vector2& center )
00144 {
00145 Circle::SetCenter( center );
00146 }
00147
00148
00149
00150
00151
00152
00153
00154 void IGS_Circle::SetRenderFilled( const bool filled )
00155 {
00156 m_RenderFilled = true;
00157 }