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 | #include <GL/glew.h> |
---|
9 | #include <GL/gl.h> |
---|
10 | #include <GL/glu.h> |
---|
11 | |
---|
12 | #include <vrmath/Vector3f.h> |
---|
13 | |
---|
14 | #include "OrientationIndicator.h" |
---|
15 | |
---|
16 | using namespace vrmath; |
---|
17 | using namespace nv; |
---|
18 | |
---|
19 | OrientationIndicator::OrientationIndicator() : |
---|
20 | _rep(ARROWS), |
---|
21 | _visible(true), |
---|
22 | _lineWidth(1.f), |
---|
23 | _quadric(gluNewQuadric()), |
---|
24 | _position(0,0,0), |
---|
25 | _scale(1,1,1) |
---|
26 | { |
---|
27 | } |
---|
28 | |
---|
29 | OrientationIndicator::~OrientationIndicator() |
---|
30 | { |
---|
31 | gluDeleteQuadric((GLUquadric *)_quadric); |
---|
32 | } |
---|
33 | |
---|
34 | void OrientationIndicator::setRepresentation(Representation rep) |
---|
35 | { |
---|
36 | _rep = rep; |
---|
37 | } |
---|
38 | |
---|
39 | void OrientationIndicator::render() |
---|
40 | { |
---|
41 | if (!_visible) |
---|
42 | return; |
---|
43 | |
---|
44 | glMatrixMode(GL_MODELVIEW); |
---|
45 | glPushMatrix(); |
---|
46 | glTranslatef(_position.x, _position.y, _position.z); |
---|
47 | float scale = _scale.x; |
---|
48 | if (scale == 0 || _scale.y < scale) scale = _scale.y; |
---|
49 | if (scale == 0 || _scale.z < scale) scale = _scale.z; |
---|
50 | glScalef(scale, scale, scale); |
---|
51 | |
---|
52 | glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT); |
---|
53 | |
---|
54 | glDisable(GL_TEXTURE_2D); |
---|
55 | glEnable(GL_DEPTH_TEST); |
---|
56 | glEnable(GL_COLOR_MATERIAL); |
---|
57 | glDisable(GL_BLEND); |
---|
58 | |
---|
59 | switch (_rep) { |
---|
60 | case LINES: { |
---|
61 | glLineWidth(_lineWidth); |
---|
62 | glDisable(GL_LIGHTING); |
---|
63 | if (_scale.x > 0) { |
---|
64 | glColor3f(1, 0, 0); |
---|
65 | glBegin(GL_LINES); |
---|
66 | glVertex3f(0, 0, 0); |
---|
67 | glVertex3f(0.5f, 0, 0); |
---|
68 | glEnd(); |
---|
69 | } |
---|
70 | if (_scale.y > 0) { |
---|
71 | glColor3f(0, 1, 0); |
---|
72 | glBegin(GL_LINES); |
---|
73 | glVertex3f(0, 0, 0); |
---|
74 | glVertex3f(0, 0.5f, 0); |
---|
75 | glEnd(); |
---|
76 | } |
---|
77 | if (_scale.z > 0) { |
---|
78 | glColor3f(0, 0, 1); |
---|
79 | glBegin(GL_LINES); |
---|
80 | glVertex3f(0, 0, 0); |
---|
81 | glVertex3f(0, 0, 0.5f); |
---|
82 | glEnd(); |
---|
83 | } |
---|
84 | } |
---|
85 | break; |
---|
86 | case ARROWS: { |
---|
87 | GLUquadric *qobj = (GLUquadric *)_quadric; |
---|
88 | |
---|
89 | int segments = 50; |
---|
90 | |
---|
91 | glEnable(GL_LIGHTING); |
---|
92 | glEnable(GL_LIGHT0); |
---|
93 | glEnable(GL_NORMALIZE); |
---|
94 | |
---|
95 | // X |
---|
96 | if (_scale.x > 0) { |
---|
97 | glColor3f(1, 0, 0); |
---|
98 | glPushMatrix(); |
---|
99 | glRotatef(90, 0, 1, 0); |
---|
100 | gluCylinder(qobj, 0.01, 0.01, 0.3, segments, 1); |
---|
101 | glPopMatrix(); |
---|
102 | |
---|
103 | glPushMatrix(); |
---|
104 | glTranslatef(0.3, 0., 0.); |
---|
105 | glRotatef(90, 0, 1, 0); |
---|
106 | gluCylinder(qobj, 0.02, 0.0, 0.06, segments, 1); |
---|
107 | glPopMatrix(); |
---|
108 | } |
---|
109 | |
---|
110 | // Y |
---|
111 | if (_scale.y > 0) { |
---|
112 | glColor3f(0, 1, 0); |
---|
113 | glPushMatrix(); |
---|
114 | glRotatef(-90, 1, 0, 0); |
---|
115 | gluCylinder(qobj, 0.01, 0.01, 0.3, segments, 1); |
---|
116 | glPopMatrix(); |
---|
117 | |
---|
118 | glPushMatrix(); |
---|
119 | glTranslatef(0., 0.3, 0.); |
---|
120 | glRotatef(-90, 1, 0, 0); |
---|
121 | gluCylinder(qobj, 0.02, 0.0, 0.06, segments, 1); |
---|
122 | glPopMatrix(); |
---|
123 | } |
---|
124 | |
---|
125 | // Z |
---|
126 | if (_scale.z > 0) { |
---|
127 | glColor3f(0, 0, 1); |
---|
128 | glPushMatrix(); |
---|
129 | gluCylinder(qobj, 0.01, 0.01, 0.3, segments, 1); |
---|
130 | glPopMatrix(); |
---|
131 | |
---|
132 | glPushMatrix(); |
---|
133 | glTranslatef(0., 0., 0.3); |
---|
134 | gluCylinder(qobj, 0.02, 0.0, 0.06, segments, 1); |
---|
135 | glPopMatrix(); |
---|
136 | } |
---|
137 | } |
---|
138 | break; |
---|
139 | default: |
---|
140 | ; |
---|
141 | } |
---|
142 | |
---|
143 | glPopAttrib(); |
---|
144 | glPopMatrix(); |
---|
145 | } |
---|