Coverage Report

Created: 2025-07-11 06:33

/src/ogre/OgreMain/include/OgreBillboard.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
-----------------------------------------------------------------------------
3
This source file is part of OGRE
4
    (Object-oriented Graphics Rendering Engine)
5
For the latest info, see http://www.ogre3d.org/
6
7
Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9
Permission is hereby granted, free of charge, to any person obtaining a copy
10
of this software and associated documentation files (the "Software"), to deal
11
in the Software without restriction, including without limitation the rights
12
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
copies of the Software, and to permit persons to whom the Software is
14
furnished to do so, subject to the following conditions:
15
16
The above copyright notice and this permission notice shall be included in
17
all copies or substantial portions of the Software.
18
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
THE SOFTWARE.
26
-----------------------------------------------------------------------------
27
*/
28
29
#ifndef __Billboard_H__
30
#define __Billboard_H__
31
32
#include "OgrePrerequisites.h"
33
34
#include "OgreColourValue.h"
35
#include "OgreCommon.h"
36
#include "OgreHeaderPrefix.h"
37
#include "OgreMath.h"
38
#include "OgreVector.h"
39
40
namespace Ogre {
41
    /** \addtogroup Core
42
    *  @{
43
    */
44
    /** \addtogroup Effects
45
    *  @{
46
    */
47
48
    /** A billboard is a primitive which always faces the camera in every frame.
49
50
        Billboards can be used for special effects or some other trickery which requires the
51
        triangles to always facing the camera no matter where it is. Ogre groups billboards into
52
        sets for efficiency, so you should never create a billboard on it's own (it's ok to have a
53
        set of one if you need it).
54
        @par
55
            Billboards have their geometry generated every frame depending on where the camera is. It is most
56
            beneficial for all billboards in a set to be identically sized since Ogre can take advantage of this and
57
            save some calculations - useful when you have sets of hundreds of billboards as is possible with special
58
            effects. You can deviate from this if you wish (example: a smoke effect would probably have smoke puffs
59
            expanding as they rise, so each billboard will legitimately have it's own size) but be aware the extra
60
            overhead this brings and try to avoid it if you can.
61
        @par
62
            Billboards are just the mechanism for rendering a range of effects such as particles. It is other classes
63
            which use billboards to create their individual effects, so the methods here are quite generic.
64
        @see
65
            BillboardSet
66
    */
67
68
    class _OgreExport Billboard : public FXAlloc
69
    {
70
        friend class BillboardSet;
71
        friend class BillboardParticleRenderer;
72
    private:
73
        bool mOwnDimensions;
74
        bool mUseTexcoordRect;
75
        uint16 mTexcoordIndex;      /// Index into the BillboardSet array of texture coordinates
76
        FloatRect mTexcoordRect;    /// Individual texture coordinates
77
        float mWidth;
78
        float mHeight;
79
    public:
80
        // Note the intentional public access to main internal variables used at runtime
81
        // Forcing access via get/set would be too costly for 000's of billboards
82
        Vector3 mPosition;
83
        /// Normalised direction vector
84
        Vector3 mDirection;
85
        RGBA mColour;
86
        Radian mRotation;
87
88
        /** Default constructor.
89
        */
90
        Billboard();
91
92
        /** Default destructor.
93
        */
94
        ~Billboard();
95
96
        /** Normal constructor as called by BillboardSet.
97
        */
98
        Billboard(const Vector3& position, BillboardSet* owner, const ColourValue& colour = ColourValue::White);
99
100
        /** Get the rotation of the billboard.
101
102
            This rotation is relative to the center of the billboard.
103
        */
104
0
        const Radian& getRotation(void) const { return mRotation; }
105
106
        /** Set the rotation of the billboard.
107
108
            @copydetails getRotation
109
        */
110
0
        void setRotation(const Radian& rotation) { mRotation = rotation; }
111
112
        /** Set the position of the billboard.
113
114
            This position is relative to a point on the quad which is the billboard. Depending on the BillboardSet,
115
            this may be the center of the quad, the top-left etc. See BillboardSet::setBillboardOrigin for more info.
116
        */
117
0
        void setPosition(const Vector3& position) { mPosition = position; }
118
119
        /// @overload
120
0
        void setPosition(Real x, Real y, Real z) { setPosition({x, y, z}); }
121
122
        /** Get the position of the billboard.
123
124
            @copydetails setPosition
125
        */
126
0
        const Vector3& getPosition(void) const { return mPosition; }
127
128
        /** Sets the width and height for this billboard.
129
130
            Note that it is most efficient for every billboard in a BillboardSet to have the same dimensions. If you
131
            choose to alter the dimensions of an individual billboard the set will be less efficient. Do not call
132
            this method unless you really need to have different billboard dimensions within the same set. Otherwise
133
            just call the BillboardSet::setDefaultDimensions method instead.
134
        */
135
        void setDimensions(float width, float height);
136
137
        /** Resets this Billboard to use the parent BillboardSet's dimensions instead of it's own. */
138
0
        void resetDimensions(void) { mOwnDimensions = false; }
139
        /** Sets the colour of this billboard.
140
141
            Billboards can be tinted based on a base colour. This allows variations in colour irrespective of the
142
            base colour of the material allowing more varied billboards. The default colour is white.
143
            The tinting is effected using vertex colours.
144
        */
145
0
        void setColour(const ColourValue& colour) { mColour = colour.getAsBYTE(); }
146
147
        /** Gets the colour of this billboard.
148
        */
149
0
        ColourValue getColour(void) const { return ColourValue((const uchar*)&mColour); }
150
151
        /** Returns true if this billboard deviates from the BillboardSet's default dimensions (i.e. if the
152
            Billboard::setDimensions method has been called for this instance).
153
            @see
154
                Billboard::setDimensions
155
        */
156
0
        bool hasOwnDimensions(void) const { return mOwnDimensions; }
157
158
        /** Retrieves the billboard's personal width, if hasOwnDimensions is true. */
159
0
        float getOwnWidth(void) const { return mWidth; }
160
161
        /** Retrieves the billboard's personal height, if hasOwnDimensions is true. */
162
0
        float getOwnHeight(void) const { return mHeight; }
163
164
        /** Returns true if this billboard use individual texture coordinate rect (i.e. if the 
165
            Billboard::setTexcoordRect() method has been called for this instance), or returns
166
            false if use texture coordinates defined in the parent BillboardSet's texture
167
            coordinates array (i.e. if the Billboard::setTexcoordIndex() method has been called
168
            for this instance).
169
        */
170
0
        bool isUseTexcoordRect(void) const { return mUseTexcoordRect; }
171
172
        /** setTexcoordIndex() sets which texture coordinate rect this billboard will use 
173
            when rendering. The parent billboard set may contain more than one, in which 
174
            case a billboard can be textured with different pieces of a larger texture 
175
            sheet very efficiently.
176
          @see
177
            BillboardSet::setTextureCoords()
178
          */
179
        void setTexcoordIndex(uint16 texcoordIndex);
180
181
        /** getTexcoordIndex() returns the previous value set by setTexcoordIndex(). 
182
            The default value is 0, which is always a valid texture coordinate set.
183
184
            This value is useful only when isUseTexcoordRect return false.
185
          */
186
0
        uint16 getTexcoordIndex(void) const { return mTexcoordIndex; }
187
188
        /** sets the individual texture coordinate rect of this billboard will use when rendering.
189
            The parent billboard set may contain more than one, in
190
            which case a billboard can be textured with different pieces of a larger texture
191
            sheet very efficiently.
192
        */
193
        void setTexcoordRect(const FloatRect& texcoordRect);
194
195
        /// @overload
196
0
        void setTexcoordRect(float u0, float v0, float u1, float v1) { setTexcoordRect({u0, v0, u1, v1}); }
197
198
        /** getTexcoordRect() returns the previous value set by setTexcoordRect(). 
199
200
            This value is useful only when isUseTexcoordRect returns true.
201
        */
202
0
        const FloatRect& getTexcoordRect(void) const { return mTexcoordRect; }
203
    };
204
205
    /** @} */
206
    /** @} */
207
208
}
209
210
#include "OgreHeaderSuffix.h"
211
212
#endif