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-2013 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 #ifndef __Particle_H__ 29 #define __Particle_H__ 30 31 #include "OgrePrerequisites.h" 32 #include "OgreBillboard.h" 33 #include "OgreHeaderPrefix.h" 34 35 namespace Ogre { 36 37 /** \addtogroup Core 38 * @{ 39 */ 40 /** \addtogroup Effects 41 * @{ 42 */ 43 /** Abstract class containing any additional data required to be associated 44 with a particle to perform the required rendering. 45 @remarks 46 Because you can specialise the way that particles are rendered by supplying 47 custom ParticleSystemRenderer classes, you might well need some additional 48 data for your custom rendering routine which is not held on the default particle 49 class. If that's the case, then you should define a subclass of this class, 50 and construct it when asked in your custom ParticleSystemRenderer class. 51 */ 52 class _OgreExport ParticleVisualData : public FXAlloc 53 { 54 public: ParticleVisualData()55 ParticleVisualData() {} ~ParticleVisualData()56 virtual ~ParticleVisualData() {} 57 58 }; 59 60 /** Class representing a single particle instance. */ 61 class _OgreExport Particle : public FXAlloc 62 { 63 protected: 64 /// Parent ParticleSystem 65 ParticleSystem* mParentSystem; 66 /// Additional visual data you might want to associate with the Particle 67 ParticleVisualData* mVisual; 68 public: 69 /// Type of particle 70 enum ParticleType 71 { 72 Visual, 73 Emitter 74 }; 75 76 /// Does this particle have it's own dimensions? 77 bool mOwnDimensions; 78 /// Personal width if mOwnDimensions == true 79 Real mWidth; 80 /// Personal height if mOwnDimensions == true 81 Real mHeight; 82 /// Current rotation value 83 Radian rotation; 84 // Note the intentional public access to internal variables 85 // Accessing via get/set would be too costly for 000's of particles 86 /// World position 87 Vector3 position; 88 /// Direction (and speed) 89 Vector3 direction; 90 /// Current colour 91 ColourValue colour; 92 /// Time to live, number of seconds left of particles natural life 93 Real timeToLive; 94 /// Total Time to live, number of seconds of particles natural life 95 Real totalTimeToLive; 96 /// Speed of rotation in radians/sec 97 Radian rotationSpeed; 98 /// Determines the type of particle. 99 ParticleType particleType; 100 Particle()101 Particle() 102 : mParentSystem(0), mVisual(0), mOwnDimensions(false), rotation(0), 103 position(Vector3::ZERO), direction(Vector3::ZERO), 104 colour(ColourValue::White), timeToLive(10), totalTimeToLive(10), 105 rotationSpeed(0), particleType(Visual) 106 { 107 } 108 109 /** Sets the width and height for this particle. 110 @remarks 111 Note that it is most efficient for every particle in a ParticleSystem to have the same dimensions. If you 112 choose to alter the dimensions of an individual particle the set will be less efficient. Do not call 113 this method unless you really need to have different particle dimensions within the same set. Otherwise 114 just call the ParticleSystem::setDefaultDimensions method instead. 115 */ 116 void setDimensions(Real width, Real height); 117 118 /** Returns true if this particle deviates from the ParticleSystem's default dimensions (i.e. if the 119 particle::setDimensions method has been called for this instance). 120 @see 121 particle::setDimensions 122 */ hasOwnDimensions(void)123 bool hasOwnDimensions(void) const { return mOwnDimensions; } 124 125 /** Retrieves the particle's personal width, if hasOwnDimensions is true. */ getOwnWidth(void)126 Real getOwnWidth(void) const { return mWidth; } 127 128 /** Retrieves the particle's personal width, if hasOwnDimensions is true. */ getOwnHeight(void)129 Real getOwnHeight(void) const { return mHeight; } 130 131 /** Sets the current rotation */ 132 void setRotation(const Radian& rad); 133 getRotation(void)134 const Radian& getRotation(void) const { return rotation; } 135 136 /** Internal method for notifying the particle of it's owner. 137 */ 138 void _notifyOwner(ParticleSystem* owner); 139 140 /** Internal method for notifying the particle of it's optional visual data. 141 */ _notifyVisualData(ParticleVisualData * vis)142 void _notifyVisualData(ParticleVisualData* vis) { mVisual = vis; } 143 144 /// Get the optional visual data associated with the class getVisualData(void)145 ParticleVisualData* getVisualData(void) const { return mVisual; } 146 147 /// Utility method to reset this particle 148 void resetDimensions(void); 149 }; 150 /** @} */ 151 /** @} */ 152 } 153 154 #include "OgreHeaderSuffix.h" 155 156 #endif 157 158