Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 074dbd882a9d69d1d7c1fc3379e6e3d355537b44 (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
108
109
110
111
112
113
/*
   shipdrawer.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 "client/shipdrawer.h"
#include "render/render.h"
#include "render/box.h"

#include <iostream>

namespace client {

using namespace render;

using math::Vector3f;
using math::Color;

Vector3f v0(1.0f, -1.0f, -1.0f);
Vector3f v1(1.0f,  1.0f, -1.0f);
Vector3f v2(1.0f,  1.0f,  1.0f);
Vector3f v3(1.0f, -1.0f,  1.0f);

Vector3f v4(-1.0f, -1.0f, -1.0f);
Vector3f v5(-1.0f,  1.0f, -1.0f);
Vector3f v6(-1.0f,  1.0f,  1.0f);
Vector3f v7(-1.0f, -1.0f,  1.0f);

ShipDrawer::ShipDrawer(game::Ship *s) 
{
    	angle = 0;
	ship = s;
}

ShipDrawer::~ShipDrawer() 
{
}

void ShipDrawer::draw(float elapsed) 
{
	gl::push();

	gl::rotate(ship->yaw(), 0.0f, 1.0f, 0.0f );

	Vector3f tl(0.25, 0.125, 0.125);
	Vector3f br(-0.25, -0.125, -0.125);
	
	Box box(tl, br);
	box.draw();

	tl = Vector3f(0, 0.07, 0.25);
	br = Vector3f(-0.5, -0.07, 0.125);
	Box engine1(tl, br);
	engine1.topcolor = Color(0.7, 0.7, 0.7);
	engine1.bottomcolor = engine1.topcolor * 0.5;
	engine1.draw();

	tl = Vector3f(0, 0.07, -0.125);
	br = Vector3f(-0.5, -0.07, -0.25);
	Box engine2(tl, br);
	engine2.topcolor = engine1.topcolor;
	engine2.bottomcolor = engine1.bottomcolor;
	engine2.draw();

	tl = Vector3f(0.4, 0.07, 0.07);
	br = Vector3f(0.25, -0.07, -0.07);
	Box cockpit(tl, br);
	cockpit.topcolor = engine1.topcolor;
	cockpit.bottomcolor = engine1.bottomcolor;
	cockpit.draw();

	if(ship->thrust() > 0 ) {
		gl::color(1.0f,0 ,0 );
		gl::begin(gl::Lines);
		gl::vertex(-0.5f, 0, 0.185);
		gl::vertex(-0.5f-0.25f*ship->thrust(), 0, 0.185);
	
		gl::vertex(-0.5f, 0, -0.185f);
		gl::vertex(-0.5f-0.25f*ship->thrust(), 0, -0.185f);
		gl::end();
	}

	// shield rotation
    	gl::rotate(angle, 0.0f, 1.0f, 0.0f );
    	angle += 180.0f * elapsed;
    	if( angle > 360.0f ) {
            angle -= 360.0f;
    	}
	
	// draw the shield
	gl::color(Color(0.0f, 1.0f ,0.0f , 0.5f));
	
	gl::begin(gl::LineStrip);
	gl::vertex(v0);
	gl::vertex(v1);
	gl::vertex(v2);
	gl::vertex(v3);
	gl::vertex(v0);
	gl::end();
	
	gl::begin(gl::LineStrip);
	gl::vertex(v4);
    	gl::vertex(v5);
        gl::vertex(v6);
        gl::vertex(v7);
	gl::vertex(v4);
	gl::end();

	gl::pop();
}

}