source: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/BBCSubEntity.cpp @ 699

Revision 699, 4.8 KB checked in by igarcia, 19 years ago (diff)
Line 
1
2#include "BBCSubEntity.h"
3
4namespace BBC {
5
6SubEntity::SubEntity()
7{
8        mHasTangents = false;
9        mHasVertexColours = false;
10        mHasNormals = true;
11        mHasTextureCoords = true;
12}
13
14SubEntity::~SubEntity()
15{
16}
17
18void SubEntity::setPosition(unsigned int index, Ogre::Vector3 value)
19{
20        mUniqueVertexList[index].position = value;
21}
22
23Ogre::Vector3 SubEntity::getPosition(unsigned int index)
24{
25        return mUniqueVertexList[index].position;
26}
27
28void SubEntity::setNormal(unsigned int index, Ogre::Vector3 value)
29{
30        mUniqueVertexList[index].normal = value;
31}
32
33Ogre::Vector3 SubEntity::getNormal(unsigned int index)
34{
35        return mUniqueVertexList[index].normal;
36}
37
38void SubEntity::setTexCoord(unsigned int index, unsigned int set, Ogre::Vector3 value)
39{
40        mUniqueVertexList[index].uv[set] = value;
41}
42
43Ogre::Vector3 SubEntity::getTexCoord(unsigned int index, unsigned int set, unsigned int value)
44{
45        return mUniqueVertexList[index].uv[set];
46}
47
48void SubEntity::addFaceVerticesIDs(Ogre::Vector3 value)
49{
50        mIndices.push_back(value);
51}
52
53void SubEntity::removeFaceVerticesIDs(unsigned int value)
54{
55        mIndices.erase(mIndices.begin()+value);
56}
57
58Ogre::Vector3 SubEntity::getFaceVerticesIDs(unsigned int value)
59{
60        return mIndices[value];
61}
62
63void SubEntity::enableTangents(bool value)
64{
65        mHasTangents = value;
66}
67
68bool SubEntity::hasTangents()
69{
70        return mHasTangents;
71}
72
73void SubEntity::enableNormals(bool value)
74{
75        mHasNormals = value;
76}
77
78bool SubEntity::hasNormals()
79{
80        return mHasNormals;
81}
82
83void SubEntity::enableTextureCoords(bool value)
84{
85        mHasTextureCoords = value;
86}
87
88void SubEntity::addTextureCoordSet(unsigned int numTexCoords)
89{
90        mTextureCoordSetsDimensions.push_back(numTexCoords);
91        enableTextureCoords(true);
92}
93
94unsigned int SubEntity::getNumTexCoordSets()
95{
96        return static_cast<unsigned int>(mTextureCoordSetsDimensions.size());
97}
98
99unsigned int SubEntity::getNumTexCoords()
100{
101        return static_cast<unsigned int>(mUniqueVertexList.size());
102}
103
104unsigned int SubEntity::getTexCoordDimensions(unsigned int set)
105{
106        return mTextureCoordSetsDimensions[set];
107}
108
109void SubEntity::enableVertexColours(bool value)
110{
111        mHasVertexColours = value;
112}
113
114bool SubEntity::hasVertexColours()
115{
116        return mHasVertexColours;
117}
118
119void SubEntity::setVertexColour(unsigned int index, Ogre::RGBA value)
120{
121        mUniqueVertexList[index].colour = value;
122}
123
124Ogre::RGBA SubEntity::getVertexColour(unsigned int index)
125{
126        return mUniqueVertexList[index].colour;
127}
128
129unsigned int SubEntity::getNumFaces()
130{
131        return static_cast<unsigned int>(mIndices.size());
132}
133
134unsigned int SubEntity::getNumVertices()
135{
136        return static_cast<unsigned int>(mUniqueVertexList.size());
137}
138
139Ogre::String SubEntity::getName()
140{
141        return mName;
142}
143
144void SubEntity::setName(Ogre::String value)
145{
146        mName = value;
147}
148
149Ogre::String SubEntity::getMaterialName()
150{
151        return mMaterialName;
152}
153
154void SubEntity::setMaterialName(Ogre::String value)
155{
156        mMaterialName = value;
157}
158
159
160UniqueVertexList* SubEntity::getUniqueVertices()
161{
162        return &mUniqueVertexList;
163}
164
165/*
166void 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
182void SubEntity::addUniqueVertex(UniqueVertex uniqueVertex)
183{
184        mUniqueVertexList.push_back(uniqueVertex);
185}
186
187void SubEntity::removeUniqueVertex(unsigned int index)
188{
189        mUniqueVertexList.erase(mUniqueVertexList.begin() + index);
190}
191
192UniqueVertex SubEntity::getUniqueVertex(unsigned int index)
193{
194        return mUniqueVertexList[index];
195}
196
197const Ogre::AxisAlignedBox &SubEntity::getAABBox()
198{
199        return mAABBox;
200}
201
202void SubEntity::setAABBox(Ogre::AxisAlignedBox box)
203{
204        mAABBox = box;
205}
206
207void 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}
Note: See TracBrowser for help on using the repository browser.