-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCameraModel.h
More file actions
167 lines (134 loc) · 5.94 KB
/
Copy pathCameraModel.h
File metadata and controls
167 lines (134 loc) · 5.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#ifndef CAMERAMODEL_H
#define CAMERAMODEL_H
#include <iostream>
#include <sstream>
#include <QObject>
#include <osg/Object>
#include <osg/Node>
#include <osgUtil/LineSegmentIntersector>
class CameraModel : public QObject, public osg::Object
{
Q_OBJECT
public:
explicit CameraModel(QObject *parent = 0);
CameraModel( const CameraModel& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY );
META_Object(osgwTools,CameraModel)
// simple accessors ///////////////////////////////////////////////////////
osg::Vec3d viewUp() const { return m_viewUp; }
osg::Vec3d viewDir() const { return m_viewDir; }
osg::Vec3d viewCenter() const { return m_viewCenter; }
double fovY() const { return m_fovY; }
double viewDistance() const { return m_viewDistance; }
double aspect() const { return m_aspect; }
double trackballRollSensitivity() const { return m_trackballRollSensitivity; }
bool isOrtho() const { return m_ortho; }
double orthoTop() const { return m_orthoTop; }
double orthoBottom() const { return m_orthoBottom; }
bool viewChangeInProgress() const { return m_viewChangeInProgress; }
bool dollyCanChangeCenter() const { return m_dollyCanChangeCenter; }
int dollyCenterChangeThreshold() const { return m_dollyCenterChangeThreshold; }
int dollyCenterPressure() const { return m_dollyCurrentPressure; }
unsigned cullMask() const { return m_cullMask; }
// derive other representations of member variables ////////////////////
osg::Matrixd computeProjection() const;
osg::Matrixd getModelViewMatrix() const;
osg::Matrixd getMatrix() const;
osg::Vec3d getEyePosition() const;
double getFovyRadians() const;
osg::Vec3d getAzElTwist() const;
osg::Vec3d getYawPitchRoll() const;
signals:
void changed();
void cullMaskChanged(unsigned);
public slots:
void computeInitialView();
void fitToScreen();
void setUpAndDir(osg::Vec3d up, osg::Vec3d dir);
void setViewUp(osg::Vec3d v);
void setViewDir(osg::Vec3d v);
void setViewCenter(osg::Vec3d newCenter);
void setFovY(double fov) { m_fovY = fov; emit changed(); }
void setViewDistance(double distance);
void setEyePosition(osg::Vec3d p);
void setAspect(double a);
void setOrtho(bool tf);
void fovYScaleUp();
void fovYScaleDown();
void setClampFovyScale(bool clamp, osg::Vec2d range);
void setViewDirFromAzEl(osg::Vec2d aet);
void saveView(std::stringstream &stream);
void loadView(std::stringstream &stream);
void setTrackballRollSensitivity(double s) { m_trackballRollSensitivity=s; }
void setOrthoFromQAction();
void stashView();
void restoreView();
// Manipulation operations ///////////////////////////////////////////////
void startOrbit(osg::Vec2d startingNDC);
void orbit(osg::Vec2d currentNDC);
void finishOrbit(osg::Vec2d currentNDC);
void finishOrbit() {finishOrbit(m_startingNDC);}
void startRotate(osg::Vec2d startingNDC);
void rotate(osg::Vec2d currentNDC);
void finishRotate(osg::Vec2d currentNDC);
void finishRotate() { finishRotate(m_startingNDC); }
void startPan(osg::Vec2d startingNDC, osg::Vec4d panPlane);
void pan(osg::Vec2d currentNDC);
void finishPan(osg::Vec2d currentNDC);
void finishPan() { finishPan(m_startingNDC); }
void startZoom(osg::Vec2d startingNDC);
void zoom(osg::Vec2d currentNDC);
void finishZoom(osg::Vec2d currentNDC);
void finishZoom() { finishZoom(m_startingNDC); }
/** Dolly the camera forwards and backwards. Changes the view distance.
This function is a no-op for orthographic projections. */
void startDolly(osg::Vec2d startingNDC);
void dolly( const double deltaMovement );
void dolly(osg::Vec2d currentNDC);
void finishDolly(osg::Vec2d currentNDC);
void finishDolly() { finishDolly(m_startingNDC); }
void setDollyCanChangeCenter(bool tf) { m_dollyCanChangeCenter = tf; emit changed(); }
void setDollyCenterChangeThreshold(int threshold) { m_dollyCenterChangeThreshold = threshold; emit changed(); }
void setCullMask(unsigned mask) { m_cullMask = mask; emit cullMaskChanged(m_cullMask); }
void setCullMaskBits(unsigned mask) { setCullMask(m_cullMask | mask); }
void clearCullMaskBits(unsigned mask) { setCullMask(m_cullMask & ~mask); }
void setBoundingNode( osg::ref_ptr< osg::Node > boundNode) { m_boundingNode = boundNode; emit changed(); }
private:
void applyViewChangeMatrix();
/// Assure m_viewUp and m_viewDir are orthogonal
inline void orthoNormalize();
bool intersectPlaneRay(osg::Vec3d &result, const osg::Vec4d &plane, const osg::Vec3d &p0, const osg::Vec3d &p1);
void getZNearZFarProj(double &zNear, double &zFar, const osg::Matrixd &projMat);
osg::Matrixd getOrientationMatrix() const;
// Data /////////////////////////////////////////
// basic camera parameters
osg::Vec3d m_viewUp;
osg::Vec3d m_viewDir;
osg::Vec3d m_viewCenter;
double m_fovY;
double m_viewDistance;
// Projection matrix support
double m_aspect;
bool m_ortho;
double m_orthoBottom;
double m_orthoTop;
// manipulation parameters
double m_fovYScaleFactor;
osg::Vec2d m_clampFovyRange;
bool m_shouldClampFovYScale;
double m_trackballRollSensitivity;
bool m_dollyCanChangeCenter;
int m_dollyCenterChangeThreshold;
int m_dollyCurrentPressure;
osg::Vec4d m_panPlane;
bool m_viewChangeInProgress; // is the user in the process of adjusting the view
osg::Matrixd m_viewChangeMatrix; // matrix representing the change thus far
osg::Vec2d m_startingNDC; // NDC where view change began
// node for doing scene bound computation.
// This is necesary for fitToScreen() because nodes such as OriginAxis
// have AutoTransform nodes which skew the bounding box based upon the
// results of the last draw.
osg::ref_ptr< osg::Node > m_boundingNode;
std::string m_stashedView;
unsigned m_cullMask;
};
#endif // CAMERACONTROL_H