-
Notifications
You must be signed in to change notification settings - Fork 19
/
TrackBallCamera.cpp
executable file
·75 lines (61 loc) · 1.25 KB
/
TrackBallCamera.cpp
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
#include "TrackBallCamera.h"
TrackBallCamera::TrackBallCamera()
{
m_hold = false;
m_dist = 40.0;
m_xAngle = 0.0;
m_yAngle = 0.0;
m_scrollSens = 0.05;
m_motionSens = 0.15;
}
TrackBallCamera::~TrackBallCamera()
{
}
void TrackBallCamera::look()
{
gluLookAt(0.0, 0.0, m_dist,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
glRotated(m_xAngle, 1.0, 0.0, 0.0);
glRotated(m_yAngle, 0.0, 1.0, 0.0);
}
void TrackBallCamera::onMouseMotion(QMouseEvent *event)
{
if(m_hold)
{
double dx = event->x() - m_lastPos.x();
double dy = event->y() - m_lastPos.y();
m_xAngle += dy*m_motionSens;
m_yAngle += dx*m_motionSens;
m_lastPos = event->pos();
}
return;
}
void TrackBallCamera::onMousePress(QMouseEvent* event)
{
if(!m_hold)
{
m_hold = true;
m_lastPos = event->pos();
}
return;
}
void TrackBallCamera::onMouseRelease(QMouseEvent* event)
{
if(m_hold)
{
m_hold = false;
}
return;
}
void TrackBallCamera::onWheel(QWheelEvent *event)
{
m_dist -= event->angleDelta().y()*m_scrollSens;
if(m_dist < 0.1)
m_dist = 0.1;
return;
}
void TrackBallCamera::onKeyPressed(QEvent *event)
{
return;
}