Ai
7 Star 22 Fork 16

Gitee 极速下载/OpenSceneGraph

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/openscenegraph/OpenSceneGraph
克隆/下载
AngularDampingOperator 3.25 KB
一键复制 编辑 原始数据 按行查看 历史
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
*
* 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.
*/
// Written by Wang Rui, (C) 2010
#ifndef OSGPARTICLE_ANGULARDAMPINGOPERATOR
#define OSGPARTICLE_ANGULARDAMPINGOPERATOR
#include <osgParticle/Operator>
#include <osgParticle/Particle>
namespace osgParticle
{
/** A angular damping operator applies damping constant to particle's angular velocity.
Refer to David McAllister's Particle System API (http://www.particlesystems.org)
*/
class AngularDampingOperator : public Operator
{
public:
AngularDampingOperator() : Operator(), _cutoffLow(0.0f), _cutoffHigh(FLT_MAX)
{}
AngularDampingOperator( const AngularDampingOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY )
: Operator(copy, copyop), _damping(copy._damping),
_cutoffLow(copy._cutoffLow), _cutoffHigh(copy._cutoffHigh)
{}
META_Object( osgParticle, AngularDampingOperator );
/// Set the damping factors
void setDamping( float x, float y, float z ) { _damping.set(x, y, z); }
void setDamping( const osg::Vec3& damping ) { _damping = damping; }
/// Set the damping factors to one value
void setDamping( float x ) { _damping.set(x, x, x); }
/// Get the damping factors
void getDamping( float& x, float& y, float& z ) const
{ x = _damping.x(); y = _damping.y(); z = _damping.z(); }
const osg::Vec3& getDamping() const { return _damping; }
/// Set the velocity cutoff factors
void setCutoff( float low, float high ) { _cutoffLow = low; _cutoffHigh = high; }
void setCutoffLow( float low ) { _cutoffLow = low; }
void setCutoffHigh( float low ) { _cutoffHigh = low; }
/// Get the velocity cutoff factors
void getCutoff( float& low, float& high ) const { low = _cutoffLow; high = _cutoffHigh; }
float getCutoffLow() const { return _cutoffLow; }
float getCutoffHigh() const { return _cutoffHigh; }
/// Apply the acceleration to a particle. Do not call this method manually.
inline void operate( Particle* P, double dt );
protected:
virtual ~AngularDampingOperator() {}
AngularDampingOperator& operator=( const AngularDampingOperator& ) { return *this; }
osg::Vec3 _damping;
float _cutoffLow;
float _cutoffHigh;
};
// INLINE METHODS
inline void AngularDampingOperator::operate( Particle* P, double dt )
{
const osg::Vec3& vel = P->getAngularVelocity();
float length2 = vel.length2();
if ( length2>=_cutoffLow && length2<=_cutoffHigh )
{
osg::Vec3 newvel( vel.x() * (1.0f - (1.0f - _damping.x()) * dt),
vel.y() * (1.0f - (1.0f - _damping.y()) * dt),
vel.z() * (1.0f - (1.0f - _damping.z()) * dt) );
P->setAngularVelocity( newvel );
}
}
}
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/mirrors/OpenSceneGraph.git
git@gitee.com:mirrors/OpenSceneGraph.git
mirrors
OpenSceneGraph
OpenSceneGraph
master

搜索帮助