summaryrefslogtreecommitdiff
path: root/src/gui/Camera.cc
blob: 65c80b77f549d8fbb13094a5e150b842a15e6acf (plain) (blame)
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
/*
 * Camera.cc
 *
 *  Created on: Mar 31, 2011
 *      Author: jakob
 */

#include "Camera.h"

namespace vhc {

Camera::Camera(): position(1, 1, 1), direction(-1, 0, 0), up(0,0,1), heading(M_PI_4), pitch(-M_PI_4) {};

Camera::~Camera();

void Camera::setView() {
	Vector3D td = direction.rotate(Vector3D::j, pitch).rotate(Vector3D::k, heading);; //tranformed direction
	Vector3D at = position + td;

	gluLookAt(position.getX(), position.getY(), position.getZ(),
			at.getX(), at.getY(), at.getZ(),
			up.getX(), up.getY(), up.getZ());
}

void Camera::addHeading(double h) {
	heading += h;
}

void Camera::addPitch(double h) {
	pitch += h;
	if (pitch <= -M_PI_2) pitch = -M_PI_2 + 0.001;
	if (pitch >= M_PI_2) pitch = M_PI_2 - 0.001;
}


void Camera::move(const Vector3D& moveVector) {
	Vector3D mv = moveVector.rotate(Vector3D::j, pitch).rotate(Vector3D::k, heading);
	position = position + mv;
}

Vector3D Camera::getPosition() const {return position;}
double Camera::getHeading() const {return heading;}
double Camera::getPitch() const {return pitch;}


} //vhc