source: OGRE/trunk/ogre_changes/Ogre1.2/OgreMain/include/OgreBillboard.h @ 768

Revision 768, 9.8 KB checked in by szirmay, 18 years ago (diff)
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
26#ifndef __Billboard_H__
27#define __Billboard_H__
28
29#include "OgrePrerequisites.h"
30
31#include "OgreVector3.h"
32#include "OgreColourValue.h"
33#include "OgreCommon.h"
34
35namespace Ogre {
36
37    /** A billboard is a primitive which always faces the camera in every frame.
38        @remarks
39            Billboards can be used for special effects or some other trickery which requires the
40            triangles to always facing the camera no matter where it is. Ogre groups billboards into
41            sets for efficiency, so you should never create a billboard on it's own (it's ok to have a
42            set of one if you need it).
43        @par
44            Billboards have their geometry generated every frame depending on where the camera is. It is most
45            beneficial for all billboards in a set to be identically sized since Ogre can take advantage of this and
46            save some calculations - useful when you have sets of hundreds of billboards as is possible with special
47            effects. You can deviate from this if you wish (example: a smoke effect would probably have smoke puffs
48            expanding as they rise, so each billboard will legitimately have it's own size) but be aware the extra
49            overhead this brings and try to avoid it if you can.
50        @par
51            Billboards are just the mechanism for rendering a range of effects such as particles. It is other classes
52            which use billboards to create their individual effects, so the methods here are quite generic.
53        @see
54            BillboardSet
55    */
56
57    class _OgreExport Billboard
58    {
59        friend class BillboardSet;
60        friend class BillboardParticleRenderer;
61
62#ifdef GAMETOOLS_ILLUMINATION_MODULE
63                friend class SpriteSet;
64        friend class SpriteParticleRenderer;
65#endif
66
67    protected:
68        bool mOwnDimensions;
69        bool mUseTexcoordRect;
70        uint16 mTexcoordIndex;      // index into the BillboardSet array of texture coordinates
71        FloatRect mTexcoordRect;    // individual texture coordinates
72        Real mWidth;
73        Real mHeight;
74    public:
75        // Note the intentional public access to main internal variables used at runtime
76        // Forcing access via get/set would be too costly for 000's of billboards
77        Vector3 mPosition;
78        // Normalised direction vector
79        Vector3 mDirection;
80        BillboardSet* mParentSet;
81        ColourValue mColour;
82        Radian mRotation;
83
84        /** Default constructor.
85        */
86        Billboard();
87
88        /** Default destructor.
89        */
90        ~Billboard();
91
92        /** Normal constructor as called by BillboardSet.
93        */
94        Billboard(const Vector3& position, BillboardSet* owner, const ColourValue& colour = ColourValue::White);
95
96        /** Get the rotation of the billboard.
97            @remarks
98                This rotation is relative to the center of the billboard.
99        */
100        const Radian& getRotation(void) const { return mRotation; }
101
102        /** Set the rotation of the billboard.
103            @remarks
104                This rotation is relative to the center of the billboard.
105        */
106        void setRotation(const Radian& rotation);
107
108        /** Set the position of the billboard.
109            @remarks
110                This position is relative to a point on the quad which is the billboard. Depending on the BillboardSet,
111                this may be the center of the quad, the top-left etc. See BillboardSet::setBillboardOrigin for more info.
112        */
113        void setPosition(const Vector3& position);
114
115        /** Set the position of the billboard.
116            @remarks
117                This position is relative to a point on the quad which is the billboard. Depending on the BillboardSet,
118                this may be the center of the quad, the top-left etc. See BillboardSet::setBillboardOrigin for more info.
119        */
120        void setPosition(Real x, Real y, Real z);
121
122        /** Get the position of the billboard.
123            @remarks
124                This position is relative to a point on the quad which is the billboard. Depending on the BillboardSet,
125                this may be the center of the quad, the top-left etc. See BillboardSet::setBillboardOrigin for more info.
126        */
127        const Vector3& getPosition(void) const;
128
129        /** Sets the width and height for this billboard.
130            @remarks
131                Note that it is most efficient for every billboard in a BillboardSet to have the same dimensions. If you
132                choose to alter the dimensions of an individual billboard the set will be less efficient. Do not call
133                this method unless you really need to have different billboard dimensions within the same set. Otherwise
134                just call the BillboardSet::setDefaultDimensions method instead.
135        */
136        void setDimensions(Real width, Real height);
137
138        /** Resets this Billboard to use the parent BillboardSet's dimensions instead of it's own. */
139        void resetDimensions(void) { mOwnDimensions = false; }
140        /** Sets the colour of this billboard.
141            @remarks
142                Billboards can be tinted based on a base colour. This allows variations in colour irresective of the
143                base colour of the material allowing more varied billboards. The default colour is white.
144                The tinting is effected using vertex colours.
145        */
146        void setColour(const ColourValue& colour);
147
148        /** Gets the colour of this billboard.
149        */
150        const ColourValue& getColour(void) const;
151
152        /** Returns true if this billboard deviates from the BillboardSet's default dimensions (i.e. if the
153            Billboard::setDimensions method has been called for this instance).
154            @see
155                Billboard::setDimensions
156        */
157        bool hasOwnDimensions(void) const;
158
159        /** Retrieves the billboard's personal width, if hasOwnDimensions is true. */
160        Real getOwnWidth(void) const;
161
162        /** Retrieves the billboard's personal width, if hasOwnDimensions is true. */
163        Real getOwnHeight(void) const;
164
165        /** Internal method for notifying the billboard of it's owner.
166        */
167        void _notifyOwner(BillboardSet* owner);
168
169        /** Returns true if this billboard use individual texture coordinate rect (i.e. if the
170            Billboard::setTexcoordRect method has been called for this instance), or returns
171            false if use texture coordinates defined in the parent BillboardSet's texture
172            coordinates array (i.e. if the Billboard::setTexcoordIndex method has been called
173            for this instance).
174            @see
175                Billboard::setTexcoordIndex()
176                Billboard::setTexcoordRect()
177        */
178        bool isUseTexcoordRect(void) const { return mUseTexcoordRect; }
179
180        /** setTexcoordIndex() sets which texture coordinate rect this billboard will use
181            when rendering. The parent billboard set may contain more than one, in which
182            case a billboard can be textured with different pieces of a larger texture
183            sheet very efficiently.
184          @see
185            BillboardSet::setTextureCoords()
186          */
187        void setTexcoordIndex(uint16 texcoordIndex);
188
189        /** getTexcoordIndex() returns the previous value set by setTexcoordIndex().
190            The default value is 0, which is always a valid texture coordinate set.
191            @remarks
192                This value is useful only when isUseTexcoordRect return false.
193          */
194        uint16 getTexcoordIndex(void) const { return mTexcoordIndex; }
195
196        /** setTexcoordRect() sets the individual texture coordinate rect of this billboard
197            will use when rendering. The parent billboard set may contain more than one, in
198            which case a billboard can be textured with different pieces of a larger texture
199            sheet very efficiently.
200        */
201        void setTexcoordRect(const FloatRect& texcoordRect);
202
203        /** setTexcoordRect() sets the individual texture coordinate rect of this billboard
204            will use when rendering. The parent billboard set may contain more than one, in
205            which case a billboard can be textured with different pieces of a larger texture
206            sheet very efficiently.
207        */
208        void setTexcoordRect(Real u0, Real v0, Real u1, Real v1);
209
210        /** getTexcoordRect() returns the previous value set by setTexcoordRect().
211            @remarks
212                This value is useful only when isUseTexcoordRect return true.
213        */
214        const FloatRect& getTexcoordRect(void) const { return mTexcoordRect; }
215    };
216
217}
218
219#endif
Note: See TracBrowser for help on using the repository browser.