OGRE  1.9
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 "OgreHeaderPrefix.h"
40 
41 namespace Ogre {
55  {
65  };
68  {
73  };
76  {
87  };
88 
111  {
112  protected:
115  BillboardSet();
116 
121 
126 
131 
136 
139 
142 
145 
148 
151 
155 
165 
174 
180 
186  float* mLockPtr;
190  Vector3 mVOffset[4];
194  Real mLeftOff, mRightOff, mTopOff, mBottomOff;
196  Vector3 mCamX, mCamY;
203 
206 
209 
212 
215 
220 
222  inline bool billboardVisible(Camera* cam, const Billboard& bill);
223 
225  unsigned short mNumVisibleBillboards;
226 
228  virtual void increasePool(size_t size);
229 
230 
231  //-----------------------------------------------------------------------
232  // The internal methods which follow are here to allow maximum flexibility as to
233  // when various components of the calculation are done. Depending on whether the
234  // billboards are of fixed size and whether they are point or oriented type will
235  // determine how much calculation has to be done per-billboard. NOT a one-size fits all approach.
236  //-----------------------------------------------------------------------
241  void genBillboardAxes(Vector3* pX, Vector3 *pY, const Billboard* pBill = 0);
242 
245  void getParametricOffsets(Real& left, Real& right, Real& top, Real& bottom);
246 
251  void genVertices(const Vector3* const offsets, const Billboard& pBillboard);
252 
260  void genVertOffsets(Real inleft, Real inright, Real intop, Real inbottom,
261  Real width, Real height,
262  const Vector3& x, const Vector3& y, Vector3* pDestVec);
263 
264 
267  {
270 
271  SortByDirectionFunctor(const Vector3& dir);
272  float operator()(Billboard* bill) const;
273  };
274 
277  {
280 
281  SortByDistanceFunctor(const Vector3& pos);
282  float operator()(Billboard* bill) const;
283  };
284 
286 
289 
290 
291 
292  private:
296  size_t mPoolSize;
303 
306  void _createBuffers(void);
309  void _destroyBuffers(void);
310 
311  public:
312 
332  BillboardSet( const String& name, unsigned int poolSize = 20,
333  bool externalDataSource = false);
334 
335  virtual ~BillboardSet();
336 
354  Billboard* createBillboard(
355  const Vector3& position,
356  const ColourValue& colour = ColourValue::White );
357 
379  Billboard* createBillboard(
380  Real x, Real y, Real z,
381  const ColourValue& colour = ColourValue::White );
382 
385  virtual int getNumBillboards(void) const;
386 
402  virtual void setAutoextend(bool autoextend);
403 
408  virtual bool getAutoextend(void) const;
409 
413  virtual void setSortingEnabled(bool sortenable);
414 
419  virtual bool getSortingEnabled(void) const;
420 
431  virtual void setPoolSize(size_t size);
432 
439  virtual unsigned int getPoolSize(void) const;
440 
441 
444  virtual void clear();
445 
457  virtual Billboard* getBillboard(unsigned int index) const;
458 
463  virtual void removeBillboard(unsigned int index);
464 
469  virtual void removeBillboard(Billboard* pBill);
470 
482  virtual void setBillboardOrigin(BillboardOrigin origin);
483 
488  virtual BillboardOrigin getBillboardOrigin(void) const;
489 
499  virtual void setBillboardRotationType(BillboardRotationType rotationType);
500 
505  virtual BillboardRotationType getBillboardRotationType(void) const;
506 
517  virtual void setDefaultDimensions(Real width, Real height);
518 
520  virtual void setDefaultWidth(Real width);
522  virtual Real getDefaultWidth(void) const;
524  virtual void setDefaultHeight(Real height);
526  virtual Real getDefaultHeight(void) const;
527 
532  virtual void setMaterialName( const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
533 
537  virtual const String& getMaterialName(void) const;
538 
543  virtual void _notifyCurrentCamera(Camera* cam);
544 
550  void beginBillboards(size_t numBillboards = 0);
552  void injectBillboard(const Billboard& bb);
554  void endBillboards(void);
560  void setBounds(const AxisAlignedBox& box, Real radius);
561 
562 
567  virtual const AxisAlignedBox& getBoundingBox(void) const;
568 
573  virtual Real getBoundingRadius(void) const;
578  virtual void _updateRenderQueue(RenderQueue* queue);
579 
584  virtual const MaterialPtr& getMaterial(void) const;
585 
590  virtual void setMaterial( const MaterialPtr& material );
591 
596  virtual void getRenderOperation(RenderOperation& op);
597 
602  virtual void getWorldTransforms(Matrix4* xform) const;
603 
606  virtual void _notifyBillboardResized(void);
607 
610  virtual void _notifyBillboardRotated(void);
611 
613  virtual bool getCullIndividually(void) const;
634  virtual void setCullIndividually(bool cullIndividual);
635 
656  virtual void setBillboardType(BillboardType bbt);
657 
659  virtual BillboardType getBillboardType(void) const;
660 
675  virtual void setCommonDirection(const Vector3& vec);
676 
678  virtual const Vector3& getCommonDirection(void) const;
679 
694  virtual void setCommonUpVector(const Vector3& vec);
695 
697  virtual const Vector3& getCommonUpVector(void) const;
698 
712  virtual void setUseAccurateFacing(bool acc) { mAccurateFacing = acc; }
717  virtual bool getUseAccurateFacing(void) const { return mAccurateFacing; }
718 
720  virtual const String& getMovableType(void) const;
721 
723  Real getSquaredViewDepth(const Camera* cam) const;
724 
726  virtual void _updateBounds(void);
728  const LightList& getLights(void) const;
729 
731  void visitRenderables(Renderable::Visitor* visitor,
732  bool debugRenderables = false);
733 
735  virtual void _sortBillboards( Camera* cam);
736 
738  virtual SortMode _getSortMode(void) const;
739 
745  virtual void setBillboardsInWorldSpace(bool ws) { mWorldSpace = ws; }
746 
749  bool getBillboardsInWorldSpace() { return mWorldSpace; }
750 
778  virtual void setTextureCoords( Ogre::FloatRect const * coords, uint16 numCoords );
779 
793  virtual void setTextureStacksAndSlices( uchar stacks, uchar slices );
794 
801  virtual Ogre::FloatRect const * getTextureCoords( uint16 * oNumCoords );
802 
831  virtual void setPointRenderingEnabled(bool enabled);
832 
834  virtual bool isPointRenderingEnabled(void) const
835  { return mPointRendering; }
836 
838  uint32 getTypeFlags(void) const;
839 
849  void setAutoUpdate(bool autoUpdate);
850 
852  bool getAutoUpdate(void) const { return mAutoUpdate; }
853 
858  void notifyBillboardDataChanged(void) { mBillboardDataChanged = true; }
859 
860  };
861 
864  {
865  protected:
866  MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
867  public:
870 
872 
873  const String& getType(void) const;
874  void destroyInstance( MovableObject* obj);
875 
876  };
880 } // namespace Ogre
881 
882 #include "OgreHeaderSuffix.h"
883 
884 #endif // __BillboardSet_H__
Factory object for creating BillboardSet instances.
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
Real mDefaultHeight
Default height of each billboard.
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
VertexData * mVertexData
The vertex position data for all billboards in this set.
float Real
Software floating point type.
unsigned int uint32
Definition: OgrePlatform.h:344
#define _OgreExport
Definition: OgrePlatform.h:260
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:550
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.
A 3D box aligned with the x/y/z axes.
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.
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) ...
AxisAlignedBox mAABB
Bounds of all billboards in this set.
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...
Real mBoundingRadius
Bounding radius.
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.
unsigned char uchar
In order to avoid finger-aches :)
SortMode
Sort mode for billboard-set and particle-system.
Definition: OgreCommon.h:286
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.
Camera * mCurrentCamera
Current camera.
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:51
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:67
Billboards are oriented around their own direction vector (their own Y axis) and only rotate around t...
_StringBase String
BillboardRotationType mRotationType
Rotation type of each billboard.
list< Billboard * >::type FreeBillboardList
unsigned short uint16
Definition: OgrePlatform.h:345
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.