-
Notifications
You must be signed in to change notification settings - Fork 429
/
ArcBall.hpp
72 lines (56 loc) · 1.97 KB
/
ArcBall.hpp
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
//
// This code is derived from the well-known, much-copied Arcball class:
// (C) 1999-2003 Tatewake.com
// This code is provided under the license terms from the http://nehe.gamedev.net/
// tutorials/basecode series, which (depending on where you look) is either CC-SA or
// the following:
//
// If you plan to put this program on your web page or a cdrom of
// any sort, let me know via email, I'm curious to see where
// it ends up :)
// If you use the code for your own projects please give me credit,
// or mention my web site somewhere in your program or it's docs.
//
// http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=48
//
#ifndef INCLUDED_PCVIEW_ARCBALL_H
#define INCLUDED_PCVIEW_ARCBALL_H
#include "ArcBallMath.hpp"
class ArcBall : public ArcBallMath
{
public:
ArcBall(GLfloat NewWidth, GLfloat NewHeight);
virtual ~ArcBall() { };
void setBounds(GLfloat NewWidth, GLfloat NewHeight);
// mouse down
void click(const Point2fT* NewPt);
// mouse drag, calculate rotation
void drag(const Point2fT* NewPt, Quat4fT* NewRot);
protected:
void _mapToSphere(const Point2fT* NewPt, Vector3fT* NewVec) const;
Vector3fT StVec; // saved click vector
Vector3fT EnVec; // saved drag vector
GLfloat AdjustWidth; // mouse bounds width
GLfloat AdjustHeight; // mouse bounds height
};
// this class encapsulates all the state-management code thatm using regular ArcBall,
// has to live in the client app
class ArcBallControl : public ArcBall
{
public:
ArcBallControl(int width, int height);
virtual ~ArcBallControl();
void reset();
bool update(int x, int y);
bool changeState(bool isClicked, int x, int y);
const GLfloat* getTransform() const;
private:
void dragAction();
ArcBall::Matrix4fT m_transform;
ArcBall::Matrix3fT m_lastRot;
ArcBall::Matrix3fT m_thisRot;
ArcBall::Point2fT m_mousePt;
bool m_isClicked;
bool m_isDragging;
};
#endif