Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/include/OgreRibbonTrail.h @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

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