source: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/LBBCDiffuseColorPointClusterGenerator.cpp @ 961

Revision 961, 4.6 KB checked in by igarcia, 18 years ago (diff)
Line 
1
2#include "LBBCDiffuseColorPointClusterGenerator.h"
3
4namespace LBBC
5{
6
7DiffuseColorPointClusterGenerator::DiffuseColorPointClusterGenerator()
8{
9}
10
11DiffuseColorPointClusterGenerator::~DiffuseColorPointClusterGenerator()
12{
13}
14
15void DiffuseColorPointClusterGenerator::setBillboardCloud(BBC::BillboardCloud *billboardCloud)
16{
17        mBillboardCloud = billboardCloud;
18}
19
20BBC::BillboardCloud* DiffuseColorPointClusterGenerator::getBillboardCloud()
21{
22        return mBillboardCloud;
23}
24
25void DiffuseColorPointClusterGenerator::setEntity(BBC::EntityPtr entity)
26{
27        mEntity = entity;
28}
29
30BBC::EntityPtr DiffuseColorPointClusterGenerator::getEntity()
31{
32        return mEntity;
33}
34
35void DiffuseColorPointClusterGenerator::setNumSamples(Ogre::Real numSamples)
36{
37        mNumSamples = numSamples;
38}
39
40Ogre::Real DiffuseColorPointClusterGenerator::getNumSamples()
41{
42        return mNumSamples;
43}
44
45void DiffuseColorPointClusterGenerator::setMaterialName(Ogre::String materialName)
46{
47        mMaterialName = materialName;
48}
49
50Ogre::String DiffuseColorPointClusterGenerator::getMaterialName()
51{
52        return mMaterialName;
53}
54
55void DiffuseColorPointClusterGenerator::generateDiffuseColorPointCluster()
56{
57        unsigned int numSubEntities = 0;
58        mEntity->removeSubEntity(0);
59       
60        for (unsigned int iBillboard = 0; iBillboard < mBillboardCloud->getNumBillboards(); iBillboard++)
61        {
62                BBC::BillboardPtr billboard = mBillboardCloud->getBillboard(iBillboard);               
63                BBC::EntityClusterPtr entityCluster = billboard->getBillboardClusterData()->getEntityCluster();
64
65                if (entityCluster->getNumEntitiesClusterData() > 0)
66                {                                       
67                        mEntity->createSubEntity();
68                        mEntity->getSubEntity(numSubEntities)->setMaterialName(mMaterialName);
69                        mEntity->getSubEntity(numSubEntities)->enableNormals(false);
70                        mEntity->getSubEntity(numSubEntities)->enableTextureCoords(true);
71                        mEntity->getSubEntity(numSubEntities)->addTextureCoordSet(2);
72                        mEntity->getSubEntity(numSubEntities)->enableVertexColours(true);
73
74                        Ogre::Vector3 p1, p2, p3, p4, pa, pb;
75                        Ogre::Real height, width;
76
77                        height = Ogre::Vector3(billboard->getBillboardClusterData()->getQuadTopLeftCorner() - billboard->getBillboardClusterData()->getQuadBottomLeftCorner()).length();
78                        width = Ogre::Vector3(billboard->getBillboardClusterData()->getQuadTopLeftCorner() - billboard->getBillboardClusterData()->getQuadTopRightCorner()).length();
79
80                        for (unsigned int iLeaf = 0; iLeaf < entityCluster->getNumEntitiesClusterData(); iLeaf++)
81                        {
82                                BBC::UniqueVertex vertex;
83
84                                BBC::EntityClusterData* entityClusterData = entityCluster->getEntityClusterData(iLeaf).get();
85                                Leaf *leaf = (Leaf*)entityClusterData->getEntity().get();
86                                vertex.position = leaf->getPosition();
87
88                                Ogre::Real numSamples = mNumSamples;
89                                Ogre::Real randomInt = Ogre::Math::Ceil(Ogre::Math::RangeRandom(0.5,numSamples));
90
91                                Ogre::Vector2 topLeftCorner[16];
92                                topLeftCorner[0] = Ogre::Vector2(0.0,  0.0);
93                                topLeftCorner[1] = Ogre::Vector2(0.25, 0.0);
94                                topLeftCorner[2] = Ogre::Vector2(0.5,  0.0);
95                                topLeftCorner[3] = Ogre::Vector2(0.75, 0.0);
96                                topLeftCorner[4] = Ogre::Vector2(0.0,  0.25);
97                                topLeftCorner[5] = Ogre::Vector2(0.25, 0.25);
98                                topLeftCorner[6] = Ogre::Vector2(0.5,  0.25);
99                                topLeftCorner[7] = Ogre::Vector2(0.75, 0.25);
100                                topLeftCorner[8] = Ogre::Vector2(0.0,  0.5);
101                                topLeftCorner[9] = Ogre::Vector2(0.25, 0.5);
102                                topLeftCorner[10] = Ogre::Vector2(0.5,  0.5);
103                                topLeftCorner[11] = Ogre::Vector2(0.75, 0.5);
104                                topLeftCorner[12] = Ogre::Vector2(0.0,  0.75);
105                                topLeftCorner[13] = Ogre::Vector2(0.25, 0.75);
106                                topLeftCorner[14] = Ogre::Vector2(0.5,  0.75);
107                                topLeftCorner[15] = Ogre::Vector2(0.75, 0.75);
108
109                                vertex.uv[0] = Ogre::Vector3(1.0 - topLeftCorner[(unsigned int)randomInt-1][0], 1.0 - topLeftCorner[(unsigned int)randomInt-1][1], 0.0);
110                                vertex.colour = Ogre::ColourValue(Ogre::Math::RangeRandom(0.0, 1.0), Ogre::Math::RangeRandom(0.0, 1.0), Ogre::Math::RangeRandom(0.0, 1.0), 1.0).getAsRGBA();
111                                mEntity->getSubEntity(numSubEntities)->addUniqueVertex(vertex);
112                        }
113
114                        unsigned int iVertexFace = 0;
115                        Ogre::Vector3 faceVertexIndices = Ogre::Vector3::ZERO;
116
117                        for (unsigned int iVertex = 0; iVertex < mEntity->getSubEntity(numSubEntities)->getNumVertices(); iVertex++)
118                        {
119                                faceVertexIndices[iVertexFace] = iVertex;
120                                iVertexFace++;
121                               
122                                if ((iVertex + 1) != mEntity->getSubEntity(numSubEntities)->getNumVertices())
123                                {
124                                        if (iVertexFace == 3)
125                                        {
126                                                mEntity->getSubEntity(numSubEntities)->addFaceVerticesIDs(faceVertexIndices);
127                                                iVertexFace = 0;
128                                                faceVertexIndices = Ogre::Vector3::ZERO;
129                                        }
130                                }
131                                else
132                                {
133                                        mEntity->getSubEntity(numSubEntities)->addFaceVerticesIDs(faceVertexIndices);
134                                }                               
135                        }
136
137                        numSubEntities++;
138                }
139        }
140}
141
142}
Note: See TracBrowser for help on using the repository browser.