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

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