source: OGRE/trunk/ogrenew/OgreMain/src/OgreBillboardParticleRenderer.cpp @ 692

Revision 692, 20.0 KB checked in by mattausch, 18 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreStableHeaders.h"
26
27#include "OgreBillboardParticleRenderer.h"
28#include "OgreParticle.h"
29#include "OgreStringConverter.h"
30
31namespace Ogre {
32    String rendererTypeName = "billboard";
33
34    //-----------------------------------------------------------------------
35    BillboardParticleRenderer::CmdBillboardType BillboardParticleRenderer::msBillboardTypeCmd;
36    BillboardParticleRenderer::CmdBillboardOrigin BillboardParticleRenderer::msBillboardOriginCmd;
37    BillboardParticleRenderer::CmdBillboardRotationType BillboardParticleRenderer::msBillboardRotationTypeCmd;
38    BillboardParticleRenderer::CmdCommonDirection BillboardParticleRenderer::msCommonDirectionCmd;
39    BillboardParticleRenderer::CmdCommonUpVector BillboardParticleRenderer::msCommonUpVectorCmd;
40    BillboardParticleRenderer::CmdPointRendering BillboardParticleRenderer::msPointRenderingCmd;
41        BillboardParticleRenderer::CmdAccurateFacing BillboardParticleRenderer::msAccurateFacingCmd;
42    //-----------------------------------------------------------------------
43    BillboardParticleRenderer::BillboardParticleRenderer()
44    {
45        if (createParamDictionary("BillboardParticleRenderer"))
46        {
47            ParamDictionary* dict = getParamDictionary();
48            dict->addParameter(ParameterDef("billboard_type",
49                "The type of billboard to use. 'point' means a simulated spherical particle, "
50                "'oriented_common' means all particles in the set are oriented around common_direction, "
51                "'oriented_self' means particles are oriented around their own direction, "
52                "'perpendicular_common' means all particles are perpendicular to common_direction, "
53                "and 'perpendicular_self' means particles are perpendicular to their own direction.",
54                PT_STRING),
55                &msBillboardTypeCmd);
56
57            dict->addParameter(ParameterDef("billboard_origin",
58                "This setting controls the fine tuning of where a billboard appears in relation to it's position. "
59                "Possible value are: 'top_left', 'top_center', 'top_right', 'center_left', 'center', 'center_right', "
60                "'bottom_left', 'bottom_center' and 'bottom_right'. Default value is 'center'.",
61                PT_STRING),
62                &msBillboardOriginCmd);
63
64            dict->addParameter(ParameterDef("billboard_rotation_type",
65                "This setting controls the billboard rotation type. "
66                                "'vertex' means rotate the billboard's vertices around their facing direction."
67                "'texcoord' means rotate the billboard's texture coordinates. Default value is 'texcoord'.",
68                PT_STRING),
69                &msBillboardRotationTypeCmd);
70
71            dict->addParameter(ParameterDef("common_direction",
72                "Only useful when billboard_type is oriented_common or perpendicular_common. "
73                                "When billboard_type is oriented_common, this parameter sets the common orientation for "
74                                "all particles in the set (e.g. raindrops may all be oriented downwards). "
75                                "When billboard_type is perpendicular_common, this parameter sets the perpendicular vector for "
76                                "all particles in the set (e.g. an aureola around the player and parallel to the ground).",
77                PT_VECTOR3),
78                &msCommonDirectionCmd);
79
80            dict->addParameter(ParameterDef("common_up_vector",
81                "Only useful when billboard_type is perpendicular_self or perpendicular_common. This "
82                                "parameter sets the common up-vector for all particles in the set (e.g. an aureola around "
83                                "the player and parallel to the ground).",
84                PT_VECTOR3),
85                &msCommonUpVectorCmd);
86            dict->addParameter(ParameterDef("point_rendering",
87                "Set whether or not particles will use point rendering "
88                                "rather than manually generated quads. This allows for faster "
89                                "rendering of point-oriented particles although introduces some "
90                                "limitations too such as requiring a common particle size."
91                                "Possible values are 'true' or 'false'.",
92                PT_BOOL),
93                &msPointRenderingCmd);
94                        dict->addParameter(ParameterDef("accurate_facing",
95                                "Set whether or not particles will be oriented to the camera "
96                                "based on the relative position to the camera rather than just "
97                                "the camera direction. This is more accurate but less optimal. "
98                                "Cannot be combined with point rendering.",
99                                PT_BOOL),
100                                &msAccurateFacingCmd);
101        }
102
103        // Create billboard set
104        mBillboardSet = new BillboardSet("", 0, true);
105        // World-relative axes
106        mBillboardSet->setBillboardsInWorldSpace(true);
107    }
108    //-----------------------------------------------------------------------
109    BillboardParticleRenderer::~BillboardParticleRenderer()
110    {
111        delete mBillboardSet;
112    }
113    //-----------------------------------------------------------------------
114    const String& BillboardParticleRenderer::getType(void) const
115    {
116        return rendererTypeName;
117    }
118    //-----------------------------------------------------------------------
119    void BillboardParticleRenderer::_updateRenderQueue(RenderQueue* queue,
120        std::list<Particle*>& currentParticles, bool cullIndividually)
121    {
122        mBillboardSet->setCullIndividually(cullIndividually);
123
124        // Update billboard set geometry
125        mBillboardSet->beginBillboards();
126        Billboard bb;
127        for (std::list<Particle*>::iterator i = currentParticles.begin();
128            i != currentParticles.end(); ++i)
129        {
130            Particle* p = *i;
131            bb.mPosition = p->position;
132                        if (mBillboardSet->getBillboardType() == BBT_ORIENTED_SELF ||
133                                mBillboardSet->getBillboardType() == BBT_PERPENDICULAR_SELF)
134                        {
135                                // Normalise direction vector
136                                bb.mDirection = p->direction;
137                                bb.mDirection.normalise();
138                        }
139            bb.mColour = p->colour;
140            bb.mRotation = p->rotation;
141            // Assign and compare at the same time
142            if (bb.mOwnDimensions = p->mOwnDimensions)
143            {
144                bb.mWidth = p->mWidth;
145                bb.mHeight = p->mHeight;
146            }
147            mBillboardSet->injectBillboard(bb);
148
149        }
150       
151        mBillboardSet->endBillboards();
152
153        // Update the queue
154        mBillboardSet->_updateRenderQueue(queue);
155    }
156    //-----------------------------------------------------------------------
157    void BillboardParticleRenderer::_setMaterial(MaterialPtr& mat)
158    {
159        mBillboardSet->setMaterialName(mat->getName());
160    }
161    //-----------------------------------------------------------------------
162    void BillboardParticleRenderer::setBillboardType(BillboardType bbt)
163    {
164        mBillboardSet->setBillboardType(bbt);
165    }
166        //-----------------------------------------------------------------------
167        void BillboardParticleRenderer::setUseAccurateFacing(bool acc)
168        {
169                mBillboardSet->setUseAccurateFacing(acc);
170        }
171        //-----------------------------------------------------------------------
172        bool BillboardParticleRenderer::getUseAccurateFacing(void) const
173        {
174                return mBillboardSet->getUseAccurateFacing();
175        }
176    //-----------------------------------------------------------------------
177    BillboardType BillboardParticleRenderer::getBillboardType(void) const
178    {
179        return mBillboardSet->getBillboardType();
180    }
181    //-----------------------------------------------------------------------
182    void BillboardParticleRenderer::setBillboardRotationType(BillboardRotationType rotationType)
183    {
184        mBillboardSet->setBillboardRotationType(rotationType);
185    }
186    //-----------------------------------------------------------------------
187    BillboardRotationType BillboardParticleRenderer::getBillboardRotationType(void) const
188    {
189        return mBillboardSet->getBillboardRotationType();
190    }
191    //-----------------------------------------------------------------------
192    void BillboardParticleRenderer::setCommonDirection(const Vector3& vec)
193    {
194        mBillboardSet->setCommonDirection(vec);
195    }
196    //-----------------------------------------------------------------------
197    const Vector3& BillboardParticleRenderer::getCommonDirection(void) const
198    {
199        return mBillboardSet->getCommonDirection();
200    }
201    //-----------------------------------------------------------------------
202    void BillboardParticleRenderer::setCommonUpVector(const Vector3& vec)
203    {
204        mBillboardSet->setCommonUpVector(vec);
205    }
206    //-----------------------------------------------------------------------
207    const Vector3& BillboardParticleRenderer::getCommonUpVector(void) const
208    {
209        return mBillboardSet->getCommonUpVector();
210    }
211    //-----------------------------------------------------------------------
212    void BillboardParticleRenderer::_notifyCurrentCamera(Camera* cam)
213    {
214        mBillboardSet->_notifyCurrentCamera(cam);
215    }
216    //-----------------------------------------------------------------------
217    void BillboardParticleRenderer::_notifyParticleRotated(void)
218    {
219        mBillboardSet->_notifyBillboardRotated();
220    }
221    //-----------------------------------------------------------------------
222    void BillboardParticleRenderer::_notifyDefaultDimensions(Real width, Real height)
223    {
224        mBillboardSet->setDefaultDimensions(width, height);
225    }
226    //-----------------------------------------------------------------------
227    void BillboardParticleRenderer::_notifyParticleResized(void)
228    {
229        mBillboardSet->_notifyBillboardResized();
230    }
231    //-----------------------------------------------------------------------
232    void BillboardParticleRenderer::_notifyParticleQuota(size_t quota)
233    {
234        mBillboardSet->setPoolSize(quota);
235    }
236    //-----------------------------------------------------------------------
237    void BillboardParticleRenderer::_notifyAttached(Node* parent, bool isTagPoint)
238    {
239        mBillboardSet->_notifyAttached(parent, isTagPoint);
240    }
241        //-----------------------------------------------------------------------
242        void BillboardParticleRenderer::setRenderQueueGroup(uint8 queueID)
243        {
244                mBillboardSet->setRenderQueueGroup(queueID);
245        }
246        //-----------------------------------------------------------------------
247        void BillboardParticleRenderer::setKeepParticlesInLocalSpace(bool keepLocal)
248        {
249                mBillboardSet->setBillboardsInWorldSpace(!keepLocal);
250        }
251    //-----------------------------------------------------------------------
252    SortMode BillboardParticleRenderer::_getSortMode(void) const
253    {
254        return mBillboardSet->_getSortMode();
255    }
256        //-----------------------------------------------------------------------
257        void BillboardParticleRenderer::setPointRenderingEnabled(bool enabled)
258        {
259                mBillboardSet->setPointRenderingEnabled(enabled);
260        }
261        //-----------------------------------------------------------------------
262        bool BillboardParticleRenderer::isPointRenderingEnabled(void) const
263        {
264                return mBillboardSet->isPointRenderingEnabled();
265        }
266    //-----------------------------------------------------------------------
267    //-----------------------------------------------------------------------
268    //-----------------------------------------------------------------------
269    const String& BillboardParticleRendererFactory::getType() const
270    {
271        return rendererTypeName;
272    }
273    //-----------------------------------------------------------------------
274    ParticleSystemRenderer* BillboardParticleRendererFactory::createInstance(
275        const String& name )
276    {
277        return new BillboardParticleRenderer();
278    }
279    //-----------------------------------------------------------------------
280    void BillboardParticleRendererFactory::destroyInstance(
281        ParticleSystemRenderer* inst)
282    {
283        delete inst;
284    }
285    //-----------------------------------------------------------------------
286    //-----------------------------------------------------------------------
287    String BillboardParticleRenderer::CmdBillboardType::doGet(const void* target) const
288    {
289        BillboardType t = static_cast<const BillboardParticleRenderer*>(target)->getBillboardType();
290        switch(t)
291        {
292        case BBT_POINT:
293            return "point";
294            break;
295        case BBT_ORIENTED_COMMON:
296            return "oriented_common";
297            break;
298        case BBT_ORIENTED_SELF:
299            return "oriented_self";
300            break;
301        case BBT_PERPENDICULAR_COMMON:
302            return "perpendicular_common";
303        case BBT_PERPENDICULAR_SELF:
304            return "perpendicular_self";
305        }
306        // Compiler nicety
307        return "";
308    }
309    void BillboardParticleRenderer::CmdBillboardType::doSet(void* target, const String& val)
310    {
311        BillboardType t;
312        if (val == "point")
313        {
314            t = BBT_POINT;
315        }
316        else if (val == "oriented_common")
317        {
318            t = BBT_ORIENTED_COMMON;
319        }
320        else if (val == "oriented_self")
321        {
322            t = BBT_ORIENTED_SELF;
323        }
324        else if (val == "perpendicular_common")
325        {
326            t = BBT_PERPENDICULAR_COMMON;
327        }
328        else if (val == "perpendicular_self")
329        {
330            t = BBT_PERPENDICULAR_SELF;
331        }
332        else
333        {
334            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
335                "Invalid billboard_type '" + val + "'",
336                "ParticleSystem::CmdBillboardType::doSet");
337        }
338
339        static_cast<BillboardParticleRenderer*>(target)->setBillboardType(t);
340    }
341    //-----------------------------------------------------------------------
342    String BillboardParticleRenderer::CmdBillboardOrigin::doGet(const void* target) const
343    {
344        BillboardOrigin o = static_cast<const BillboardParticleRenderer*>(target)->getBillboardOrigin();
345        switch (o)
346        {
347        case BBO_TOP_LEFT:
348            return "top_left";
349        case BBO_TOP_CENTER:
350            return "top_center";
351        case BBO_TOP_RIGHT:
352            return "top_right";
353        case BBO_CENTER_LEFT:
354            return "center_left";
355        case BBO_CENTER:
356            return "center";
357        case BBO_CENTER_RIGHT:
358            return "center_right";
359        case BBO_BOTTOM_LEFT:
360            return "bottom_left";
361        case BBO_BOTTOM_CENTER:
362            return "bottom_center";
363        case BBO_BOTTOM_RIGHT:
364            return "bottom_right";
365        }
366        // Compiler nicety
367        return StringUtil::BLANK;
368    }
369    void BillboardParticleRenderer::CmdBillboardOrigin::doSet(void* target, const String& val)
370    {
371        BillboardOrigin o;
372        if (val == "top_left")
373            o = BBO_TOP_LEFT;
374        else if (val =="top_center")
375            o = BBO_TOP_CENTER;
376        else if (val =="top_right")
377            o = BBO_TOP_RIGHT;
378        else if (val =="center_left")
379            o = BBO_CENTER_LEFT;
380        else if (val =="center")
381            o = BBO_CENTER;
382        else if (val =="center_right")
383            o = BBO_CENTER_RIGHT;
384        else if (val =="bottom_left")
385            o = BBO_BOTTOM_LEFT;
386        else if (val =="bottom_center")
387            o = BBO_BOTTOM_CENTER;
388        else if (val =="bottom_right")
389            o = BBO_BOTTOM_RIGHT;
390        else
391        {
392            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
393                "Invalid billboard_origin '" + val + "'",
394                "ParticleSystem::CmdBillboardOrigin::doSet");
395        }
396
397        static_cast<BillboardParticleRenderer*>(target)->setBillboardOrigin(o);
398    }
399    //-----------------------------------------------------------------------
400    String BillboardParticleRenderer::CmdBillboardRotationType::doGet(const void* target) const
401    {
402        BillboardRotationType r = static_cast<const BillboardParticleRenderer*>(target)->getBillboardRotationType();
403        switch(r)
404        {
405        case BBR_VERTEX:
406            return "vertex";
407        case BBR_TEXCOORD:
408            return "texcoord";
409        }
410        // Compiler nicety
411        return StringUtil::BLANK;
412    }
413    void BillboardParticleRenderer::CmdBillboardRotationType::doSet(void* target, const String& val)
414    {
415        BillboardRotationType r;
416        if (val == "vertex")
417            r = BBR_VERTEX;
418        else if (val == "texcoord")
419            r = BBR_TEXCOORD;
420        else
421        {
422            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
423                "Invalid billboard_rotation_type '" + val + "'",
424                "ParticleSystem::CmdBillboardRotationType::doSet");
425        }
426
427        static_cast<BillboardParticleRenderer*>(target)->setBillboardRotationType(r);
428    }
429    //-----------------------------------------------------------------------
430    String BillboardParticleRenderer::CmdCommonDirection::doGet(const void* target) const
431    {
432        return StringConverter::toString(
433            static_cast<const BillboardParticleRenderer*>(target)->getCommonDirection() );
434    }
435    void BillboardParticleRenderer::CmdCommonDirection::doSet(void* target, const String& val)
436    {
437        static_cast<BillboardParticleRenderer*>(target)->setCommonDirection(
438            StringConverter::parseVector3(val));
439    }
440    //-----------------------------------------------------------------------
441    String BillboardParticleRenderer::CmdCommonUpVector::doGet(const void* target) const
442    {
443        return StringConverter::toString(
444            static_cast<const BillboardParticleRenderer*>(target)->getCommonUpVector() );
445    }
446    void BillboardParticleRenderer::CmdCommonUpVector::doSet(void* target, const String& val)
447    {
448        static_cast<BillboardParticleRenderer*>(target)->setCommonUpVector(
449            StringConverter::parseVector3(val));
450    }
451    //-----------------------------------------------------------------------
452    String BillboardParticleRenderer::CmdPointRendering::doGet(const void* target) const
453    {
454        return StringConverter::toString(
455            static_cast<const BillboardParticleRenderer*>(target)->isPointRenderingEnabled() );
456    }
457    void BillboardParticleRenderer::CmdPointRendering::doSet(void* target, const String& val)
458    {
459        static_cast<BillboardParticleRenderer*>(target)->setPointRenderingEnabled(
460            StringConverter::parseBool(val));
461    }
462        //-----------------------------------------------------------------------
463        String BillboardParticleRenderer::CmdAccurateFacing::doGet(const void* target) const
464        {
465                return StringConverter::toString(
466                        static_cast<const BillboardParticleRenderer*>(target)->getUseAccurateFacing() );
467        }
468        void BillboardParticleRenderer::CmdAccurateFacing::doSet(void* target, const String& val)
469        {
470                static_cast<BillboardParticleRenderer*>(target)->setUseAccurateFacing(
471                        StringConverter::parseBool(val));
472        }
473
474}
475
Note: See TracBrowser for help on using the repository browser.