Changeset 13041 for OpenSceneGraph/trunk/include/osgParticle/Particle
- Timestamp:
- 03/21/12 18:36:20 (15 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgParticle/Particle
r11755 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 41 41 time (lifeTime >= 0). For each property which is defined as a range of values, a 42 42 "current" value will be evaluated at each frame by interpolating the <I>min</I> 43 and <I>max</I> values so that <I>curr_value = min</I> when <I>t == 0</I>, and 43 and <I>max</I> values so that <I>curr_value = min</I> when <I>t == 0</I>, and 44 44 <I>curr_value = max</I> when <I>t == lifeTime</I>. 45 45 You may customize the interpolator objects to achieve any kind of transition. … … 51 51 friend class ParticleSystem; 52 52 public: 53 53 54 54 enum 55 55 { … … 66 66 QUAD_TRIANGLESTRIP, // uses GL_TRI_angleSTRIP as primitive, but each particle needs a glBegin/glEnd pair 67 67 HEXAGON, // may save some filling time, but uses more triangles 68 LINE, // uses GL_LINES to draw line segments that point to the direction of motion 68 LINE, // uses GL_LINES to draw line segments that point to the direction of motion 69 69 USER // uses a user-defined drawable as primitive 70 70 }; 71 71 72 72 Particle(); 73 73 74 74 /// Get the shape of the particle. 75 75 inline Shape getShape() const; 76 76 77 77 /// Set the shape of the particle. 78 78 inline void setShape(Shape s); … … 80 80 /// Get whether the particle is still alive. 81 81 inline bool isAlive() const; 82 82 83 83 /// Get the life time of the particle (in seconds). 84 84 inline double getLifeTime() const; 85 85 86 86 /// Get the age of the particle (in seconds). 87 87 inline double getAge() const; 88 88 89 89 /// Get the minimum and maximum values for polygon size. 90 90 inline const rangef& getSizeRange() const; 91 91 92 92 /// Get the minimum and maximum values for alpha. 93 93 inline const rangef& getAlphaRange() const; 94 94 95 95 /// Get the minimum and maximum values for color. 96 96 inline const rangev4& getColorRange() const; 97 97 98 98 /// Get the interpolator for computing the size of polygons. 99 99 inline const Interpolator* getSizeInterpolator() const; 100 100 101 101 /// Get the interpolator for computing alpha values. 102 102 inline const Interpolator* getAlphaInterpolator() const; 103 103 104 104 /// Get the interpolator for computing color values. 105 105 inline const Interpolator* getColorInterpolator() const; … … 109 109 */ 110 110 inline float getRadius() const; 111 111 112 112 /** Get the mass of the particle. 113 113 For built-in operators to work correctly, remember that the mass is expressed in kg. 114 114 */ 115 115 inline float getMass() const; 116 116 117 117 /// Get <CODE>1 / getMass()</CODE>. 118 118 inline float getMassInv() const; 119 119 120 120 /// Get the position vector. 121 121 inline const osg::Vec3& getPosition() const; 122 122 123 123 /** Get the velocity vector. 124 124 For built-in operators to work correctly, remember that velocity components are expressed 125 125 in meters per second. 126 126 */ 127 inline const osg::Vec3& getVelocity() const; 128 127 inline const osg::Vec3& getVelocity() const; 128 129 129 /// Get the previous position (the position before last update). 130 130 inline const osg::Vec3& getPreviousPosition() const; … … 132 132 /// Get the angle vector. 133 133 inline const osg::Vec3& getAngle() const; 134 134 135 135 /// Get the rotational velocity vector. 136 136 inline const osg::Vec3& getAngularVelocity() const; 137 137 138 138 /// Get the previous angle vector. 139 139 inline const osg::Vec3& getPreviousAngle() const; 140 140 141 141 /// Get the current color 142 142 inline const osg::Vec4& getCurrentColor() const { return _current_color; } … … 144 144 /// Get the current alpha 145 145 inline float getCurrentAlpha() const { return _current_alpha; } 146 146 147 147 /// Get the s texture coordinate of the bottom left of the particle 148 148 inline float getSTexCoord() const { return _s_coord; } … … 153 153 /// Get width of texture tile 154 154 inline int getTileS() const; 155 155 156 156 /// Get height of texture tile 157 157 inline int getTileT() const; 158 158 159 159 /// Get number of texture tiles 160 160 inline int getNumTiles() const { return _end_tile - _start_tile + 1; } 161 161 162 162 /** Kill the particle on next update 163 NOTE: after calling this function, the <CODE>isAlive()</CODE> method will still 163 NOTE: after calling this function, the <CODE>isAlive()</CODE> method will still 164 164 return true until the particle is updated again. 165 165 */ 166 166 inline void kill(); 167 167 168 168 /// Set the life time of the particle. 169 169 inline void setLifeTime(double t); 170 170 171 171 /// Set the minimum and maximum values for polygon size. 172 172 inline void setSizeRange(const rangef& r); 173 173 174 174 /// Set the minimum and maximum values for alpha. 175 175 inline void setAlphaRange(const rangef& r); 176 176 177 177 /// Set the minimum and maximum values for color. 178 178 inline void setColorRange(const rangev4& r); 179 179 180 180 /// Set the interpolator for computing size values. 181 181 inline void setSizeInterpolator(Interpolator* ri); 182 183 /// Set the interpolator for computing alpha values. 182 183 /// Set the interpolator for computing alpha values. 184 184 inline void setAlphaInterpolator(Interpolator* ai); 185 185 186 186 /// Set the interpolator for computing color values. 187 187 inline void setColorInterpolator(Interpolator* ci); … … 191 191 */ 192 192 inline void setRadius(float r); 193 193 194 194 /** Set the mass of the particle. 195 195 For built-in operators to work correctly, remember that the mass is expressed in kg. 196 196 */ 197 197 inline void setMass(float m); 198 199 /// Set the position vector. 198 199 /// Set the position vector. 200 200 inline void setPosition(const osg::Vec3& p); 201 201 202 202 /** Set the velocity vector. 203 203 For built-in operators to work correctly, remember that velocity components are expressed … … 205 205 */ 206 206 inline void setVelocity(const osg::Vec3& v); 207 207 208 208 /// Add a vector to the velocity vector. 209 209 inline void addVelocity(const osg::Vec3& dv); 210 210 211 211 /// Transform position and velocity vectors by a matrix. 212 212 inline void transformPositionVelocity(const osg::Matrix& xform); … … 217 217 /// Set the angle vector. 218 218 inline void setAngle(const osg::Vec3& a); 219 219 220 220 /** 221 Set the angular velocity vector. 221 Set the angular velocity vector. 222 222 Components x, y and z are angles of rotation around the respective axis (in radians). 223 223 */ 224 224 inline void setAngularVelocity(const osg::Vec3& v); 225 225 226 226 /// Add a vector to the angular velocity vector. 227 227 inline void addAngularVelocity(const osg::Vec3& dv); 228 228 229 229 /// Transform angle and angularVelocity vectors by a matrix. 230 230 inline void transformAngleVelocity(const osg::Matrix& xform); 231 231 232 232 /** Update the particle (don't call this method manually). 233 233 This method is called automatically by <CODE>ParticleSystem::update()</CODE>; it … … 240 240 /// Perform some pre-rendering tasks. Called automatically by particle systems. 241 241 inline void beginRender(osg::GLBeginEndAdapter* gl) const; 242 242 243 243 /// Render the particle. Called automatically by particle systems. 244 244 void render(osg::GLBeginEndAdapter* gl, const osg::Vec3& xpos, const osg::Vec3& px, const osg::Vec3& py, float scale = 1.0f) const; 245 245 246 246 /// Render the particle with user-defined drawable 247 247 void render(osg::RenderInfo& renderInfo, const osg::Vec3& xpos, const osg::Vec3& xrot) const; 248 248 249 249 /// Perform some post-rendering tasks. Called automatically by particle systems. 250 250 inline void endRender(osg::GLBeginEndAdapter* gl) const; 251 251 252 252 /// Get the current (interpolated) polygon size. Valid only after the first call to update(). 253 253 inline float getCurrentSize() const; 254 254 255 255 /// Specify how the particle texture is tiled. 256 256 /// All tiles in the given range are sequentially displayed during the lifetime … … 272 272 /// Get the const next particle 273 273 inline int getNextParticle() const { return _nextParticle; } 274 274 275 275 /// Set the depth of the particle 276 276 inline void setDepth(double d) { _depth = d; } 277 277 278 278 /// Get the depth of the particle 279 279 inline double getDepth() const { return _depth; } 280 280 281 281 /// Set the user-defined particle drawable 282 282 inline void setDrawable(osg::Drawable* d) { _drawable = d; } 283 283 284 284 /// Get the user-defined particle drawable 285 285 inline osg::Drawable* getDrawable() const { return _drawable.get(); } 286 286 287 287 /// Sorting operator 288 288 bool operator<(const Particle &P) const { return _depth < P._depth; } … … 292 292 293 293 protected: 294 294 295 295 Shape _shape; 296 296 … … 317 317 osg::Vec3 _angul_arvel; 318 318 319 double _t0; 319 double _t0; 320 320 321 321 float _alive; … … 324 324 osg::Vec3 _base_prop; // [0] _alive [1] _current_size [2] _current_alpha 325 325 osg::Vec4 _current_color; 326 326 327 327 float _s_tile; 328 328 float _t_tile; … … 332 332 float _s_coord; 333 333 float _t_coord; 334 334 335 335 // previous and next Particles are only used in ConnectedParticleSystems 336 336 int _previousParticle; 337 337 int _nextParticle; 338 338 339 339 // the depth of the particle is used only when sorting is enabled 340 340 double _depth; 341 341 342 342 // the particle drawable is used only when USER shape is enabled 343 343 osg::ref_ptr<osg::Drawable> _drawable; … … 365 365 return _lifeTime; 366 366 } 367 367 368 368 inline double Particle::getAge() const 369 369 { 370 370 return _t0; 371 371 } 372 372 373 373 inline float Particle::getRadius() const 374 374 { 375 375 return _radius; 376 376 } 377 377 378 378 inline void Particle::setRadius(float r) 379 379 { … … 420 420 return _velocity; 421 421 } 422 422 423 423 inline const osg::Vec3& Particle::getPreviousPosition() const 424 424 { … … 430 430 return _angle; 431 431 } 432 432 433 433 inline const osg::Vec3& Particle::getAngularVelocity() const 434 434 { 435 435 return _angul_arvel; 436 436 } 437 437 438 438 inline const osg::Vec3& Particle::getPreviousAngle() const 439 439 { 440 440 return _prev_angle; 441 441 } 442 442 443 443 inline int Particle::getTileS() const 444 444 { … … 450 450 return (_t_tile>0.0f) ? static_cast<int>(1.0f / _t_tile) : 1; 451 451 } 452 452 453 453 inline void Particle::kill() 454 454 { … … 511 511 _velocity = osg::Matrix::transform3x3(_velocity, xform); 512 512 } 513 513 514 514 inline void Particle::transformPositionVelocity(const osg::Matrix& xform1, const osg::Matrix& xform2, float r) 515 515 { … … 522 522 _velocity = velocity1*r + velocity2*one_minus_r; 523 523 } 524 524 525 525 inline void Particle::setAngle(const osg::Vec3& a) 526 526 { 527 527 _angle = a; 528 528 } 529 529 530 530 inline void Particle::setAngularVelocity(const osg::Vec3& v) 531 531 { 532 532 _angul_arvel = v; 533 533 } 534 534 535 535 inline void Particle::addAngularVelocity(const osg::Vec3& dv) 536 536 { 537 537 _angul_arvel += dv; 538 538 } 539 539 540 540 inline void Particle::transformAngleVelocity(const osg::Matrix& xform) 541 541 { 542 542 // this should be optimized! 543 543 544 544 osg::Vec3 a1 = _angle + _angul_arvel; 545 545 546 546 _angle = xform.preMult(_angle); 547 547 a1 = xform.preMult(a1); 548 548 549 549 _angul_arvel = a1 - _angle; 550 550 } 551 551 552 552 inline float Particle::getMass() const 553 553 { 554 554 return _mass; 555 555 } 556 556 557 557 inline float Particle::getMassInv() const 558 558 { 559 559 return _massinv; 560 560 } 561 561 562 562 inline void Particle::setMass(float m) 563 563 { … … 565 565 _massinv = 1 / m; 566 566 } 567 567 568 568 inline void Particle::beginRender(osg::GLBeginEndAdapter* gl) const 569 569 { … … 611 611 _s_tile = (sTile>0) ? 1.0f / static_cast<float>(sTile) : 1.0f; 612 612 _t_tile = (tTile>0) ? 1.0f / static_cast<float>(tTile) : 1.0f; 613 613 614 614 if(startTile == -1) 615 615 {
