[3605] | 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 | |
---|
[5523] | 8 | #define USE_GLUT |
---|
| 9 | |
---|
[3605] | 10 | #include <GL/glew.h> |
---|
| 11 | #include <GL/gl.h> |
---|
| 12 | #include <GL/glu.h> |
---|
[5523] | 13 | #ifdef USE_GLUT |
---|
| 14 | #include <GL/glut.h> |
---|
| 15 | #endif |
---|
[3605] | 16 | |
---|
[5516] | 17 | #include <vrmath/Vector3f.h> |
---|
| 18 | |
---|
[3605] | 19 | #include "OrientationIndicator.h" |
---|
| 20 | |
---|
[5516] | 21 | using namespace vrmath; |
---|
[3605] | 22 | using namespace nv; |
---|
| 23 | |
---|
| 24 | OrientationIndicator::OrientationIndicator() : |
---|
| 25 | _rep(ARROWS), |
---|
| 26 | _visible(true), |
---|
| 27 | _lineWidth(1.f), |
---|
[5516] | 28 | _quadric(gluNewQuadric()), |
---|
| 29 | _position(0,0,0), |
---|
| 30 | _scale(1,1,1) |
---|
[3605] | 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 | |
---|
[5516] | 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 | |
---|
[3605] | 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); |
---|
[5516] | 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 | } |
---|
[3605] | 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); |
---|
[5516] | 98 | glEnable(GL_NORMALIZE); |
---|
[3605] | 99 | |
---|
| 100 | // X |
---|
[5516] | 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(); |
---|
[3605] | 107 | |
---|
[5516] | 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(); |
---|
[5523] | 113 | |
---|
| 114 | #ifdef USE_GLUT |
---|
| 115 | glDisable(GL_LIGHTING); |
---|
| 116 | glPushMatrix(); |
---|
| 117 | glTranslatef(0.4, 0., 0.); |
---|
[5524] | 118 | glRotatef(90, 1, 0, 0); |
---|
[5523] | 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 |
---|
[5516] | 125 | } |
---|
[3605] | 126 | |
---|
| 127 | // Y |
---|
[5516] | 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(); |
---|
[3605] | 134 | |
---|
[5516] | 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(); |
---|
[5523] | 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 |
---|
[5516] | 152 | } |
---|
[3605] | 153 | |
---|
| 154 | // Z |
---|
[5516] | 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(); |
---|
[3605] | 160 | |
---|
[5516] | 161 | glPushMatrix(); |
---|
| 162 | glTranslatef(0., 0., 0.3); |
---|
| 163 | gluCylinder(qobj, 0.02, 0.0, 0.06, segments, 1); |
---|
| 164 | glPopMatrix(); |
---|
[5523] | 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 |
---|
[5516] | 177 | } |
---|
[3605] | 178 | } |
---|
| 179 | break; |
---|
| 180 | default: |
---|
| 181 | ; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | glPopAttrib(); |
---|
[5516] | 185 | glPopMatrix(); |
---|
[3605] | 186 | } |
---|