1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | /* |
---|
3 | * Copyright (c) 2004-2013 HUBzero Foundation, LLC |
---|
4 | * |
---|
5 | * Author: Leif Delgass <ldelgass@purdue.edu> |
---|
6 | */ |
---|
7 | |
---|
8 | #define USE_GLUT |
---|
9 | |
---|
10 | #include <GL/glew.h> |
---|
11 | #include <GL/gl.h> |
---|
12 | #include <GL/glu.h> |
---|
13 | #ifdef USE_GLUT |
---|
14 | #include <GL/glut.h> |
---|
15 | #endif |
---|
16 | |
---|
17 | #include <vrmath/Vector3f.h> |
---|
18 | |
---|
19 | #include "OrientationIndicator.h" |
---|
20 | |
---|
21 | using namespace vrmath; |
---|
22 | using namespace nv; |
---|
23 | |
---|
24 | OrientationIndicator::OrientationIndicator() : |
---|
25 | _rep(ARROWS), |
---|
26 | _visible(true), |
---|
27 | _lineWidth(1.f), |
---|
28 | _quadric(gluNewQuadric()), |
---|
29 | _position(0,0,0), |
---|
30 | _scale(1,1,1) |
---|
31 | { |
---|
32 | } |
---|
33 | |
---|
34 | OrientationIndicator::~OrientationIndicator() |
---|
35 | { |
---|
36 | gluDeleteQuadric((GLUquadric *)_quadric); |
---|
37 | } |
---|
38 | |
---|
39 | void OrientationIndicator::setRepresentation(Representation rep) |
---|
40 | { |
---|
41 | _rep = rep; |
---|
42 | } |
---|
43 | |
---|
44 | void OrientationIndicator::render() |
---|
45 | { |
---|
46 | if (!_visible) |
---|
47 | return; |
---|
48 | |
---|
49 | glMatrixMode(GL_MODELVIEW); |
---|
50 | glPushMatrix(); |
---|
51 | glTranslatef(_position.x, _position.y, _position.z); |
---|
52 | float scale = _scale.x; |
---|
53 | if (scale == 0 || _scale.y < scale) scale = _scale.y; |
---|
54 | if (scale == 0 || _scale.z < scale) scale = _scale.z; |
---|
55 | glScalef(scale, scale, scale); |
---|
56 | |
---|
57 | glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT); |
---|
58 | |
---|
59 | glDisable(GL_TEXTURE_2D); |
---|
60 | glEnable(GL_DEPTH_TEST); |
---|
61 | glEnable(GL_COLOR_MATERIAL); |
---|
62 | glDisable(GL_BLEND); |
---|
63 | |
---|
64 | switch (_rep) { |
---|
65 | case LINES: { |
---|
66 | glLineWidth(_lineWidth); |
---|
67 | glDisable(GL_LIGHTING); |
---|
68 | if (_scale.x > 0) { |
---|
69 | glColor3f(1, 0, 0); |
---|
70 | glBegin(GL_LINES); |
---|
71 | glVertex3f(0, 0, 0); |
---|
72 | glVertex3f(0.5f, 0, 0); |
---|
73 | glEnd(); |
---|
74 | } |
---|
75 | if (_scale.y > 0) { |
---|
76 | glColor3f(0, 1, 0); |
---|
77 | glBegin(GL_LINES); |
---|
78 | glVertex3f(0, 0, 0); |
---|
79 | glVertex3f(0, 0.5f, 0); |
---|
80 | glEnd(); |
---|
81 | } |
---|
82 | if (_scale.z > 0) { |
---|
83 | glColor3f(0, 0, 1); |
---|
84 | glBegin(GL_LINES); |
---|
85 | glVertex3f(0, 0, 0); |
---|
86 | glVertex3f(0, 0, 0.5f); |
---|
87 | glEnd(); |
---|
88 | } |
---|
89 | } |
---|
90 | break; |
---|
91 | case ARROWS: { |
---|
92 | GLUquadric *qobj = (GLUquadric *)_quadric; |
---|
93 | |
---|
94 | int segments = 50; |
---|
95 | |
---|
96 | glEnable(GL_LIGHTING); |
---|
97 | glEnable(GL_LIGHT0); |
---|
98 | glEnable(GL_NORMALIZE); |
---|
99 | |
---|
100 | // X |
---|
101 | if (_scale.x > 0) { |
---|
102 | glColor3f(1, 0, 0); |
---|
103 | glPushMatrix(); |
---|
104 | glRotatef(90, 0, 1, 0); |
---|
105 | gluCylinder(qobj, 0.01, 0.01, 0.3, segments, 1); |
---|
106 | glPopMatrix(); |
---|
107 | |
---|
108 | glPushMatrix(); |
---|
109 | glTranslatef(0.3, 0., 0.); |
---|
110 | glRotatef(90, 0, 1, 0); |
---|
111 | gluCylinder(qobj, 0.02, 0.0, 0.06, segments, 1); |
---|
112 | glPopMatrix(); |
---|
113 | |
---|
114 | #ifdef USE_GLUT |
---|
115 | glDisable(GL_LIGHTING); |
---|
116 | glPushMatrix(); |
---|
117 | glTranslatef(0.4, 0., 0.); |
---|
118 | glRotatef(90, 1, 0, 0); |
---|
119 | glRotatef(180, 0, 1, 0); |
---|
120 | glScalef(0.0005, 0.0005, 0.0005); |
---|
121 | glutStrokeCharacter(GLUT_STROKE_ROMAN, 'x'); |
---|
122 | glPopMatrix(); |
---|
123 | glEnable(GL_LIGHTING); |
---|
124 | #endif |
---|
125 | } |
---|
126 | |
---|
127 | // Y |
---|
128 | if (_scale.y > 0) { |
---|
129 | glColor3f(0, 1, 0); |
---|
130 | glPushMatrix(); |
---|
131 | glRotatef(-90, 1, 0, 0); |
---|
132 | gluCylinder(qobj, 0.01, 0.01, 0.3, segments, 1); |
---|
133 | glPopMatrix(); |
---|
134 | |
---|
135 | glPushMatrix(); |
---|
136 | glTranslatef(0., 0.3, 0.); |
---|
137 | glRotatef(-90, 1, 0, 0); |
---|
138 | gluCylinder(qobj, 0.02, 0.0, 0.06, segments, 1); |
---|
139 | glPopMatrix(); |
---|
140 | |
---|
141 | #ifdef USE_GLUT |
---|
142 | glDisable(GL_LIGHTING); |
---|
143 | glPushMatrix(); |
---|
144 | glTranslatef(0., 0.4, 0.); |
---|
145 | glRotatef(90, 1, 0, 0); |
---|
146 | glRotatef(180, 0, 1, 0); |
---|
147 | glScalef(0.0005, 0.0005, 0.0005); |
---|
148 | glutStrokeCharacter(GLUT_STROKE_ROMAN, 'y'); |
---|
149 | glPopMatrix(); |
---|
150 | glEnable(GL_LIGHTING); |
---|
151 | #endif |
---|
152 | } |
---|
153 | |
---|
154 | // Z |
---|
155 | if (_scale.z > 0) { |
---|
156 | glColor3f(0, 0, 1); |
---|
157 | glPushMatrix(); |
---|
158 | gluCylinder(qobj, 0.01, 0.01, 0.3, segments, 1); |
---|
159 | glPopMatrix(); |
---|
160 | |
---|
161 | glPushMatrix(); |
---|
162 | glTranslatef(0., 0., 0.3); |
---|
163 | gluCylinder(qobj, 0.02, 0.0, 0.06, segments, 1); |
---|
164 | glPopMatrix(); |
---|
165 | |
---|
166 | #ifdef USE_GLUT |
---|
167 | glDisable(GL_LIGHTING); |
---|
168 | glPushMatrix(); |
---|
169 | glTranslatef(0., 0., 0.4); |
---|
170 | glRotatef(90, 1, 0, 0); |
---|
171 | glRotatef(180, 0, 1, 0); |
---|
172 | glScalef(0.0005, 0.0005, 0.0005); |
---|
173 | glutStrokeCharacter(GLUT_STROKE_ROMAN, 'z'); |
---|
174 | glPopMatrix(); |
---|
175 | glEnable(GL_LIGHTING); |
---|
176 | #endif |
---|
177 | } |
---|
178 | } |
---|
179 | break; |
---|
180 | default: |
---|
181 | ; |
---|
182 | } |
---|
183 | |
---|
184 | glPopAttrib(); |
---|
185 | glPopMatrix(); |
---|
186 | } |
---|