source: nanovis/trunk/Camera.h @ 6295

Last change on this file since 6295 was 4936, checked in by ldelgass, 10 years ago

whitespace

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright (c) 2004-2013  HUBzero Foundation, LLC
4 *
5 *  Authors:
6 *    Wei Qiao <qiaow@purdue.edu>
7 */
8#ifndef NV_CAMERA_H
9#define NV_CAMERA_H
10
11#include <vrmath/Matrix4x4d.h>
12#include <vrmath/Vector3f.h>
13
14#include "config.h"
15
16namespace nv {
17
18class Camera
19{
20public:
21    enum AxisDirection {
22        X_POS = 1,
23        Y_POS = 2,
24        Z_POS = 3,
25        X_NEG = -1,
26        Y_NEG = -2,
27        Z_NEG = -3
28    };
29
30    Camera(int x, int y, int width, int height);
31
32    ~Camera()
33    {}
34
35    void setUpdir(AxisDirection dir)
36    {
37        setUpDirMatrix(dir);
38        _mvDirty = true;
39    }
40
41    void setPosition(const vrmath::Vector3f& pos)
42    {
43        _position = pos;
44        _mvDirty = true;
45    }
46
47    const vrmath::Vector3f& getPosition() const
48    {
49        return _position;
50    }
51
52    const vrmath::Vector3f& getFocalPoint() const
53    {
54        return _focalPoint;
55    }
56
57    double getDistance() const
58    {
59        return vrmath::Vector3f(_focalPoint - _position).length();
60    }
61
62    vrmath::Vector3f getDirectionOfProjection() const
63    {
64        vrmath::Vector3f dir = _focalPoint - _position;
65        dir = dir.normalize();
66        return dir;
67    }
68
69    vrmath::Vector3f getViewPlaneNormal() const
70    {
71        vrmath::Vector3f dir = _position - _focalPoint;
72        dir = dir.normalize();
73        return dir;
74    }
75
76    void pan(float x, float y, bool absolute = true);
77
78    void zoom(float z, bool absolute = true);
79
80    void orient(double *quat);
81
82    void orient(float angleX, float angleY, float angleZ);
83
84    void setFov(float fov)
85    {
86        _fov = fov;
87    }
88
89    float getFov() const
90    {
91        return _fov;
92    }
93
94    void reset(const vrmath::Vector3f& bboxMin,
95               const vrmath::Vector3f& bboxMax,
96               bool resetOrientation = false);
97
98    void resetClippingRange(const vrmath::Vector3f& bboxMin,
99                            const vrmath::Vector3f& bboxMax);
100
101    void setViewport(int x, int y, int width, int height)
102    {
103        _viewport[0] = x;
104        _viewport[1] = y;
105        _viewport[2] = width;
106        _viewport[3] = height;
107    }
108
109    /**
110     * \brief Make the camera setting active, this has to be
111     * called before drawing things
112     */
113    void initialize();
114
115    void print() const;
116
117    vrmath::Matrix4x4d& getModelViewMatrix()
118    {
119        computeModelViewMatrix();
120        return _modelViewMatrix;
121    }
122
123    void getProjectionMatrix(vrmath::Matrix4x4d& mat);
124
125    const vrmath::Matrix4x4d& getUpDirMatrix() const;
126
127    void windowToWorldCoords(double x, double y, double z, vrmath::Vector3f& objPos);
128
129    void worldToWindowCoords(double x, double y, double z, vrmath::Vector3f& winPos);
130
131private:
132    void computeModelViewMatrix();
133
134    void setUpDirMatrix(AxisDirection dir);
135
136    AxisDirection _updir;
137
138    double _zoomRatio;
139    float _pan[2];
140    /// Position of the camera in the scene
141    vrmath::Vector3f _position;
142    vrmath::Vector3f _focalPoint;
143
144    /// Model transform for z-up scene
145    vrmath::Matrix4x4d _updirMatrix;
146    /// Camera orientation
147    vrmath::Matrix4x4d _rotationMatrix;
148    /// Full camera matrix
149    bool _mvDirty;
150    vrmath::Matrix4x4d _modelViewMatrix;
151
152    /// Field of view (vertical angle in degrees)
153    float _fov;
154    /// Near, far z clipping
155    float _near, _far;
156
157    // x, y, width, height
158    int _viewport[4];
159};
160
161}
162
163#endif
Note: See TracBrowser for help on using the repository browser.