1 | |
---|
2 | #include <BBCEntityCluster.h> |
---|
3 | #include <BBCEntity.h> |
---|
4 | |
---|
5 | namespace BBC { |
---|
6 | |
---|
7 | EntityCluster::EntityCluster(): references(0) // initialize references to 0 |
---|
8 | { |
---|
9 | } |
---|
10 | |
---|
11 | EntityCluster::~EntityCluster() |
---|
12 | { |
---|
13 | mEntityClusterDataList.clear(); |
---|
14 | } |
---|
15 | |
---|
16 | EntityClusterDataPtr EntityCluster::getEntityClusterData(unsigned int value) |
---|
17 | { |
---|
18 | return mEntityClusterDataList[value]; |
---|
19 | } |
---|
20 | |
---|
21 | void EntityCluster::removeEntityClusterData(unsigned int value) |
---|
22 | { |
---|
23 | mEntityClusterDataList.erase(mEntityClusterDataList.begin() + value); |
---|
24 | } |
---|
25 | |
---|
26 | |
---|
27 | unsigned int EntityCluster::getNumEntitiesClusterData() |
---|
28 | { |
---|
29 | return static_cast<unsigned int>(mEntityClusterDataList.size()); |
---|
30 | } |
---|
31 | |
---|
32 | void EntityCluster::addEntityClusterData(EntityClusterDataPtr value) |
---|
33 | { |
---|
34 | mEntityClusterDataList.push_back(value); |
---|
35 | } |
---|
36 | |
---|
37 | void EntityCluster::removeEntitClusterData(unsigned int value) |
---|
38 | { |
---|
39 | mEntityClusterDataList.erase(mEntityClusterDataList.begin()+value); |
---|
40 | } |
---|
41 | |
---|
42 | EntityPtr EntityCluster::getEntity() |
---|
43 | { |
---|
44 | return mEntity; |
---|
45 | } |
---|
46 | |
---|
47 | void EntityCluster::setEntity(EntityPtr value) { |
---|
48 | mEntity = value; |
---|
49 | } |
---|
50 | |
---|
51 | unsigned int EntityCluster::getBillboardHandle() { |
---|
52 | return mBillboardHandle; |
---|
53 | } |
---|
54 | |
---|
55 | void EntityCluster::setBillboardHandle(unsigned int value) { |
---|
56 | mBillboardHandle = value; |
---|
57 | } |
---|
58 | |
---|
59 | void EntityCluster::setEntityDistribution(EntityDistributionPtr value) |
---|
60 | { |
---|
61 | mEntityDistribution = value; |
---|
62 | } |
---|
63 | |
---|
64 | EntityDistributionPtr EntityCluster::getEntityDistribution() |
---|
65 | { |
---|
66 | return mEntityDistribution; |
---|
67 | } |
---|
68 | |
---|
69 | void EntityCluster::generateEntityCluster() |
---|
70 | { |
---|
71 | mEntity = BBC::EntityPtr(new BBC::Entity()); |
---|
72 | |
---|
73 | mEntity->getSubEntity(0)->addTextureCoordSet(2); |
---|
74 | Ogre::Vector3 indicesOffset = Ogre::Vector3::ZERO; |
---|
75 | |
---|
76 | mEntity->getSubEntity(0)->enableVertexColours(true); |
---|
77 | |
---|
78 | float fRed = Ogre::Math::RangeRandom(0.0,1.0); |
---|
79 | float fGreen = Ogre::Math::RangeRandom(0.0,1.0); |
---|
80 | float fBlue = Ogre::Math::RangeRandom(0.0,1.0); |
---|
81 | Ogre::ColourValue subEntityColour = Ogre::ColourValue(1.0,fRed,fGreen,fBlue); |
---|
82 | |
---|
83 | unsigned int offset = 0; |
---|
84 | for (unsigned int iEntityClusterData = 0; iEntityClusterData < getNumEntitiesClusterData(); iEntityClusterData++) |
---|
85 | { |
---|
86 | EntityPtr entity = getEntityClusterData(iEntityClusterData)->getEntity(); |
---|
87 | |
---|
88 | for (unsigned int iFace = 0; iFace < entity->getSubEntity(0)->getNumFaces(); iFace++) |
---|
89 | { |
---|
90 | UniqueVertex uniqueVertex01, uniqueVertex02, uniqueVertex03; |
---|
91 | Ogre::Vector3 indices = entity->getSubEntity(0)->getFaceVerticesIDs(iFace); |
---|
92 | mEntity->getSubEntity(0)->addFaceVerticesIDs(indices + indicesOffset); |
---|
93 | |
---|
94 | mEntity->getSubEntity(0)->enableVertexColours(entity->getSubEntity(0)->hasVertexColours()); |
---|
95 | |
---|
96 | uniqueVertex01.position = entity->getSubEntity(0)->getUniqueVertex(indices[0]).position; |
---|
97 | uniqueVertex01.normal = entity->getSubEntity(0)->getUniqueVertex(indices[0]).normal; |
---|
98 | uniqueVertex01.uv[0] = entity->getSubEntity(0)->getUniqueVertex(indices[0]).uv[0]; |
---|
99 | if (mEntity->getSubEntity(0)->hasVertexColours()) |
---|
100 | { |
---|
101 | uniqueVertex01.colour = subEntityColour.getAsRGBA(); |
---|
102 | } |
---|
103 | mEntity->getSubEntity(0)->addUniqueVertex(uniqueVertex01); |
---|
104 | |
---|
105 | uniqueVertex02.position = entity->getSubEntity(0)->getUniqueVertex(indices[1]).position; |
---|
106 | uniqueVertex02.normal = entity->getSubEntity(0)->getUniqueVertex(indices[1]).normal; |
---|
107 | uniqueVertex02.uv[0] = entity->getSubEntity(0)->getUniqueVertex(indices[1]).uv[0]; |
---|
108 | if (mEntity->getSubEntity(0)->hasVertexColours()) |
---|
109 | { |
---|
110 | uniqueVertex02.colour = subEntityColour.getAsRGBA(); |
---|
111 | } |
---|
112 | mEntity->getSubEntity(0)->addUniqueVertex(uniqueVertex02); |
---|
113 | |
---|
114 | uniqueVertex03.position = entity->getSubEntity(0)->getUniqueVertex(indices[2]).position; |
---|
115 | uniqueVertex03.normal = entity->getSubEntity(0)->getUniqueVertex(indices[2]).normal; |
---|
116 | uniqueVertex03.uv[0] = entity->getSubEntity(0)->getUniqueVertex(indices[2]).uv[0]; |
---|
117 | if (mEntity->getSubEntity(0)->hasVertexColours()) |
---|
118 | { |
---|
119 | uniqueVertex03.colour = subEntityColour.getAsRGBA(); |
---|
120 | } |
---|
121 | mEntity->getSubEntity(0)->addUniqueVertex(uniqueVertex03); |
---|
122 | |
---|
123 | |
---|
124 | } |
---|
125 | offset = offset + entity->getSubEntity(0)->getNumFaces() * 3; |
---|
126 | indicesOffset = Ogre::Vector3(offset, offset, offset); |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | } |
---|