OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreBillboardSet.h
Go to the documentation of this file.
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 __BillboardSet_H__
30 #define __BillboardSet_H__
31 
32 #include "OgrePrerequisites.h"
33 
34 #include "OgreMovableObject.h"
35 #include "OgreRenderable.h"
36 #include "OgreRadixSort.h"
37 #include "OgreCommon.h"
39 #include "OgreRenderQueue.h"
40 #include "OgreHeaderPrefix.h"
41 
42 namespace Ogre {
56  {
66  };
69  {
74  };
77  {
88  };
89 
112  {
113  protected:
118 
123 
128 
131 
134 
137 
140 
143 
147 
157 
166 
172 
178  float* mLockPtr;
182  Vector3 mVOffset[4];
184  Real mLeftOff, mRightOff, mTopOff, mBottomOff;
186  Vector3 mCamX, mCamY;
193 
196 
199 
202 
205 
210 
212  inline bool billboardVisible(const Camera* cam, const Billboard& bill);
213 
215  unsigned short mNumVisibleBillboards;
216 
218  virtual void increasePool(size_t size);
219 
220 
221  //-----------------------------------------------------------------------
222  // The internal methods which follow are here to allow maximum flexibility as to
223  // when various components of the calculation are done. Depending on whether the
224  // billboards are of fixed size and whether they are point or oriented type will
225  // determine how much calculation has to be done per-billboard. NOT a one-size fits all approach.
226  //-----------------------------------------------------------------------
231  void genBillboardAxes(Vector3* pX, Vector3 *pY, const Billboard* pBill = 0);
232 
235  void getParametricOffsets(Real& left, Real& right, Real& top, Real& bottom);
236 
241  void genVertices(const Vector3* const offsets, const Billboard& pBillboard);
242 
250  void genVertOffsets(Real inleft, Real inright, Real intop, Real inbottom,
251  Real width, Real height,
252  const Vector3& x, const Vector3& y, Vector3* pDestVec);
253 
254 
257  {
260 
261  SortByDirectionFunctor(const Vector3& dir);
262  float operator()(Billboard* bill) const;
263  };
264 
267  {
270 
271  SortByDistanceFunctor(const Vector3& pos);
272  float operator()(Billboard* bill) const;
273  };
274 
276 
279 
280 
281 
282  private:
286  size_t mPoolSize;
293 
296  void _createBuffers(void);
299  void _destroyBuffers(void);
300 
301  public:
302 
322  BillboardSet( IdType id, ObjectMemoryManager *objectMemoryManager,
323  unsigned int poolSize = 20, bool externalDataSource = false,
324  uint8 renderQueueId=RENDER_QUEUE_MAIN );
325 
326  virtual ~BillboardSet();
327 
345  Billboard* createBillboard(
346  const Vector3& position,
347  const ColourValue& colour = ColourValue::White );
348 
370  Billboard* createBillboard(
371  Real x, Real y, Real z,
372  const ColourValue& colour = ColourValue::White );
373 
376  virtual int getNumBillboards(void) const;
377 
393  virtual void setAutoextend(bool autoextend);
394 
399  virtual bool getAutoextend(void) const;
400 
404  virtual void setSortingEnabled(bool sortenable);
405 
410  virtual bool getSortingEnabled(void) const;
411 
422  virtual void setPoolSize(size_t size);
423 
430  virtual unsigned int getPoolSize(void) const;
431 
432 
435  virtual void clear();
436 
448  virtual Billboard* getBillboard(unsigned int index) const;
449 
454  virtual void removeBillboard(unsigned int index);
455 
460  virtual void removeBillboard(Billboard* pBill);
461 
473  virtual void setBillboardOrigin(BillboardOrigin origin);
474 
479  virtual BillboardOrigin getBillboardOrigin(void) const;
480 
490  virtual void setBillboardRotationType(BillboardRotationType rotationType);
491 
496  virtual BillboardRotationType getBillboardRotationType(void) const;
497 
508  virtual void setDefaultDimensions(Real width, Real height);
509 
511  virtual void setDefaultWidth(Real width);
513  virtual Real getDefaultWidth(void) const;
515  virtual void setDefaultHeight(Real height);
517  virtual Real getDefaultHeight(void) const;
518 
523  virtual void setMaterialName( const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
524 
528  virtual const String& getMaterialName(void) const;
529 
534  virtual void _notifyCurrentCamera(Camera* cam);
535 
541  void beginBillboards(size_t numBillboards = 0);
543  void injectBillboard(const Billboard& bb, const Camera *camera);
545  void endBillboards(void);
551  void setBounds(const Aabb& aabb, Real radius);
552 
557  virtual void _updateRenderQueue(RenderQueue* queue, Camera *camera, const Camera *lodCamera);
558 
563  virtual const MaterialPtr& getMaterial(void) const;
564 
569  virtual void setMaterial( const MaterialPtr& material );
570 
575  virtual void getRenderOperation(RenderOperation& op);
576 
581  virtual void getWorldTransforms(Matrix4* xform) const;
582 
585  virtual void _notifyBillboardResized(void);
586 
589  virtual void _notifyBillboardRotated(void);
590 
592  virtual bool getCullIndividually(void) const;
613  virtual void setCullIndividually(bool cullIndividual);
614 
635  virtual void setBillboardType(BillboardType bbt);
636 
638  virtual BillboardType getBillboardType(void) const;
639 
654  virtual void setCommonDirection(const Vector3& vec);
655 
657  virtual const Vector3& getCommonDirection(void) const;
658 
673  virtual void setCommonUpVector(const Vector3& vec);
674 
676  virtual const Vector3& getCommonUpVector(void) const;
677 
691  virtual void setUseAccurateFacing(bool acc) { mAccurateFacing = acc; }
696  virtual bool getUseAccurateFacing(void) const { return mAccurateFacing; }
697 
699  virtual const String& getMovableType(void) const;
700 
702  Real getSquaredViewDepth(const Camera* cam) const;
703 
705  virtual void _updateBounds(void);
707  const LightList& getLights(void) const;
708 
710  void visitRenderables(Renderable::Visitor* visitor,
711  bool debugRenderables = false);
712 
714  virtual void _sortBillboards( Camera* cam);
715 
717  virtual SortMode _getSortMode(void) const;
718 
724  virtual void setBillboardsInWorldSpace(bool ws) { mWorldSpace = ws; }
725 
728  bool getBillboardsInWorldSpace() { return mWorldSpace; }
729 
757  virtual void setTextureCoords( Ogre::FloatRect const * coords, uint16 numCoords );
758 
772  virtual void setTextureStacksAndSlices( uchar stacks, uchar slices );
773 
780  virtual Ogre::FloatRect const * getTextureCoords( uint16 * oNumCoords );
781 
810  virtual void setPointRenderingEnabled(bool enabled);
811 
813  virtual bool isPointRenderingEnabled(void) const
814  { return mPointRendering; }
815 
825  void setAutoUpdate(bool autoUpdate);
826 
828  bool getAutoUpdate(void) const { return mAutoUpdate; }
829 
834  void notifyBillboardDataChanged(void) { mBillboardDataChanged = true; }
835 
836  };
837 
840  {
841  protected:
842  virtual MovableObject* createInstanceImpl( IdType id, ObjectMemoryManager *objectMemoryManager,
843  const NameValuePairList* params = 0 );
844  public:
847 
849 
850  const String& getType(void) const;
851  void destroyInstance( MovableObject* obj);
852 
853  };
857 } // namespace Ogre
858 
859 #include "OgreHeaderSuffix.h"
860 
861 #endif // __BillboardSet_H__
Factory object for creating BillboardSet instances.
unsigned char uint8
Definition: OgrePlatform.h:422
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:82
Real mDefaultHeight
Default height of each billboard.
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
VertexData * mVertexData
The vertex position data for all billboards in this set.
float Real
Software floating point type.
#define _OgreExport
Definition: OgrePlatform.h:255
bool getBillboardsInWorldSpace()
Gets whether billboards are treated as being in world space.
bool mAccurateFacing
Use 'true' billboard to cam position facing, rather than camera direcion.
map< String, String >::type NameValuePairList
Name / value parameter pair (first = name, second = value)
Definition: OgreCommon.h:580
Class for performing a radix sort (fast comparison-less sort based on byte value) on various standard...
Definition: OgreRadixSort.h:88
Vector3 sortPos
Position to sort in.
Vector3 sortDir
Direction to sort in.
Class representing colour.
bool mExternalData
Is external billboard data in use?
Vector3 mCamDir
Camera direction in billboard space.
Rotate the billboard's texture coordinates.
Billboards are oriented around a shared direction vector (used as Y axis) and only rotate around this...
static const ColourValue White
bool mBuffersCreated
Flag indicating whether the HW buffers have been created.
ActiveBillboardList mActiveBillboards
Active billboard list.
list< Billboard * >::type ActiveBillboardList
static String AUTODETECT_RESOURCE_GROUP_NAME
Special resource group name which causes resource group to be automatically determined based on searc...
bool mPointRendering
Use point rendering?
BillboardRotationType
The rotation type of billboard.
String mMaterialName
Name of the material to use.
Shared pointer implementation used to share vertex buffers.
bool getAutoUpdate(void) const
Return the auto update state of this billboard set.
Vector3 mCommonDirection
Common direction for billboards of type BBT_ORIENTED_COMMON and BBT_PERPENDICULAR_COMMON.
TextureCoordSets mTextureCoords
Interface definition for a factory class which produces a certain kind of MovableObject, and can be registered with Root in order to allow all clients to produce new instances of this object, integrated with the standard Ogre processing.
bool mAllDefaultSize
True if no billboards in this set have been resized - greater efficiency.
BillboardPool mBillboardPool
Pool of billboard instances for use and reuse in the active billboard list.
Wrap-around class that contains multiple ArrayMemoryManager, one per render queue.
Abstract class defining a movable object in a scene.
Billboards are perpendicular to a shared direction vector (used as Z axis, the facing direction) and ...
bool mSortingEnabled
Flag indicating whether the billboards has to be sorted.
unsigned short mNumVisibleBillboards
Number of visible billboards (will be == getNumBillboards if mCullIndividual == false) ...
Abstract class defining the interface all renderable objects must implement.
Implementation of a Quaternion, i.e.
A collection of billboards (faces which are always facing the given direction) with the same (default...
FreeBillboardList mFreeBillboards
Free billboard queue.
size_t mPoolSize
The number of billboard in the pool.
Quaternion mCamQ
Camera orientation in billboard space.
virtual bool getUseAccurateFacing(void) const
Gets whether or not billboards use an 'accurate' facing model based on the vector from each billboard...
Rotate the billboard's vertices around their facing direction.
Ogre::uint32 IdType
Big projects with lots, lots of units for very long periods of time (MMORPGs?) may want to define thi...
Definition: OgreId.h:36
unsigned char uchar
In order to avoid finger-aches :)
SortMode
Sort mode for billboard-set and particle-system.
Definition: OgreCommon.h:231
Billboards are perpendicular to their own direction vector (their own Z axis, the facing direction) a...
IndexData * mIndexData
The vertex index data for all billboards in this set (1 set only)
Summary class collecting together index data source information.
AoS (array of structures) version of ArrayAabb.
Definition: C/OgreAabb.h:78
virtual bool isPointRenderingEnabled(void) const
Returns whether point rendering is enabled.
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
bool mAutoUpdate
Tell if vertex buffer should be update automatically.
Vector3 mCommonUpVector
Common up-vector for billboards of type BBT_PERPENDICULAR_SELF and BBT_PERPENDICULAR_COMMON.
float * mLockPtr
Locked pointer to buffer.
HardwareVertexBufferSharedPtr mMainBuf
Shortcut to main buffer (positions, colours, texture coords)
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
bool mBillboardDataChanged
True if the billboard data changed. Will cause vertex buffer update.
virtual void setUseAccurateFacing(bool acc)
Sets whether or not billboards should use an 'accurate' facing model based on the vector from each bi...
Standard point billboard (default), always faces the camera completely and is always upright...
Summary class collecting together vertex source information.
'New' rendering operation using vertex buffers.
BillboardType mBillboardType
The type of billboard to render.
void notifyBillboardDataChanged(void)
When billboard set is not auto updating its GPU buffer, the user is responsible to inform it about an...
Class to manage the scene object rendering queue.
bool mAutoExtendPool
Flag indicating whether to autoextend pool.
BillboardOrigin
Enum covering what exactly a billboard's position means (center, top-left etc).
vector< Billboard * >::type BillboardPool
A billboard is a primitive which always faces the camera in every frame.
Definition: OgreBillboard.h:66
Billboards are oriented around their own direction vector (their own Y axis) and only rotate around t...
The default render queue.
_StringBase String
Definition: OgreCommon.h:53
BillboardRotationType mRotationType
Rotation type of each billboard.
list< Billboard * >::type FreeBillboardList
unsigned short uint16
Definition: OgrePlatform.h:421
Vector3 mCamPos
Camera position in billboard space.
vector< Ogre::FloatRect >::type TextureCoordSets
BillboardOrigin mOriginType
Origin of each billboard.
virtual void setBillboardsInWorldSpace(bool ws)
Sets whether billboards should be treated as being in world space.
bool mCullIndividual
Flag indicating whether each billboard should be culled separately (default: false) ...
MaterialPtr mMaterial
Pointer to the material to use.
static RadixSort< ActiveBillboardList, Billboard *, float > mRadixSorter
Real mDefaultWidth
Default width of each billboard.
BillboardType
The type of billboard to use.