Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: d6f14b5d13774cc8d2406bbb2034ba1c8856d1f8 (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
/*
   render/box.cc
   This file is part of the Osirion project and is distributed under 
   the terms of the GNU General Public License version 2 
*/

#include "render/box.h"

namespace render {

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

Box::Box(Vector3f const & tl, Vector3f const &br) : 
	topleft(tl), bottomright(br)
{
	topcolor = Color::White();
	bottomcolor= Color::White() * 0.7f;
	radius = 1.0f;
}

Box::Box(const Box & other)
{
	(*this) = other;
}

Box& Box::operator=(const Box &other)
{
	bottomcolor = other.bottomcolor;
	topcolor = other.topcolor;

	topleft = other.topleft;
	bottomright = other.bottomright;
	return (*this);
}

void Box::draw()
{
	using namespace gl;

	Vector3f v0(topleft.x, bottomright.y, bottomright.z);
	Vector3f v1(topleft.x,  topleft.y, bottomright.z);
	Vector3f v2(topleft.x,  topleft.y,  topleft.z);
	Vector3f v3(topleft.x, bottomright.y,  topleft.z);

	Vector3f v4(bottomright.x, bottomright.y, bottomright.z);
	Vector3f v5(bottomright.x,  topleft.y, bottomright.z);
	Vector3f v6(bottomright.x,  topleft.y,  topleft.z);
	Vector3f v7(bottomright.x, bottomright.y,  topleft.z);

	begin(Quads);

	// top
	color(topcolor);	
	vertex(radius*v2);
	vertex(radius*v1);
        vertex(radius*v5);
	vertex(radius*v6);
	
	// sides
	color(bottomcolor);
	vertex(radius*v0);
	color(topcolor);
    	vertex(radius*v1);
        vertex(radius*v2);
	color(bottomcolor);
        vertex(radius*v3);

        vertex(radius*v3);
	color(topcolor);
    	vertex(radius*v2);
        vertex(radius*v6);
	color(bottomcolor);
        vertex(radius*v7);

	vertex(radius*v4);
	color(topcolor);
    	vertex(radius*v5);
        vertex(radius*v1);
	color(bottomcolor);
        vertex(radius*v0);

	vertex(radius*v7);
	color(topcolor);
    	vertex(radius*v6);
        vertex(radius*v5);
	color(bottomcolor);
        vertex(radius*v4);

	// bottom
	color(bottomcolor);	
	vertex(radius*v4);
	vertex(radius*v0);
        vertex(radius*v3);
	vertex(radius*v7);

	end();

}

}