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

Revision 657, 9.6 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

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::CmdCommonDirection BillboardParticleRenderer::msCommonDirectionCmd;
37    //-----------------------------------------------------------------------
38    BillboardParticleRenderer::BillboardParticleRenderer()
39    {
40        if (createParamDictionary("BillboardParticleRenderer"))
41        {
42            ParamDictionary* dict = getParamDictionary();
43            dict->addParameter(ParameterDef("billboard_type",
44                "The type of billboard to use. 'point' means a simulated spherical particle, "
45                "'oriented_common' means all particles in the set are oriented around common_direction, "
46                "and 'oriented_self' means particles are oriented around their own direction.",
47                PT_STRING),
48                &msBillboardTypeCmd);
49
50            dict->addParameter(ParameterDef("common_direction",
51                "Only useful when billboard_type is oriented_common. This parameter sets the common "
52                "orientation for all particles in the set (e.g. raindrops may all be oriented downwards).",
53                PT_VECTOR3),
54                &msCommonDirectionCmd);
55        }
56
57        // Create billboard set
58        mBillboardSet = new BillboardSet("", 0, true);
59        // World-relative axes
60        mBillboardSet->setBillboardsInWorldSpace(true);
61    }
62    //-----------------------------------------------------------------------
63    BillboardParticleRenderer::~BillboardParticleRenderer()
64    {
65        delete mBillboardSet;
66    }
67    //-----------------------------------------------------------------------
68    const String& BillboardParticleRenderer::getType(void) const
69    {
70        return rendererTypeName;
71    }
72    //-----------------------------------------------------------------------
73    void BillboardParticleRenderer::_updateRenderQueue(RenderQueue* queue,
74        std::list<Particle*>& currentParticles, bool cullIndividually)
75    {
76        mBillboardSet->setCullIndividually(cullIndividually);
77
78        // Update billboard set geometry
79        mBillboardSet->beginBillboards();
80        Billboard bb;
81        for (std::list<Particle*>::iterator i = currentParticles.begin();
82            i != currentParticles.end(); ++i)
83        {
84            Particle* p = *i;
85            bb.mPosition = p->position;
86            bb.mDirection = p->direction;
87            bb.mColour = p->colour;
88            bb.mRotation = p->rotation;
89            // Assign and compare at the same time
90            if (bb.mOwnDimensions = p->mOwnDimensions)
91            {
92                bb.mWidth = p->mWidth;
93                bb.mHeight = p->mHeight;
94            }
95            mBillboardSet->injectBillboard(bb);
96
97        }
98       
99        mBillboardSet->endBillboards();
100
101        // Update the queue
102        mBillboardSet->_updateRenderQueue(queue);
103    }
104    //-----------------------------------------------------------------------
105    void BillboardParticleRenderer::_setMaterial(MaterialPtr& mat)
106    {
107        mBillboardSet->setMaterialName(mat->getName());
108    }
109    //-----------------------------------------------------------------------
110    void BillboardParticleRenderer::setBillboardType(BillboardType bbt)
111    {
112        mBillboardSet->setBillboardType(bbt);
113    }
114    //-----------------------------------------------------------------------
115    BillboardType BillboardParticleRenderer::getBillboardType(void) const
116    {
117        return mBillboardSet->getBillboardType();
118    }
119    //-----------------------------------------------------------------------
120    void BillboardParticleRenderer::setCommonDirection(const Vector3& vec)
121    {
122        mBillboardSet->setCommonDirection(vec);
123    }
124    //-----------------------------------------------------------------------
125    const Vector3& BillboardParticleRenderer::getCommonDirection(void) const
126    {
127        return mBillboardSet->getCommonDirection();
128    }
129    //-----------------------------------------------------------------------
130    void BillboardParticleRenderer::_notifyCurrentCamera(Camera* cam)
131    {
132        mBillboardSet->_notifyCurrentCamera(cam);
133    }
134    //-----------------------------------------------------------------------
135    void BillboardParticleRenderer::_notifyParticleRotated(void)
136    {
137        mBillboardSet->_notifyBillboardTextureCoordsModified();
138    }
139    //-----------------------------------------------------------------------
140    void BillboardParticleRenderer::_notifyDefaultDimensions(Real width, Real height)
141    {
142        mBillboardSet->setDefaultDimensions(width, height);
143    }
144    //-----------------------------------------------------------------------
145    void BillboardParticleRenderer::_notifyParticleResized(void)
146    {
147        mBillboardSet->_notifyBillboardResized();
148    }
149    //-----------------------------------------------------------------------
150    void BillboardParticleRenderer::_notifyParticleQuota(size_t quota)
151    {
152        mBillboardSet->setPoolSize(quota);
153    }
154    //-----------------------------------------------------------------------
155    void BillboardParticleRenderer::_notifyAttached(Node* parent, bool isTagPoint)
156    {
157        mBillboardSet->_notifyAttached(parent, isTagPoint);
158    }
159        //-----------------------------------------------------------------------
160        void BillboardParticleRenderer::setRenderQueueGroup(RenderQueueGroupID queueID)
161        {
162                mBillboardSet->setRenderQueueGroup(queueID);
163        }
164    //-----------------------------------------------------------------------
165    //-----------------------------------------------------------------------
166    //-----------------------------------------------------------------------
167    const String& BillboardParticleRendererFactory::getType() const
168    {
169        return rendererTypeName;
170    }
171    //-----------------------------------------------------------------------
172    ParticleSystemRenderer* BillboardParticleRendererFactory::createInstance(
173        const String& name )
174    {
175        return new BillboardParticleRenderer();
176    }
177    //-----------------------------------------------------------------------
178    void BillboardParticleRendererFactory::destroyInstance(
179        ParticleSystemRenderer* inst)
180    {
181        delete inst;
182    }
183    //-----------------------------------------------------------------------
184    //-----------------------------------------------------------------------
185    String BillboardParticleRenderer::CmdBillboardType::doGet(const void* target) const
186    {
187        BillboardType t = static_cast<const BillboardParticleRenderer*>(target)->getBillboardType();
188        switch(t)
189        {
190        case BBT_POINT:
191            return "point";
192            break;
193        case BBT_ORIENTED_COMMON:
194            return "oriented_common";
195            break;
196        case BBT_ORIENTED_SELF:
197            return "oriented_self";
198            break;
199        }
200        // Compiler nicety
201        return "";
202    }
203    void BillboardParticleRenderer::CmdBillboardType::doSet(void* target, const String& val)
204    {
205        BillboardType t;
206        if (val == "point")
207        {
208            t = BBT_POINT;
209        }
210        else if (val == "oriented_common")
211        {
212            t = BBT_ORIENTED_COMMON;
213        }
214        else if (val == "oriented_self")
215        {
216            t = BBT_ORIENTED_SELF;
217        }
218        else
219        {
220            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
221                "Invalid billboard_type '" + val + "'",
222                "ParticleSystem::CmdBillboardType::doSet");
223        }
224
225        static_cast<BillboardParticleRenderer*>(target)->setBillboardType(t);
226    }
227    //-----------------------------------------------------------------------
228    String BillboardParticleRenderer::CmdCommonDirection::doGet(const void* target) const
229    {
230        return StringConverter::toString(
231            static_cast<const BillboardParticleRenderer*>(target)->getCommonDirection() );
232    }
233    void BillboardParticleRenderer::CmdCommonDirection::doSet(void* target, const String& val)
234    {
235        static_cast<BillboardParticleRenderer*>(target)->setCommonDirection(
236            StringConverter::parseVector3(val));
237    }
238
239}
240
Note: See TracBrowser for help on using the repository browser.