openscenegraph
AngularDampingOperator
Go to the documentation of this file.
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_ANGULARDAMPINGOPERATOR
16#define OSGPARTICLE_ANGULARDAMPINGOPERATOR
17
18#include <osgParticle/Operator>
19#include <osgParticle/Particle>
20
21namespace osgParticle
22{
23
24
29{
30public:
33
38
40
42 void setDamping( float x, float y, float z ) { _damping.set(x, y, z); }
43 void setDamping( const osg::Vec3& damping ) { _damping = damping; }
44
46 void setDamping( float x ) { _damping.set(x, x, x); }
47
49 void getDamping( float& x, float& y, float& z ) const
50 { x = _damping.x(); y = _damping.y(); z = _damping.z(); }
51
52 const osg::Vec3& getDamping() const { return _damping; }
53
55 void setCutoff( float low, float high ) { _cutoffLow = low; _cutoffHigh = high; }
56 void setCutoffLow( float low ) { _cutoffLow = low; }
57 void setCutoffHigh( float low ) { _cutoffHigh = low; }
58
60 void getCutoff( float& low, float& high ) const { low = _cutoffLow; high = _cutoffHigh; }
61 float getCutoffLow() const { return _cutoffLow; }
62 float getCutoffHigh() const { return _cutoffHigh; }
63
65 inline void operate( Particle* P, double dt );
66
67protected:
70
74};
75
76// INLINE METHODS
77
78inline void AngularDampingOperator::operate( Particle* P, double dt )
79{
80 const osg::Vec3& vel = P->getAngularVelocity();
81 float length2 = vel.length2();
82 if ( length2>=_cutoffLow && length2<=_cutoffHigh )
83 {
84 osg::Vec3 newvel( vel.x() * (1.0f - (1.0f - _damping.x()) * dt),
85 vel.y() * (1.0f - (1.0f - _damping.y()) * dt),
86 vel.z() * (1.0f - (1.0f - _damping.z()) * dt) );
87 P->setAngularVelocity( newvel );
88 }
89}
90
91
92}
93
94#endif
Definition AngularDampingOperator:29
AngularDampingOperator(const AngularDampingOperator &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition AngularDampingOperator:34
float getCutoffHigh() const
Definition AngularDampingOperator:62
AngularDampingOperator()
Definition AngularDampingOperator:31
float _cutoffHigh
Definition AngularDampingOperator:73
void setDamping(float x, float y, float z)
Set the damping factors.
Definition AngularDampingOperator:42
void setCutoffLow(float low)
Definition AngularDampingOperator:56
void setDamping(float x)
Set the damping factors to one value.
Definition AngularDampingOperator:46
float getCutoffLow() const
Definition AngularDampingOperator:61
float _cutoffLow
Definition AngularDampingOperator:72
virtual ~AngularDampingOperator()
Definition AngularDampingOperator:68
void getDamping(float &x, float &y, float &z) const
Get the damping factors.
Definition AngularDampingOperator:49
void operate(Particle *P, double dt)
Apply the acceleration to a particle. Do not call this method manually.
Definition AngularDampingOperator:78
void setCutoffHigh(float low)
Definition AngularDampingOperator:57
AngularDampingOperator & operator=(const AngularDampingOperator &)
Definition AngularDampingOperator:69
void getCutoff(float &low, float &high) const
Get the velocity cutoff factors.
Definition AngularDampingOperator:60
void setCutoff(float low, float high)
Set the velocity cutoff factors.
Definition AngularDampingOperator:55
META_Object(osgParticle, AngularDampingOperator)
void setDamping(const osg::Vec3 &damping)
Definition AngularDampingOperator:43
osg::Vec3 _damping
Definition AngularDampingOperator:71
const osg::Vec3 & getDamping() const
Definition AngularDampingOperator:52
Definition Operator:35
Definition Particle:47
const osg::Vec3 & getAngularVelocity() const
Get the rotational velocity vector.
Definition Particle:423
void setAngularVelocity(const osg::Vec3 &v)
Definition Particle:520
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Definition Vec3f:29
value_type & z()
Definition Vec3f:82
void set(value_type x, value_type y, value_type z)
Definition Vec3f:67
value_type & y()
Definition Vec3f:81
value_type & x()
Definition Vec3f:80
value_type length2() const
Definition Vec3f:182
Definition AccelOperator:27