| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield |
|---|
| 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 |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| 13 | // Written by Wang Rui, (C) 2010 |
|---|
| 14 | |
|---|
| 15 | #ifndef OSGPARTICLE_BOUNCEOPERATOR |
|---|
| 16 | #define OSGPARTICLE_BOUNCEOPERATOR |
|---|
| 17 | |
|---|
| 18 | #include <osgParticle/Particle> |
|---|
| 19 | #include <osgParticle/DomainOperator> |
|---|
| 20 | |
|---|
| 21 | namespace osgParticle |
|---|
| 22 | { |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | /** A bounce operator can affect the particle's velocity to make it rebound. |
|---|
| 26 | Refer to David McAllister's Particle System API (http://www.particlesystems.org) |
|---|
| 27 | */ |
|---|
| 28 | class OSGPARTICLE_EXPORT BounceOperator : public DomainOperator |
|---|
| 29 | { |
|---|
| 30 | public: |
|---|
| 31 | BounceOperator() |
|---|
| 32 | : DomainOperator(), _friction(1.0f), _resilience(0.0f), _cutoff(0.0f) |
|---|
| 33 | {} |
|---|
| 34 | |
|---|
| 35 | BounceOperator( const BounceOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY ) |
|---|
| 36 | : DomainOperator(copy, copyop), |
|---|
| 37 | _friction(copy._friction), _resilience(copy._resilience), _cutoff(copy._cutoff) |
|---|
| 38 | {} |
|---|
| 39 | |
|---|
| 40 | META_Object( osgParticle, BounceOperator ); |
|---|
| 41 | |
|---|
| 42 | /// Set the friction |
|---|
| 43 | void setFriction( float f ) { _friction = f; } |
|---|
| 44 | |
|---|
| 45 | /// Get the friction |
|---|
| 46 | float getFriction() const { return _friction; } |
|---|
| 47 | |
|---|
| 48 | /// Set the resilience |
|---|
| 49 | void setResilience( float r ) { _resilience = r; } |
|---|
| 50 | |
|---|
| 51 | /// Get the velocity cutoff factor |
|---|
| 52 | float getResilience() const { return _resilience; } |
|---|
| 53 | |
|---|
| 54 | /// Set the velocity cutoff factor |
|---|
| 55 | void setCutoff( float v ) { _cutoff = v; } |
|---|
| 56 | |
|---|
| 57 | /// Get the velocity cutoff factor |
|---|
| 58 | float getCutoff() const { return _cutoff; } |
|---|
| 59 | |
|---|
| 60 | protected: |
|---|
| 61 | virtual ~BounceOperator() {} |
|---|
| 62 | BounceOperator& operator=( const BounceOperator& ) { return *this; } |
|---|
| 63 | |
|---|
| 64 | virtual void handleTriangle( const Domain& domain, Particle* P, double dt ); |
|---|
| 65 | virtual void handleRectangle( const Domain& domain, Particle* P, double dt ); |
|---|
| 66 | virtual void handlePlane( const Domain& domain, Particle* P, double dt ); |
|---|
| 67 | virtual void handleSphere( const Domain& domain, Particle* P, double dt ); |
|---|
| 68 | virtual void handleDisk( const Domain& domain, Particle* P, double dt ); |
|---|
| 69 | |
|---|
| 70 | float _friction; |
|---|
| 71 | float _resilience; |
|---|
| 72 | float _cutoff; |
|---|
| 73 | }; |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | #endif |
|---|