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

#include "model/fragment.h"
#include "model/vertexarray.h"

namespace model
{

/* ---- class Fragment --------------------------------------------- */
/*
	Triangles: the number of triangles is size/3
	Quads: the number of Quads is size/4
*/

Fragment::Fragment(const Fragment &other)
{
	fragment_type = other.fragment_type;
	fragment_index = other.fragment_index;
	fragment_structural_size = other.fragment_structural_size;
	fragment_detail_size = other.fragment_detail_size;
	fragment_material = other.fragment_material;
}

Fragment::Fragment(Type type, const Material *material)
{
	fragment_type = type;
	fragment_index = VertexArray::instance()->index() / 8;
	fragment_material = material;
	fragment_structural_size = 0;
	fragment_detail_size = 0;
}

size_t Fragment::add_vertex(math::Vector3f const & vertex, math::Vector3f const &normal, bool detail)
{
	size_t n = VertexArray::instance()->add_vertex(vertex, normal);
	if (n) {
		if (detail)
			fragment_detail_size += n;
		else
			fragment_structural_size += n;
	}
	return n;
}

size_t Fragment::add_vertex(math::Vector3f const & vertex, math::Vector3f const &normal, math::Vector2f const &texcoord, bool detail)
{
	size_t n = VertexArray::instance()->add_vertex(vertex, normal, texcoord.x(), texcoord.y());
	if (n) {
		if (detail)
			fragment_detail_size += n;
		else
			fragment_structural_size += n;
	}
	return n;
}
/* ---- class FragmentGroup ---------------------------------------- */

FragmentGroup::FragmentGroup()
{
	group_type = None;
	group_scale = 1.0f;
	group_distance = 0.0f;
	group_speed = 0.0f;
	group_engine = false;
}

FragmentGroup::~FragmentGroup()
{
	clear();
}

void FragmentGroup::clear()
{

	for (Fragments::iterator it = group_fragments.begin(); it != group_fragments.end(); it++) {
		delete(*it);
	}
	group_fragments.clear();
}

}