-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera.h
executable file
·79 lines (59 loc) · 1.87 KB
/
camera.h
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
// Arcball camera by Eugene Hsu
// Based on 6.839 sample code for rotation code.
// Extended to handle translation (MIDDLE) and scale (RIGHT)
// -*-c++-*-
#ifndef CAMERA_H
#define CAMERA_H
#ifdef WIN32
#include <windows.h>
#endif
#include <vecmath.h>
class Camera
{
public:
Camera();
typedef enum { NONE, LEFT, MIDDLE, RIGHT } Button;
// You must call all of the Set*() functions before you use this!
// I didn't put it into the constructor because it's inconvenient
// to initialize stuff in my opengl application.
void SetDimensions(int w, int h);
void SetViewport(int x, int y, int w, int h);
void SetPerspective(float fovy);
// Call from whatever UI toolkit
void MouseClick(Button button, int x, int y);
void MouseDrag(int x, int y);
void MouseRelease(int x, int y);
// Apply viewport, perspective, and modeling
// use these instead of
void ApplyViewport() const;
Matrix4f projectionMatrix() const;
Matrix4f viewMatrix() const;
// Set for relevant vars
void SetCenter(const Vector3f& center);
void SetRotation(const Matrix4f& rotation);
void SetDistance(const float distance);
// Get for relevant vars
Vector3f GetCenter() const { return mCurrentCenter; }
Matrix4f GetRotation() const { return mCurrentRot; }
float GetDistance() const { return mCurrentDistance; }
private:
// States
int mDimensions[2];
int mStartClick[2];
Button mButtonState;
// For rotation
Matrix4f mStartRot;
Matrix4f mCurrentRot;
// For translation
float mPerspective[2];
int mViewport[4];
Vector3f mStartCenter;
Vector3f mCurrentCenter;
// For zoom
float mStartDistance;
float mCurrentDistance;
void ArcBallRotation(int x, int y);
void PlaneTranslation(int x, int y);
void DistanceZoom(int x, int y);
};
#endif