1 | |
---|
2 | #include "BBCSubEntity.h" |
---|
3 | |
---|
4 | namespace BBC { |
---|
5 | |
---|
6 | SubEntity::SubEntity(): references(0) // initialize references to 0 |
---|
7 | { |
---|
8 | mHasTangents = false; |
---|
9 | mHasVertexColours = false; |
---|
10 | mHasNormals = true; |
---|
11 | mHasTextureCoords = true; |
---|
12 | } |
---|
13 | |
---|
14 | SubEntity::~SubEntity() |
---|
15 | { |
---|
16 | mUniqueVertexList.clear(); |
---|
17 | mIndices.clear(); |
---|
18 | mTextureCoordSetsDimensions.clear(); |
---|
19 | |
---|
20 | } |
---|
21 | |
---|
22 | void SubEntity::setPosition(unsigned int index, Ogre::Vector3 value) |
---|
23 | { |
---|
24 | mUniqueVertexList[index].position = value; |
---|
25 | } |
---|
26 | |
---|
27 | Ogre::Vector3 SubEntity::getPosition(unsigned int index) |
---|
28 | { |
---|
29 | return mUniqueVertexList[index].position; |
---|
30 | } |
---|
31 | |
---|
32 | void SubEntity::setNormal(unsigned int index, Ogre::Vector3 value) |
---|
33 | { |
---|
34 | mUniqueVertexList[index].normal = value; |
---|
35 | } |
---|
36 | |
---|
37 | Ogre::Vector3 SubEntity::getNormal(unsigned int index) |
---|
38 | { |
---|
39 | return mUniqueVertexList[index].normal; |
---|
40 | } |
---|
41 | |
---|
42 | void SubEntity::setTexCoord(unsigned int index, unsigned int set, Ogre::Vector3 value) |
---|
43 | { |
---|
44 | mUniqueVertexList[index].uv[set] = value; |
---|
45 | } |
---|
46 | |
---|
47 | Ogre::Vector3 SubEntity::getTexCoord(unsigned int index, unsigned int set, unsigned int value) |
---|
48 | { |
---|
49 | return mUniqueVertexList[index].uv[set]; |
---|
50 | } |
---|
51 | |
---|
52 | void SubEntity::addFaceVerticesIDs(Ogre::Vector3 value) |
---|
53 | { |
---|
54 | mIndices.push_back(value); |
---|
55 | } |
---|
56 | |
---|
57 | void SubEntity::removeFaceVerticesIDs(unsigned int value) |
---|
58 | { |
---|
59 | mIndices.erase(mIndices.begin()+value); |
---|
60 | } |
---|
61 | |
---|
62 | Ogre::Vector3 SubEntity::getFaceVerticesIDs(unsigned int value) |
---|
63 | { |
---|
64 | return mIndices[value]; |
---|
65 | } |
---|
66 | |
---|
67 | void SubEntity::enableTangents(bool value) |
---|
68 | { |
---|
69 | mHasTangents = value; |
---|
70 | } |
---|
71 | |
---|
72 | bool SubEntity::hasTangents() |
---|
73 | { |
---|
74 | return mHasTangents; |
---|
75 | } |
---|
76 | |
---|
77 | void SubEntity::enableNormals(bool value) |
---|
78 | { |
---|
79 | mHasNormals = value; |
---|
80 | } |
---|
81 | |
---|
82 | bool SubEntity::hasNormals() |
---|
83 | { |
---|
84 | return mHasNormals; |
---|
85 | } |
---|
86 | |
---|
87 | void SubEntity::enableTextureCoords(bool value) |
---|
88 | { |
---|
89 | mHasTextureCoords = value; |
---|
90 | } |
---|
91 | |
---|
92 | void SubEntity::addTextureCoordSet(unsigned int numTexCoords) |
---|
93 | { |
---|
94 | mTextureCoordSetsDimensions.push_back(numTexCoords); |
---|
95 | enableTextureCoords(true); |
---|
96 | } |
---|
97 | |
---|
98 | void SubEntity::removeTextureCoordSet() |
---|
99 | { |
---|
100 | if (mTextureCoordSetsDimensions.size() > 0) |
---|
101 | { |
---|
102 | mTextureCoordSetsDimensions.erase(mTextureCoordSetsDimensions.begin()); |
---|
103 | } |
---|
104 | |
---|
105 | if (mTextureCoordSetsDimensions.size() == 0) |
---|
106 | { |
---|
107 | enableTextureCoords(false); |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | unsigned int SubEntity::getNumTexCoordSets() |
---|
112 | { |
---|
113 | return static_cast<unsigned int>(mTextureCoordSetsDimensions.size()); |
---|
114 | } |
---|
115 | |
---|
116 | unsigned int SubEntity::getNumTexCoords() |
---|
117 | { |
---|
118 | return static_cast<unsigned int>(mUniqueVertexList.size()); |
---|
119 | } |
---|
120 | |
---|
121 | unsigned int SubEntity::getTexCoordDimensions(unsigned int set) |
---|
122 | { |
---|
123 | return mTextureCoordSetsDimensions[set]; |
---|
124 | } |
---|
125 | |
---|
126 | void SubEntity::enableVertexColours(bool value) |
---|
127 | { |
---|
128 | mHasVertexColours = value; |
---|
129 | } |
---|
130 | |
---|
131 | bool SubEntity::hasVertexColours() |
---|
132 | { |
---|
133 | return mHasVertexColours; |
---|
134 | } |
---|
135 | |
---|
136 | void SubEntity::setVertexColour(unsigned int index, Ogre::RGBA value) |
---|
137 | { |
---|
138 | mUniqueVertexList[index].colour = value; |
---|
139 | } |
---|
140 | |
---|
141 | Ogre::RGBA SubEntity::getVertexColour(unsigned int index) |
---|
142 | { |
---|
143 | return mUniqueVertexList[index].colour; |
---|
144 | } |
---|
145 | |
---|
146 | unsigned int SubEntity::getNumFaces() |
---|
147 | { |
---|
148 | return static_cast<unsigned int>(mIndices.size()); |
---|
149 | } |
---|
150 | |
---|
151 | unsigned int SubEntity::getNumVertices() |
---|
152 | { |
---|
153 | return static_cast<unsigned int>(mUniqueVertexList.size()); |
---|
154 | } |
---|
155 | |
---|
156 | Ogre::String SubEntity::getName() |
---|
157 | { |
---|
158 | return mName; |
---|
159 | } |
---|
160 | |
---|
161 | void SubEntity::setName(Ogre::String value) |
---|
162 | { |
---|
163 | mName = value; |
---|
164 | } |
---|
165 | |
---|
166 | Ogre::String SubEntity::getMaterialName() |
---|
167 | { |
---|
168 | return mMaterialName; |
---|
169 | } |
---|
170 | |
---|
171 | void SubEntity::setMaterialName(Ogre::String value) |
---|
172 | { |
---|
173 | mMaterialName = value; |
---|
174 | } |
---|
175 | |
---|
176 | |
---|
177 | UniqueVertexList* SubEntity::getUniqueVertices() |
---|
178 | { |
---|
179 | return &mUniqueVertexList; |
---|
180 | } |
---|
181 | |
---|
182 | void SubEntity::addUniqueVertex(UniqueVertex uniqueVertex) |
---|
183 | { |
---|
184 | mUniqueVertexList.push_back(uniqueVertex); |
---|
185 | } |
---|
186 | |
---|
187 | void SubEntity::removeUniqueVertex(unsigned int index) |
---|
188 | { |
---|
189 | mUniqueVertexList.erase(mUniqueVertexList.begin() + index); |
---|
190 | } |
---|
191 | |
---|
192 | UniqueVertex SubEntity::getUniqueVertex(unsigned int index) |
---|
193 | { |
---|
194 | return mUniqueVertexList[index]; |
---|
195 | } |
---|
196 | |
---|
197 | const Ogre::AxisAlignedBox &SubEntity::getAABBox() |
---|
198 | { |
---|
199 | return mAABBox; |
---|
200 | } |
---|
201 | |
---|
202 | void SubEntity::setAABBox(Ogre::AxisAlignedBox box) |
---|
203 | { |
---|
204 | mAABBox = box; |
---|
205 | } |
---|
206 | |
---|
207 | void SubEntity::generateAABBox() |
---|
208 | {
|
---|
209 | // Bounds calculation
|
---|
210 | Ogre::Real squaredRadius = 0.0f;
|
---|
211 | Ogre::Vector3 min, max;
|
---|
212 | bool first = true;
|
---|
213 |
|
---|
214 | for (size_t jVertex = 0; jVertex < this->getNumVertices(); jVertex++)
|
---|
215 | {
|
---|
216 | if (first)
|
---|
217 | {
|
---|
218 | squaredRadius = this->getUniqueVertex(jVertex).position.squaredLength();
|
---|
219 | min = max = this->getUniqueVertex(jVertex).position;
|
---|
220 | first = false;
|
---|
221 | }
|
---|
222 | else
|
---|
223 | {
|
---|
224 | size_t numVertices = (unsigned int)this->getNumVertices();
|
---|
225 | //Ogre::LogManager::getSingleton().logMessage("NumVertices:" + Ogre::StringConverter::toString(numVertices));
|
---|
226 | //Ogre::LogManager::getSingleton().logMessage("IDVertex:" + Ogre::StringConverter::toString(jVertex) + "--" + Ogre::StringConverter::toString(iSubEntity) + "--" + Ogre::StringConverter::toString(mEntity->getSubEntity(iSubEntity)->getUniqueVertex(jVertex).position));
|
---|
227 | squaredRadius =
|
---|
228 | std::max(squaredRadius,this->getUniqueVertex(jVertex).position.squaredLength());
|
---|
229 | min.makeFloor(this->getUniqueVertex(jVertex).position);
|
---|
230 | max.makeCeil(this->getUniqueVertex(jVertex).position);
|
---|
231 | }
|
---|
232 | }
|
---|
233 |
|
---|
234 | // Merge bounds
|
---|
235 | mAABBox.setExtents(min, max); |
---|
236 | } |
---|
237 | |
---|
238 | } |
---|