00001
00002 #include "stage.hh"
00003 #include "worldfile.hh"
00004 using namespace Stg;
00005
00006 Puck::Puck() :
00007 color( color_pack( 1,0,0,0) ),
00008 displaylist( 0 ),
00009 height( 0.2 ),
00010 pose( 0,0,0,0 ),
00011 radius( 0.1 )
00012 { }
00013
00014 void Puck::Load( Worldfile* wf, int section )
00015 {
00016 pose.Load( wf, section, "pose" );
00017
00018
00019 radius = wf->ReadLength( section, "radius", radius );
00020 height = wf->ReadLength( section, "height", height );
00021
00022 BuildDisplayList();
00023 }
00024
00025 void Puck::Save( Worldfile* wf, int section )
00026 {
00027 pose.Save( wf, section, "pose" );
00028
00029
00030 wf->WriteLength( section, "radius", radius );
00031 wf->WriteLength( section, "height", height );
00032 }
00033
00034 void Puck::BuildDisplayList()
00035 {
00036 if( displaylist == 0 )
00037 displaylist = glGenLists(1);
00038
00039 glNewList( displaylist, GL_COMPILE );
00040
00041 GLUquadricObj *q = gluNewQuadric();
00042 glColor3f( 1,0,0 );
00043
00044
00045 glPushMatrix();
00046 glTranslatef( pose.x, pose.y, pose.z );
00047 gluCylinder(q, radius, radius, height, 16, 1 );
00048 glTranslatef( 0,0, height);
00049 gluDisk(q, 0, radius, 16, 16 );
00050 glPopMatrix();
00051
00052
00053 double r,g,b,a;
00054 color_unpack( color, &r, &g, &b, &a );
00055 glColor3f( r/2.0, g/2.0, b/2.0 );
00056
00057 gluQuadricDrawStyle( q, GLU_LINE );
00058 glTranslatef( pose.x, pose.y, pose.z );
00059 gluCylinder(q, radius+0.001, radius+0.001, height+0.001, 16, 1 );
00060
00061
00062 gluDeleteQuadric( q );
00063 glEndList();
00064 }
00065
00066
00067 void Puck::Draw()
00068 {
00069 if( displaylist == 0 )
00070 BuildDisplayList();
00071
00072 glPushMatrix();
00073 glCallList( displaylist );
00074 glPopMatrix();
00075 }