puck.cc
Go to the documentation of this file.
1 
2 #include "stage.hh"
3 #include "worldfile.hh"
4 using namespace Stg;
5 
6 Puck::Puck()
7  : color(color_pack(1, 0, 0, 0)), displaylist(0), height(0.2), pose(0, 0, 0, 0), radius(0.1)
8 { /* empty */
9 }
10 
11 void Puck::Load(Worldfile *wf, int section)
12 {
13  pose.Load(wf, section, "pose");
14  // color.Load( wf, section, "color" );
15 
16  radius = wf->ReadLength(section, "radius", radius);
17  height = wf->ReadLength(section, "height", height);
18 
19  BuildDisplayList();
20 }
21 
22 void Puck::Save(Worldfile *wf, int section)
23 {
24  pose.Save(wf, section, "pose");
25  // color.Save( wf, section, "color" );
26 
27  wf->WriteLength(section, "radius", radius);
28  wf->WriteLength(section, "height", height);
29 }
30 
31 void Puck::BuildDisplayList()
32 {
33  if (displaylist == 0)
34  displaylist = glGenLists(1);
35 
36  glNewList(displaylist, GL_COMPILE);
37 
38  GLUquadricObj *q = gluNewQuadric();
39  glColor3f(1, 0, 0);
40 
41  // draw a filled body
42  glPushMatrix();
43  glTranslatef(pose.x, pose.y, pose.z);
44  gluCylinder(q, radius, radius, height, 16, 1);
45  glTranslatef(0, 0, height);
46  gluDisk(q, 0, radius, 16, 16);
47  glPopMatrix();
48 
49  // outline the sides in a darker shade
50  double r, g, b, a;
51  color_unpack(color, &r, &g, &b, &a);
52  glColor3f(r / 2.0, g / 2.0, b / 2.0);
53 
54  gluQuadricDrawStyle(q, GLU_LINE);
55  glTranslatef(pose.x, pose.y, pose.z);
56  gluCylinder(q, radius + 0.001, radius + 0.001, height + 0.001, 16, 1);
57 
58  // clean up
59  gluDeleteQuadric(q);
60  glEndList();
61 }
62 
63 void Puck::Draw()
64 {
65  if (displaylist == 0)
66  BuildDisplayList();
67 
68  glPushMatrix();
69  glCallList(displaylist);
70  glPopMatrix();
71 }
The Stage library uses its own namespace.
Definition: canvas.hh:8
double ReadLength(int entity, const char *name, double value)
Definition: worldfile.hh:124
void WriteLength(int entity, const char *name, double value)


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Mon Feb 28 2022 23:48:56