VAPOR3 3.9.4
TrackBall.h
Go to the documentation of this file.
1//************************************************************************
2// *
3// Copyright (C) 2004 *
4// University Corporation for Atmospheric Research *
5// All Rights Reserved *
6// *
7//************************************************************************/
8//
9// File: TrackBall.h
10//
11// Author: Alan Norton
12// National Center for Atmospheric Research
13// PO 3000, Boulder, Colorado
14//
15// Date: July 2004
16//
17// Description: Defines the Trackball class:
18// This was implemented from Ken Purcell's TrackBall
19// methods. Additional methods provided to set the TrackBall
20// based on a viewing frame
21//
22/* Copyright (C) 1992 AHPCRC, Univeristy of Minnesota
23 *
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License, or
27 * (at your option) any later version.
28 *
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
33 *
34 * You should have received a copy of the GNU General Public License
35 * along with this program in a file named 'Copying'; if not, write to
36 * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139.
37 */
38
39/* Author:
40 * Ken Chin-Purcell (ken@ahpcrc.umn.edu)
41 * Army High Performance Computing Research Center (AHPCRC)
42 * Univeristy of Minnesota
43 *
44 */
45
46#ifndef TRACKBALL_H
47#define TRACKBALL_H
48
49#include <vector>
50#include <vapor/common.h>
51
52/* These vector and quaternion macros complement similar
53 * routines.
54 */
55
56/* The Trackball package gives that nice 3D rotation interface.
57 * A TrackBall class is needed for each rotated scene.
58 */
60public:
62 Trackball(float scale[3]);
64 void TrackballFlip(int axis);
68 void TrackballSetPosition(double newx, double newy);
69 void TrackballRotate(double newx, double newy);
70 void TrackballPan(double newx, double newy);
71 void TrackballZoom(double newx, double newy);
73
75
76 void GetCenter(double center[3]) const
77 {
78 for (int i = 0; i < 3; i++) center[i] = _center[i];
79 }
80
81 bool ReconstructCamera(double position[3], double upVec[3], double viewDir[3]) const;
82
83 // Note: button is 1,2,3 for left, middle, right
84 void MouseOnTrackball(int eventType, int thisButton, int xcrd, int ycrd, int width, int height);
85
86 // Initialize the trackball, provide viewer position, direction, upvector,
87 // and the center of rotation (all in trackball coordinate space)
88 //
89 bool setFromFrame(const std::vector<double> &posvec, const std::vector<double> &dirvec, const std::vector<double> &upvec, const std::vector<double> &centerRot, bool perspective);
90
91 bool setFromFrame(const double posvec[3], const double dirvec[3], const double upvec[3], const double centerRot[3], bool perspective)
92 {
93 std::vector<double> pos, dir, up, center;
94 for (int i = 0; i < 3; i++) {
95 pos.push_back(posvec[i]);
96 dir.push_back(dirvec[i]);
97 up.push_back(upvec[i]);
98 center.push_back(centerRot[i]);
99 }
100 return setFromFrame(pos, dir, up, center, perspective);
101 }
102
103 void SetScale(const double scale[3])
104 {
105 _scale[0] = scale[0];
106 _scale[1] = scale[1];
107 _scale[2] = scale[2];
108 }
109
110 double GetOrthoSize() const;
111
112 const double *GetModelViewMatrix() const { return (_modelViewMatrix); }
113
114private:
115 void setCenter(const std::vector<double> &newCenter)
116 {
117 _center[0] = newCenter[0];
118 _center[1] = newCenter[1];
119 _center[2] = newCenter[2];
120 }
121
122 double _qrot[4];
123 double _qinc[4];
124 double _trans[3];
125 double _scale[3];
126 double _center[3];
127 double _ballsize;
128 double _lastx, _lasty;
129 bool _perspective;
130 double _modelViewMatrix[16];
131};
132
133#endif // TRACKBALL_H
double GetOrthoSize() const
void MouseOnTrackball(int eventType, int thisButton, int xcrd, int ycrd, int width, int height)
void TrackballPan(double newx, double newy)
const double * GetModelViewMatrix() const
Definition: TrackBall.h:112
void TrackballSetPosition(double newx, double newy)
void SetScale(const double scale[3])
Definition: TrackBall.h:103
void TrackballSpin()
Trackball(float scale[3])
void TrackballStopSpinning()
void GetCenter(double center[3]) const
Definition: TrackBall.h:76
void TrackballCopyTo(Trackball *dst)
void TrackballRotate(double newx, double newy)
int TrackballSpinning()
void TrackballSetMatrix()
void TrackballZoom(double newx, double newy)
void TrackballFlip(int axis)
bool setFromFrame(const double posvec[3], const double dirvec[3], const double upvec[3], const double centerRot[3], bool perspective)
Definition: TrackBall.h:91
bool ReconstructCamera(double position[3], double upVec[3], double viewDir[3]) const
void TrackballReset()
bool setFromFrame(const std::vector< double > &posvec, const std::vector< double > &dirvec, const std::vector< double > &upvec, const std::vector< double > &centerRot, bool perspective)
#define RENDER_API
Definition: common.h:78