Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: ca60d186060dd8aab83873c8f954d445b91fd4af (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* camera.cc
   This file is part of the Osirion project and is distributed under 
   the terms and conditions of the GNU General Public License version 2 
*/

#include "common/functions.h"
#include "common/osirion.h"

#include "game/game.h"
#include "gl/osiriongl.h"

namespace camera
{
enum Mode {Free, Track};
Mode mode = Track;

const float track_pitch = 15.0f; // default tracking pitch
const float offset_inc = 5.0f; // default offset increment

float yaw = 90; // current yaw, angle in XZ plane
float yaw_offset = 0; // target offset, relative to target yaw

float pitch = -90; // current pitch, angle in XY
float pitch_offset = track_pitch; // target offset, relative to target pitch

float distance = 2.0f; // distance from the eye to the target


void draw(float elapsed) 
{	
	// adjust yaw target
	float yaw_target = game::ship.yaw - yaw_offset;
	float d = degreesf(yaw - yaw_target);
	yaw = degreesf( yaw - d * elapsed);

	// adjust pitch target
	float pitch_target = 0.0f - pitch_offset;
	d= degreesf(pitch - pitch_target);
	pitch = degreesf( pitch - d *elapsed);
	
	/*
	gl::translate(distance, 0.0, 0.0);
	gl::rotate(-pitch,0, 0, 1.0 );
	gl::rotate(-yaw, 0, 1.0f, 0);
	*/
	switch (mode) {
	case Free:
		gl::translate(1+distance * GAMESCALE, 0.0f, 0.0f);
		gl::rotate(-pitch, 0, 0, 1.0f);
		gl::rotate(-yaw, 0, 1.0f, 0);
		break;
	case Track:
		gl::translate(1+distance* GAMESCALE, -0.5f* GAMESCALE, 0.0f);
		gl::rotate(-pitch, 0, 0, 1.0f);
		gl::rotate(-yaw, 0, 1.0f, 0);
		break;
	default:
		break;
	}
}

void rotate_right()
{
	if (mode == Free ) {
		yaw_offset = degreesf(  yaw_offset - offset_inc);
	}
}

void rotate_left()
{
	if (mode == Free ) {
		yaw_offset = degreesf(  yaw_offset + offset_inc);
	}
}

void rotate_up()
{
	if (mode == Free ) {
		pitch_offset = degreesf( pitch_offset + offset_inc);
	}
}

void rotate_down()
{
	if (mode == Free ) {
		pitch_offset = degreesf( pitch_offset - offset_inc);
	}
}

void nextmode() {
	switch(mode) {
	case Free:
		mode = Track;
		yaw_offset = 0;
		yaw = game::ship.yaw;
		pitch_offset = track_pitch;
		break;
	case Track:
		mode = Free;
		yaw_offset = 0;
		break;
	default:
		break;
	}
}

} //namespace camera