2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2002-06-05 20:44:55 +08:00
|
|
|
//osgParticle - Copyright (C) 2002 Marco Jez
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
#ifndef OSGPARTICLE_ACCELOPERATOR
|
|
|
|
#define OSGPARTICLE_ACCELOPERATOR 1
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
#include <osgParticle/ModularProgram>
|
|
|
|
#include <osgParticle/Operator>
|
|
|
|
#include <osgParticle/Particle>
|
|
|
|
|
|
|
|
#include <osg/CopyOp>
|
|
|
|
#include <osg/Object>
|
|
|
|
#include <osg/Vec3>
|
|
|
|
|
|
|
|
namespace osgParticle
|
|
|
|
{
|
|
|
|
|
|
|
|
/** An operator class that applies a constant acceleration to the particles.
|
|
|
|
*/
|
|
|
|
class AccelOperator: public Operator {
|
|
|
|
public:
|
|
|
|
inline AccelOperator();
|
2005-04-29 17:47:57 +08:00
|
|
|
inline AccelOperator(const AccelOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
2002-06-06 21:25:36 +08:00
|
|
|
META_Object(osgParticle, AccelOperator);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Get the acceleration vector.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline const osg::Vec3& getAcceleration() const;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Set the acceleration vector.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void setAcceleration(const osg::Vec3& v);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/** Quickly set the acceleration vector to the gravity on earth (0, 0, -9.81).
|
|
|
|
The acceleration will be multiplied by the <CODE>scale</CODE> parameter.
|
|
|
|
*/
|
|
|
|
inline void setToGravity(float scale = 1);
|
|
|
|
|
|
|
|
/// Apply the acceleration to a particle. Do not call this method manually.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void operate(Particle* P, double dt);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Perform some initializations. Do not call this method manually.
|
|
|
|
inline void beginOperate(Program *prg);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~AccelOperator() {}
|
|
|
|
AccelOperator &operator=(const AccelOperator &) { return *this; }
|
|
|
|
|
|
|
|
private:
|
2005-04-29 17:47:57 +08:00
|
|
|
osg::Vec3 _accel;
|
|
|
|
osg::Vec3 _xf_accel;
|
2002-06-05 20:44:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// INLINE FUNCTIONS
|
|
|
|
|
|
|
|
inline AccelOperator::AccelOperator()
|
2005-04-29 17:47:57 +08:00
|
|
|
: Operator(), _accel(0, 0, 0)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline AccelOperator::AccelOperator(const AccelOperator& copy, const osg::CopyOp& copyop)
|
|
|
|
: Operator(copy, copyop), _accel(copy._accel)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline const osg::Vec3& AccelOperator::getAcceleration() const
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
return _accel;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void AccelOperator::setAcceleration(const osg::Vec3& v)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
_accel = v;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void AccelOperator::setToGravity(float scale)
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
_accel.set(0, 0, -9.80665f * scale);
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void AccelOperator::operate(Particle* P, double dt)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
P->addVelocity(_xf_accel * dt);
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void AccelOperator::beginOperate(Program *prg)
|
|
|
|
{
|
2004-10-25 04:04:00 +08:00
|
|
|
if (prg->getReferenceFrame() == ModularProgram::RELATIVE_RF) {
|
2005-04-29 17:47:57 +08:00
|
|
|
_xf_accel = prg->rotateLocalToWorld(_accel);
|
2002-06-05 20:44:55 +08:00
|
|
|
} else {
|
2005-04-29 17:47:57 +08:00
|
|
|
_xf_accel = _accel;
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|