source: trunk/packages/vizservers/nanovis/OrientationIndicator.cpp @ 3884

Last change on this file since 3884 was 3630, checked in by ldelgass, 12 years ago

Nanovis refactoring to fix problems with scaling and multiple results.
Do rendering in world space to properly place and scale multiple data sets.
Also fix flows to reduce resets of animations. More work toward removing
Cg dependency. Fix panning to convert viewport coords to world coords.

  • Property svn:eol-style set to native
File size: 3.4 KB
RevLine 
[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
8#include <GL/glew.h>
9#include <GL/gl.h>
10#include <GL/glu.h>
11
[3630]12#include <vrmath/Vector3f.h>
13
[3605]14#include "OrientationIndicator.h"
15
[3630]16using namespace vrmath;
[3605]17using namespace nv;
18
19OrientationIndicator::OrientationIndicator() :
20    _rep(ARROWS),
21    _visible(true),
22    _lineWidth(1.f),
[3630]23    _quadric(gluNewQuadric()),
24    _position(0,0,0),
25    _scale(1,1,1)
[3605]26{
27}
28
29OrientationIndicator::~OrientationIndicator()
30{
31    gluDeleteQuadric((GLUquadric *)_quadric);
32}
33
34void OrientationIndicator::setRepresentation(Representation rep)
35{
36    _rep = rep;
37}
38
39void OrientationIndicator::render()
40{
41    if (!_visible)
42        return;
43
[3630]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
[3605]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);
[3630]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        }
[3605]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);
[3630]93        glEnable(GL_NORMALIZE);
[3605]94
95        // X
[3630]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();
[3605]102
[3630]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        }
[3605]109
110        // Y
[3630]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();
[3605]117
[3630]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        }
[3605]124
125        // Z
[3630]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();
[3605]131
[3630]132            glPushMatrix();
133            glTranslatef(0., 0., 0.3);
134            gluCylinder(qobj, 0.02, 0.0, 0.06, segments, 1);
135            glPopMatrix();
136        }
[3605]137    }
138        break;
139    default:
140        ;
141    }
142   
143    glPopAttrib();
[3630]144    glPopMatrix();
[3605]145}
Note: See TracBrowser for help on using the repository browser.