Line | |
---|
1 | #include ".\thirdpersoncamera.h"
|
---|
2 |
|
---|
3 | ThirdPersonCamera::ThirdPersonCamera(void)
|
---|
4 | {
|
---|
5 | rot=0;
|
---|
6 | yaw=0;
|
---|
7 | dist=1;
|
---|
8 | m_LookAt=Vector(0.5,0,0);
|
---|
9 | }
|
---|
10 |
|
---|
11 | ThirdPersonCamera::~ThirdPersonCamera(void)
|
---|
12 | {
|
---|
13 | }
|
---|
14 | void ThirdPersonCamera::setViewforBbox()
|
---|
15 | {
|
---|
16 | glMatrixMode(GL_MODELVIEW);
|
---|
17 | glLoadIdentity();
|
---|
18 |
|
---|
19 | gluLookAt(0,0,0,-m_EyePosition.x,
|
---|
20 | -m_EyePosition.y,
|
---|
21 | -m_EyePosition.z,
|
---|
22 | m_UpVector.x,
|
---|
23 | m_UpVector.y,
|
---|
24 | m_UpVector.z);
|
---|
25 |
|
---|
26 | }
|
---|
27 |
|
---|
28 | void ThirdPersonCamera::SetViewandProjection(void)
|
---|
29 | {
|
---|
30 | glMatrixMode(GL_PROJECTION);
|
---|
31 | glLoadIdentity();
|
---|
32 | gluPerspective(m_FovY,m_AspectRatio,m_NearClipDistance,m_FarClipDistance);
|
---|
33 |
|
---|
34 | glMatrixMode(GL_MODELVIEW);
|
---|
35 | glLoadIdentity();
|
---|
36 |
|
---|
37 | gluLookAt(m_EyePosition.x,
|
---|
38 | m_EyePosition.y,
|
---|
39 | m_EyePosition.z,
|
---|
40 | m_LookAt.x,
|
---|
41 | m_LookAt.y,
|
---|
42 | m_LookAt.z,
|
---|
43 | m_UpVector.x,
|
---|
44 | m_UpVector.y,
|
---|
45 | m_UpVector.z);
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 | }
|
---|
50 |
|
---|
51 | void ThirdPersonCamera::Move(Axis axis, double distance)
|
---|
52 | {
|
---|
53 | switch (axis)
|
---|
54 | {
|
---|
55 | case AXIS_X:
|
---|
56 | rot+=distance*3.14/40.0;
|
---|
57 | break;
|
---|
58 | case AXIS_Y:
|
---|
59 | yaw+=distance*3.14/40.0;
|
---|
60 | break;
|
---|
61 | case AXIS_Z:
|
---|
62 | dist-=distance;
|
---|
63 | break;
|
---|
64 | }
|
---|
65 | Vector dir(cos(rot)*cos(yaw),sin(yaw),sin(rot)*cos(yaw));
|
---|
66 | dir=dir*dist;
|
---|
67 | m_EyePosition=m_LookAt+dir;
|
---|
68 | m_Orientation.y=rot/3.14*180.0;
|
---|
69 | m_Orientation.x=-yaw/3.14*180.0;
|
---|
70 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.