Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: defc356628c02c4b501a15dca33a7e3e0b394a0b (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
/*
   base/spectator.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 "example/spectator.h"

namespace example
{

core::Cvar *Spectator::g_spectatorspeed = 0;
core::Cvar *Spectator::g_spectatorrotation = 0;

Spectator::Spectator(core::Player *owner) : core::EntityControlable()
{
	// default properties
	entity_shape = core::Entity::Diamond;
	set_radius(0.25f);

	// the spectator gets player color
	if (owner) {
		set_owner(owner);
		get_color().assign(owner->color());
		get_color_second().assign(owner->color_second());
	}

	// set dirty flag
	set_dirty();
}

Spectator::~Spectator()
{
}

void Spectator::frame(float elapsed)
{
	// only update if necessary
	if (!entity_speed && ! target_thrust && !target_direction && !target_pitch && !target_roll && !target_strafe && !target_afterburner)
		return;

	// assign thrust value from input
	entity_thrust = target_thrust;

	// rotate according to input
	float rotation = g_spectatorrotation->value() * elapsed;
	get_axis().change_direction(target_direction * rotation);
	get_axis().change_pitch(target_pitch * rotation);
	get_axis().change_roll(target_roll * rotation);

	// assign speed from thruster
	float maxspeed = g_spectatorspeed->value();
	entity_speed = entity_thrust * maxspeed;

	// assign new location
	if (entity_speed)
		get_location() += axis().forward() * entity_speed * elapsed;

	if (target_afterburner)
		get_location() += axis().forward() * maxspeed * target_afterburner * elapsed;

	if (target_strafe)
		get_location() += axis().left() * maxspeed * target_strafe * elapsed;

	// set dirty flag
	set_dirty();
}

}