source: OGRE/trunk/ogrenew/OgreMain/include/OgreRibbonTrail.h @ 692

Revision 692, 8.0 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

RevLine 
[692]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
105                /** Set the starting ribbon colour for a given segment.
106                @param chainIndex The index of the chain
107                @param col The initial colour
108                @note
109                        Only used if this instance is using vertex colours.
110                */
111                virtual void setInitialColour(size_t chainIndex, const ColourValue& col);
112                /** Set the starting ribbon colour.
113                @param chainIndex The index of the chain
114                @param r,b,g,a The initial colour
115                @note
116                        Only used if this instance is using vertex colours.
117                */
118                virtual void setInitialColour(size_t chainIndex, Real r, Real g, Real b, Real a = 1.0);
119                /** Get the starting ribbon colour. */
120                virtual const ColourValue& getInitialColour(size_t chainIndex) const;
121
122                /** Enables / disables fading the trail using colour.
123                @param chainIndex The index of the chain
124                @param valuePerSecond The amount to subtract from colour each second
125                */
126                virtual void setColourChange(size_t chainIndex, const ColourValue& valuePerSecond);
127
128                /** Set the starting ribbon width in world units.
129                @param chainIndex The index of the chain
130                @param width The initial width of the ribbon
131                */
132                virtual void setInitialWidth(size_t chainIndex, Real width);
133                /** Get the starting ribbon width in world units. */
134                virtual Real getInitialWidth(size_t chainIndex) const;
135               
136                /** Set the change in ribbon width per second.
137                @param chainIndex The index of the chain
138                @param widthDeltaPerSecond The amount the width will reduce by per second
139                */
140                virtual void setWidthChange(size_t chainIndex, Real widthDeltaPerSecond);
141                /** Get the change in ribbon width per second. */
142                virtual Real getWidthChange(size_t chainIndex) const;
143
144                /** Enables / disables fading the trail using colour.
145                @param chainIndex The index of the chain
146                @param r,g,b,a The amount to subtract from each colour channel per second
147                */
148                virtual void setColourChange(size_t chainIndex, Real r, Real g, Real b, Real a);
149
150                /** Get the per-second fading amount */
151                virtual const ColourValue& getColourChange(size_t chainIndex) const;
152
153                /// @see Node::Listener::nodeUpdated
154                void nodeUpdated(const Node* node);
155                /// @see Node::Listener::nodeDestroyed
156                void nodeDestroyed(const Node* node);
157
158                /// Perform any fading / width delta required; internal method
159                virtual void _timeUpdate(Real time);
160
161        protected:
162                /// List of nodes being trailed
163                NodeList mNodeList;
164                /// Total length of trail in world units
165                Real mTrailLength;
166                /// length of each element
167                Real mElemLength;
168                /// Squared length of each element
169                Real mSquaredElemLength;
170                typedef std::vector<ColourValue> ColourValueList;
171                typedef std::vector<Real> RealList;
172                /// Initial colour of the ribbon
173                ColourValueList mInitialColour;
174                /// fade amount per second
175                ColourValueList mDeltaColour;
176                /// Initial width of the ribbon
177                RealList mInitialWidth;
178                /// Delta width of the ribbon
179                RealList mDeltaWidth;
180                /// controller used to hook up frame time to fader
181                Controller<Real>* mFadeController;
182                /// controller value for hooking up frame time to fader
183                ControllerValueRealPtr mTimeControllerValue;
184
185                /// Manage updates to the time controller
186                virtual void manageController(void);
187                /// Node has changed position, update
188                virtual void updateTrail(size_t index, const Node* node);
189
190
191        };
192
193
194        /** Factory object for creating RibbonTrail instances */
195        class _OgreExport RibbonTrailFactory : public MovableObjectFactory
196        {
197        protected:
198                MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
199        public:
200                RibbonTrailFactory() {}
201                ~RibbonTrailFactory() {}
202
203                static String FACTORY_TYPE_NAME;
204
205                const String& getType(void) const;
206                void destroyInstance( MovableObject* obj); 
207
208        };
209
210}
211
212#endif
Note: See TracBrowser for help on using the repository browser.