source: GTP/trunk/Lib/Geom/OgreStuff/include/OgreRibbonTrail.h @ 1809

Revision 1809, 8.4 KB checked in by gumbau, 18 years ago (diff)
RevLine 
[1809]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
26#ifndef __RibbonTrail_H__
27#define __RibbonTrail_H__
28
29#include "OgrePrerequisites.h"
30
31#include "OgreBillboardChain.h"
32#include "OgreNode.h"
33#include "OgreIteratorWrappers.h"
34#include "OgreFrameListener.h"
35#include "OgreControllerManager.h"
36
37namespace Ogre {
38
39        /** Subclass of BillboardChain which automatically leaves a trail behind
40                one or more Node instances.
41        @remarks
42                An instance of this class will watch one or more Node instances, and
43                automatically generate a trail behind them as they move. Because this
44                class can monitor multiple modes, it generates its own geometry in
45                world space and thus, even though it has to be attached to a SceneNode
46                to be visible, changing the position of the scene node it is attached to
47                makes no difference to the geometry rendered.
48        @par
49                The 'head' element grows smoothly in size until it reaches the required size,
50                then a new element is added. If the segment is full, the tail element
51                shrinks by the same proportion as the head grows before disappearing.
52        @par
53                Elements can be faded out on a time basis, either by altering their colour
54                or altering their alpha. The width can also alter over time.
55        @par
56                'v' texture coordinates are fixed at 0.0 if used, meaning that you can
57                use a 1D texture to 'smear' a colour pattern along the ribbon if you wish.
58                The 'u' coordinates are by default (0.0, 1.0), but you can alter this
59                using setOtherTexCoordRange if you wish.
60        */
61        class _OgreExport RibbonTrail : public BillboardChain, public Node::Listener
62        {
63        public:
64                /** Constructor (don't use directly, use factory)
65                @param name The name to give this object
66                @param maxElements The maximum number of elements per chain
67                @param numberOfChains The number of separate chain segments contained in this object,
68                        ie the maximum number of nodes that can have trails attached
69                @param useTextureCoords If true, use texture coordinates from the chain elements
70                @param useVertexColours If true, use vertex colours from the chain elements (must
71                        be true if you intend to use fading)
72                */
73                RibbonTrail(const String& name, size_t maxElements = 20, size_t numberOfChains = 1,
74                        bool useTextureCoords = true, bool useColours = true);
75                /// destructor
76                virtual ~RibbonTrail();
77
78                typedef std::vector<Node*> NodeList;
79                typedef ConstVectorIterator<NodeList> NodeIterator;
80
81                /** Add a node to be tracked.
82                @param n The node that will be tracked.
83                */
84                virtual void addNode(Node* n);
85                /** Remove tracking on a given node. */
86                virtual void removeNode(Node* n);
87                /** Get an iterator over the nodes which are being tracked. */
88                virtual NodeIterator getNodeIterator(void) const;
89
90                /** Set the length of the trail.
91                @remarks
92                        This sets the length of the trail, in world units. It also sets how
93                        far apart each segment will be, ie length / max_elements.
94                @param len The length of the trail in world units
95                */
96                virtual void setTrailLength(Real len);
97                /** Get the length of the trail. */
98                virtual Real getTrailLength(void) const { return mTrailLength; }
99
100                /** @copydoc BillboardChain::setMaxChainElements */
101                void setMaxChainElements(size_t maxElements);
102                /** @copydoc BillboardChain::setNumberOfChains */
103                void setNumberOfChains(size_t numChains);
104                /** @copydoc BillboardChain::clearChain */
105                void clearChain(size_t chainIndex);
106
107                /** Set the starting ribbon colour for a given segment.
108                @param chainIndex The index of the chain
109                @param col The initial colour
110                @note
111                        Only used if this instance is using vertex colours.
112                */
113                virtual void setInitialColour(size_t chainIndex, const ColourValue& col);
114                /** Set the starting ribbon colour.
115                @param chainIndex The index of the chain
116                @param r,b,g,a The initial colour
117                @note
118                        Only used if this instance is using vertex colours.
119                */
120                virtual void setInitialColour(size_t chainIndex, Real r, Real g, Real b, Real a = 1.0);
121                /** Get the starting ribbon colour. */
122                virtual const ColourValue& getInitialColour(size_t chainIndex) const;
123
124                /** Enables / disables fading the trail using colour.
125                @param chainIndex The index of the chain
126                @param valuePerSecond The amount to subtract from colour each second
127                */
128                virtual void setColourChange(size_t chainIndex, const ColourValue& valuePerSecond);
129
130                /** Set the starting ribbon width in world units.
131                @param chainIndex The index of the chain
132                @param width The initial width of the ribbon
133                */
134                virtual void setInitialWidth(size_t chainIndex, Real width);
135                /** Get the starting ribbon width in world units. */
136                virtual Real getInitialWidth(size_t chainIndex) const;
137               
138                /** Set the change in ribbon width per second.
139                @param chainIndex The index of the chain
140                @param widthDeltaPerSecond The amount the width will reduce by per second
141                */
142                virtual void setWidthChange(size_t chainIndex, Real widthDeltaPerSecond);
143                /** Get the change in ribbon width per second. */
144                virtual Real getWidthChange(size_t chainIndex) const;
145
146                /** Enables / disables fading the trail using colour.
147                @param chainIndex The index of the chain
148                @param r,g,b,a The amount to subtract from each colour channel per second
149                */
150                virtual void setColourChange(size_t chainIndex, Real r, Real g, Real b, Real a);
151
152                /** Get the per-second fading amount */
153                virtual const ColourValue& getColourChange(size_t chainIndex) const;
154
155                /// @see Node::Listener::nodeUpdated
156                void nodeUpdated(const Node* node);
157                /// @see Node::Listener::nodeDestroyed
158                void nodeDestroyed(const Node* node);
159
160                /// Perform any fading / width delta required; internal method
161                virtual void _timeUpdate(Real time);
162
163        /** Overridden from MovableObject */
164        const String& getMovableType(void) const;
165
166        protected:
167                /// List of nodes being trailed
168                NodeList mNodeList;
169                /// Total length of trail in world units
170                Real mTrailLength;
171                /// length of each element
172                Real mElemLength;
173                /// Squared length of each element
174                Real mSquaredElemLength;
175                typedef std::vector<ColourValue> ColourValueList;
176                typedef std::vector<Real> RealList;
177                /// Initial colour of the ribbon
178                ColourValueList mInitialColour;
179                /// fade amount per second
180                ColourValueList mDeltaColour;
181                /// Initial width of the ribbon
182                RealList mInitialWidth;
183                /// Delta width of the ribbon
184                RealList mDeltaWidth;
185                /// controller used to hook up frame time to fader
186                Controller<Real>* mFadeController;
187                /// controller value for hooking up frame time to fader
188                ControllerValueRealPtr mTimeControllerValue;
189
190                /// Manage updates to the time controller
191                virtual void manageController(void);
192                /// Node has changed position, update
193                virtual void updateTrail(size_t index, const Node* node);
194        /// Reset the tracked chain to initial state
195        virtual void resetTrail(size_t index, const Node* node);
196        /// Reset all tracked chains to initial state
197        virtual void resetAllTrails(void);
198
199        };
200
201
202        /** Factory object for creating RibbonTrail instances */
203        class _OgreExport RibbonTrailFactory : public MovableObjectFactory
204        {
205        protected:
206                MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
207        public:
208                RibbonTrailFactory() {}
209                ~RibbonTrailFactory() {}
210
211                static String FACTORY_TYPE_NAME;
212
213                const String& getType(void) const;
214                void destroyInstance( MovableObject* obj); 
215
216        };
217
218}
219
220#endif
Note: See TracBrowser for help on using the repository browser.