CoordinateAxes.cpp
Go to the documentation of this file.
1 
28  /*
29  * CoordinateAxes.cpp
30  *
31  * Created on: 27.08.2008
32  * Author: Thomas Wiemann
33  */
34 
36 
37 namespace lvr2
38 {
39 
40 CoordinateAxes::CoordinateAxes() : Renderable("Coordinate System"){
41  drawAxes(100);
42 }
43 
44 CoordinateAxes::CoordinateAxes(float length): Renderable("Coordinate System"){
45  drawAxes(length);
46 }
47 
49 
50 }
51 
52 void CoordinateAxes::drawAxes(float length){
53  m_listIndex = glGenLists(1);
54  glNewList(m_listIndex, GL_COMPILE);
55  glPushAttrib ( GL_ALL_ATTRIB_BITS ); // save colors and polygon offsets state to later restore.
56  const float charWidth = length / 40.0f;
57  const float charHeight = length / 30.0f;
58  const float charShift = 1.04f * length;
59 
60  glDisable ( GL_LIGHTING );
61  glLineWidth ( 2.0f );
62 
63  glBegin ( GL_LINES );
64  // The X
65  glVertex3f ( charShift, charWidth, -charHeight );
66  glVertex3f ( charShift, -charWidth, charHeight );
67  glVertex3f ( charShift, -charWidth, -charHeight );
68  glVertex3f ( charShift, charWidth, charHeight );
69  // The Y
70  glVertex3f ( charWidth, charShift, charHeight );
71  glVertex3f ( 0.0, charShift, 0.0 );
72  glVertex3f ( -charWidth, charShift, charHeight );
73  glVertex3f ( 0.0, charShift, 0.0 );
74  glVertex3f ( 0.0, charShift, 0.0 );
75  glVertex3f ( 0.0, charShift, -charHeight );
76  // The Z
77  glVertex3f ( -charWidth, charHeight, charShift );
78  glVertex3f ( charWidth, charHeight, charShift );
79  glVertex3f ( charWidth, charHeight, charShift );
80  glVertex3f ( -charWidth, -charHeight, charShift );
81  glVertex3f ( -charWidth, -charHeight, charShift );
82  glVertex3f ( charWidth, -charHeight, charShift );
83  glEnd();
84 
85  glEnable ( GL_LIGHTING );
86  glDisable ( GL_COLOR_MATERIAL );
87 
88  float color[4];
89  color[0] = 0.7f;
90  color[1] = 0.7f;
91  color[2] = 1.0f;
92  color[3] = 1.0f;
93  glMaterialfv ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color );
94  drawArrow ( length, 0.01f *length );
95 
96  color[0] = 1.0f;
97  color[1] = 0.7f;
98  color[2] = 0.7f;
99  color[3] = 1.0f;
100  glMaterialfv ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color );
101  glPushMatrix();
102  glRotatef ( 90.0f, 0.0f, 1.0f, 0.0f );
103  drawArrow ( length, 0.01f * length );
104  glPopMatrix();
105 
106  color[0] = 0.7f;
107  color[1] = 1.0f;
108  color[2] = 0.7f;
109  color[3] = 1.0f;
110  glMaterialfv ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color );
111  glPushMatrix();
112  glRotatef ( -90.0f, 1.0f, 0.0f, 0.0f );
113  drawArrow ( length, 0.01f * length );
114  glPopMatrix();
115 
116  glPopAttrib();
117  glEndList();
118 }
119 
120 void CoordinateAxes::drawArrow ( float length, float radius, int nbSubdivisions )
121 {
122  GLUquadric* quadric = gluNewQuadric();
123 
124  if ( radius < 0.0f )
125  radius = 0.05f * length;
126 
127  const float head = 2.5f * ( radius / length ) + 0.1f;
128  const float coneRadiusCoef = 4.0f - 5.0f * head;
129 
130  gluCylinder ( quadric, radius, radius, length * ( 1.0f - head/coneRadiusCoef ), nbSubdivisions, 1 );
131  glTranslatef ( 0.0f , 0.0f, length * ( 1.0f - head ) );
132  gluCylinder ( quadric, coneRadiusCoef * radius, 0.0, head * length, nbSubdivisions, 1 );
133  glTranslatef ( 0.0f, 0.0f, -length * ( 1.0f - head ) );
134  gluDeleteQuadric ( quadric );
135 }
136 
138  if (m_visible){
139  glPushMatrix();
140  glScalef(10.0, 10.0, 10.0);
141  glCallList(m_listIndex);
142  glPopMatrix();
143  }
144 }
145 
147 
148 }
149 
150 } // namespace lvr2
lvr2::Renderable::m_visible
bool m_visible
Definition: Renderable.hpp:142
CoordinateAxes.hpp
lvr2::Matrix4
A 4x4 matrix class implementation for use with the provided vertex types.
Definition: Matrix4.hpp:64
lvr2::color
Definition: DataStruct.hpp:81
lvr2::CoordinateAxes::~CoordinateAxes
virtual ~CoordinateAxes()
Definition: CoordinateAxes.cpp:48
lvr2::CoordinateAxes::render
virtual void render()
Definition: CoordinateAxes.cpp:137
lvr2::CoordinateAxes::drawArrow
void drawArrow(float length, float radius, int nSubdivs=12)
Definition: CoordinateAxes.cpp:120
lvr2::Renderable
Definition: Renderable.hpp:65
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::Renderable::m_listIndex
int m_listIndex
Definition: Renderable.hpp:148
lvr2::Renderable::transform
virtual void transform()
Definition: Renderable.cpp:373
lvr2::CoordinateAxes::drawAxes
void drawAxes(float length)
Definition: CoordinateAxes.cpp:52
lvr2::CoordinateAxes::CoordinateAxes
CoordinateAxes()
Definition: CoordinateAxes.cpp:40


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:23