1 | |
---|
2 | #include "BBCSubEntity.h" |
---|
3 | |
---|
4 | namespace BBC { |
---|
5 | |
---|
6 | SubEntity::SubEntity() |
---|
7 | { |
---|
8 | mHasTangents = false; |
---|
9 | mHasVertexColours = false; |
---|
10 | mHasNormals = true; |
---|
11 | mHasTextureCoords = true; |
---|
12 | } |
---|
13 | |
---|
14 | SubEntity::~SubEntity() |
---|
15 | { |
---|
16 | } |
---|
17 | |
---|
18 | void SubEntity::setPosition(unsigned int index, Ogre::Vector3 value) |
---|
19 | { |
---|
20 | mUniqueVertexList[index].position = value; |
---|
21 | } |
---|
22 | |
---|
23 | Ogre::Vector3 SubEntity::getPosition(unsigned int index) |
---|
24 | { |
---|
25 | return mUniqueVertexList[index].position; |
---|
26 | } |
---|
27 | |
---|
28 | void SubEntity::setNormal(unsigned int index, Ogre::Vector3 value) |
---|
29 | { |
---|
30 | mUniqueVertexList[index].normal = value; |
---|
31 | } |
---|
32 | |
---|
33 | Ogre::Vector3 SubEntity::getNormal(unsigned int index) |
---|
34 | { |
---|
35 | return mUniqueVertexList[index].normal; |
---|
36 | } |
---|
37 | |
---|
38 | void SubEntity::setTexCoord(unsigned int index, unsigned int set, Ogre::Vector3 value) |
---|
39 | { |
---|
40 | mUniqueVertexList[index].uv[set] = value; |
---|
41 | } |
---|
42 | |
---|
43 | Ogre::Vector3 SubEntity::getTexCoord(unsigned int index, unsigned int set, unsigned int value) |
---|
44 | { |
---|
45 | return mUniqueVertexList[index].uv[set]; |
---|
46 | } |
---|
47 | |
---|
48 | void SubEntity::addFaceVerticesIDs(Ogre::Vector3 value) |
---|
49 | { |
---|
50 | mIndices.push_back(value); |
---|
51 | } |
---|
52 | |
---|
53 | void SubEntity::removeFaceVerticesIDs(unsigned int value) |
---|
54 | { |
---|
55 | mIndices.erase(mIndices.begin()+value); |
---|
56 | } |
---|
57 | |
---|
58 | Ogre::Vector3 SubEntity::getFaceVerticesIDs(unsigned int value) |
---|
59 | { |
---|
60 | return mIndices[value]; |
---|
61 | } |
---|
62 | |
---|
63 | void SubEntity::enableTangents(bool value) |
---|
64 | { |
---|
65 | mHasTangents = value; |
---|
66 | } |
---|
67 | |
---|
68 | bool SubEntity::hasTangents() |
---|
69 | { |
---|
70 | return mHasTangents; |
---|
71 | } |
---|
72 | |
---|
73 | void SubEntity::enableNormals(bool value) |
---|
74 | { |
---|
75 | mHasNormals = value; |
---|
76 | } |
---|
77 | |
---|
78 | bool SubEntity::hasNormals() |
---|
79 | { |
---|
80 | return mHasNormals; |
---|
81 | } |
---|
82 | |
---|
83 | void SubEntity::enableTextureCoords(bool value) |
---|
84 | { |
---|
85 | mHasTextureCoords = value; |
---|
86 | } |
---|
87 | |
---|
88 | void SubEntity::addTextureCoordSet(unsigned int numTexCoords) |
---|
89 | { |
---|
90 | mTextureCoordSetsDimensions.push_back(numTexCoords); |
---|
91 | enableTextureCoords(true); |
---|
92 | } |
---|
93 | |
---|
94 | unsigned int SubEntity::getNumTexCoordSets() |
---|
95 | { |
---|
96 | return static_cast<unsigned int>(mTextureCoordSetsDimensions.size()); |
---|
97 | } |
---|
98 | |
---|
99 | unsigned int SubEntity::getNumTexCoords() |
---|
100 | { |
---|
101 | return static_cast<unsigned int>(mUniqueVertexList.size()); |
---|
102 | } |
---|
103 | |
---|
104 | unsigned int SubEntity::getTexCoordDimensions(unsigned int set) |
---|
105 | { |
---|
106 | return mTextureCoordSetsDimensions[set]; |
---|
107 | } |
---|
108 | |
---|
109 | void SubEntity::enableVertexColours(bool value) |
---|
110 | { |
---|
111 | mHasVertexColours = value; |
---|
112 | } |
---|
113 | |
---|
114 | bool SubEntity::hasVertexColours() |
---|
115 | { |
---|
116 | return mHasVertexColours; |
---|
117 | } |
---|
118 | |
---|
119 | void SubEntity::setVertexColour(unsigned int index, Ogre::RGBA value) |
---|
120 | { |
---|
121 | mUniqueVertexList[index].colour = value; |
---|
122 | } |
---|
123 | |
---|
124 | Ogre::RGBA SubEntity::getVertexColour(unsigned int index) |
---|
125 | { |
---|
126 | return mUniqueVertexList[index].colour; |
---|
127 | } |
---|
128 | |
---|
129 | unsigned int SubEntity::getNumFaces() |
---|
130 | { |
---|
131 | return static_cast<unsigned int>(mIndices.size()); |
---|
132 | } |
---|
133 | |
---|
134 | unsigned int SubEntity::getNumVertices() |
---|
135 | { |
---|
136 | return static_cast<unsigned int>(mUniqueVertexList.size()); |
---|
137 | } |
---|
138 | |
---|
139 | Ogre::String SubEntity::getName() |
---|
140 | { |
---|
141 | return mName; |
---|
142 | } |
---|
143 | |
---|
144 | void SubEntity::setName(Ogre::String value) |
---|
145 | { |
---|
146 | mName = value; |
---|
147 | } |
---|
148 | |
---|
149 | Ogre::String SubEntity::getMaterialName() |
---|
150 | { |
---|
151 | return mMaterialName; |
---|
152 | } |
---|
153 | |
---|
154 | void SubEntity::setMaterialName(Ogre::String value) |
---|
155 | { |
---|
156 | mMaterialName = value; |
---|
157 | } |
---|
158 | |
---|
159 | |
---|
160 | UniqueVertexList* SubEntity::getUniqueVertices() |
---|
161 | { |
---|
162 | return &mUniqueVertexList; |
---|
163 | } |
---|
164 | |
---|
165 | /* |
---|
166 | void SubEntity::createUniqueVertices() |
---|
167 | { |
---|
168 | for (unsigned int i = 0; i < getNumVertices(); i++) |
---|
169 | { |
---|
170 | UniqueVertex uniqueVertex; |
---|
171 | uniqueVertex.position = getVertex(i); |
---|
172 | uniqueVertex.normal = getNormal(i); |
---|
173 | for (unsigned int j = 0; j < getNumTexCoordSets(); j++) |
---|
174 | { |
---|
175 | uniqueVertex.uv[j] = getTexCoord(j,i); |
---|
176 | } |
---|
177 | |
---|
178 | } |
---|
179 | } |
---|
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 | } |
---|