1 |
|
---|
2 | #include "OgreStableHeaders.h"
|
---|
3 |
|
---|
4 | #include "SpriteParticleRenderer.h"
|
---|
5 | #include "OgreParticle.h"
|
---|
6 | #include "OgreStringConverter.h"
|
---|
7 |
|
---|
8 | #ifdef GAMETOOLS_ILLUMINATION_MODULE
|
---|
9 |
|
---|
10 | namespace Ogre {
|
---|
11 |
|
---|
12 | Vector3 cameraPosition;
|
---|
13 |
|
---|
14 | class ParticleBackToFront
|
---|
15 | {
|
---|
16 | public:
|
---|
17 | bool operator() (const Particle* p1, const Particle* p2)
|
---|
18 | {
|
---|
19 | float dist1 = (cameraPosition - p1->position).length();
|
---|
20 | float dist2 = (cameraPosition - p2->position).length();
|
---|
21 | return dist1 < dist2;
|
---|
22 | }
|
---|
23 | };
|
---|
24 |
|
---|
25 | class ParticleFrontToBack
|
---|
26 | {
|
---|
27 | public:
|
---|
28 | bool operator() (const Particle* p1, const Particle* p2)
|
---|
29 | {
|
---|
30 | float dist1 = (cameraPosition - p1->position).length();
|
---|
31 | float dist2 = (cameraPosition - p2->position).length();
|
---|
32 | return dist1 > dist2;
|
---|
33 | }
|
---|
34 | };
|
---|
35 |
|
---|
36 | String SpriteName = "sprite";
|
---|
37 | //-----------------------------------------------------------------------
|
---|
38 | SpriteParticleRenderer::SpriteParticleRenderer()
|
---|
39 | {
|
---|
40 | if (createParamDictionary("SpriteParticleRenderer"))
|
---|
41 | {
|
---|
42 | ParamDictionary* dict = getParamDictionary();
|
---|
43 |
|
---|
44 | }
|
---|
45 | particleSorting = 0;
|
---|
46 | // Create billboard set
|
---|
47 | mSpriteSet = new SpriteSet("", 0, true);
|
---|
48 | // World-relative axes
|
---|
49 | mSpriteSet->setBillboardsInWorldSpace(true);
|
---|
50 | }
|
---|
51 | //-----------------------------------------------------------------------
|
---|
52 | SpriteParticleRenderer::~SpriteParticleRenderer()
|
---|
53 | {
|
---|
54 | delete mSpriteSet;
|
---|
55 | }
|
---|
56 | //-----------------------------------------------------------------------
|
---|
57 | const String& SpriteParticleRenderer::getType(void) const
|
---|
58 | {
|
---|
59 | return SpriteName;
|
---|
60 | }
|
---|
61 |
|
---|
62 | void SpriteParticleRenderer::setParticleSorting(int sorting, Camera* cam)
|
---|
63 | {
|
---|
64 | this->particleSorting = sorting;
|
---|
65 | cameraPosition = cam->getWorldPosition();
|
---|
66 | }
|
---|
67 | //-----------------------------------------------------------------------
|
---|
68 | void SpriteParticleRenderer::_updateRenderQueue(RenderQueue* queue,
|
---|
69 | std::list<Particle*>& currentParticles, bool cullIndividually)
|
---|
70 | {
|
---|
71 | mSpriteSet->setCullIndividually(cullIndividually);
|
---|
72 |
|
---|
73 | ////sort currentParticles
|
---|
74 | if(particleSorting > 0)
|
---|
75 | currentParticles.sort(ParticleBackToFront());
|
---|
76 | if(particleSorting < 0)
|
---|
77 | currentParticles.sort(ParticleFrontToBack());
|
---|
78 |
|
---|
79 |
|
---|
80 | // Update billboard set geometry
|
---|
81 | mSpriteSet->beginBillboards();
|
---|
82 | Billboard bb;
|
---|
83 | for (std::list<Particle*>::iterator i = currentParticles.begin();
|
---|
84 | i != currentParticles.end(); ++i)
|
---|
85 | {
|
---|
86 | Particle* p = *i;
|
---|
87 | bb.mPosition = p->position;
|
---|
88 | bb.mDirection = p->direction;
|
---|
89 | bb.mColour = p->colour;
|
---|
90 | bb.mRotation = p->rotation;
|
---|
91 | // Assign and compare at the same time
|
---|
92 | if (bb.mOwnDimensions = p->mOwnDimensions)
|
---|
93 | {
|
---|
94 | bb.mWidth = p->mWidth;
|
---|
95 | bb.mHeight = p->mHeight;
|
---|
96 | }
|
---|
97 | mSpriteSet->injectBillboard(bb);
|
---|
98 |
|
---|
99 | }
|
---|
100 |
|
---|
101 | mSpriteSet->endBillboards();
|
---|
102 |
|
---|
103 | // Update the queue
|
---|
104 | mSpriteSet->_updateRenderQueue(queue);
|
---|
105 | }
|
---|
106 | //-----------------------------------------------------------------------
|
---|
107 | void SpriteParticleRenderer::_setMaterial(MaterialPtr& mat)
|
---|
108 | {
|
---|
109 | mSpriteSet->setMaterialName(mat->getName());
|
---|
110 | }
|
---|
111 |
|
---|
112 | void SpriteParticleRenderer::_notifyCurrentCamera(Camera* cam)
|
---|
113 | {
|
---|
114 | mSpriteSet->_notifyCurrentCamera(cam);
|
---|
115 | }
|
---|
116 | //-----------------------------------------------------------------------
|
---|
117 | void SpriteParticleRenderer::_notifyDefaultDimensions(Real width, Real height)
|
---|
118 | {
|
---|
119 | mSpriteSet->setDefaultDimensions(width, height);
|
---|
120 | }
|
---|
121 | //-----------------------------------------------------------------------
|
---|
122 | void SpriteParticleRenderer::_notifyParticleResized(void)
|
---|
123 | {
|
---|
124 | mSpriteSet->_notifyBillboardResized();
|
---|
125 | }
|
---|
126 | //-----------------------------------------------------------------------
|
---|
127 | void SpriteParticleRenderer::_notifyParticleQuota(size_t quota)
|
---|
128 | {
|
---|
129 | mSpriteSet->setPoolSize(quota);
|
---|
130 | }
|
---|
131 | //-----------------------------------------------------------------------
|
---|
132 | void SpriteParticleRenderer::_notifyAttached(Node* parent, bool isTagPoint)
|
---|
133 | {
|
---|
134 | mSpriteSet->_notifyAttached(parent, isTagPoint);
|
---|
135 | }
|
---|
136 | //-----------------------------------------------------------------------
|
---|
137 | void SpriteParticleRenderer::setRenderQueueGroup(uint8 queueID)
|
---|
138 | {
|
---|
139 | mSpriteSet->setRenderQueueGroup(queueID);
|
---|
140 | }
|
---|
141 | //-----------------------------------------------------------------------
|
---|
142 | //-----------------------------------------------------------------------
|
---|
143 | //-----------------------------------------------------------------------
|
---|
144 | const String& SpriteParticleRendererFactory::getType() const
|
---|
145 | {
|
---|
146 | return SpriteName;
|
---|
147 | }
|
---|
148 | //-----------------------------------------------------------------------
|
---|
149 | ParticleSystemRenderer* SpriteParticleRendererFactory::createInstance(
|
---|
150 | const String& name )
|
---|
151 | {
|
---|
152 | return new SpriteParticleRenderer();
|
---|
153 | }
|
---|
154 | //-----------------------------------------------------------------------
|
---|
155 | void SpriteParticleRendererFactory::destroyInstance(
|
---|
156 | ParticleSystemRenderer* inst)
|
---|
157 | {
|
---|
158 | delete inst;
|
---|
159 | }
|
---|
160 |
|
---|
161 | }
|
---|
162 |
|
---|
163 | #endif |
---|