OpenSceneGraph 3.6.5
AccelOperator
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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//osgParticle - Copyright (C) 2002 Marco Jez
14
15#ifndef OSGPARTICLE_ACCELOPERATOR
16#define OSGPARTICLE_ACCELOPERATOR 1
17
19#include <osgParticle/Operator>
20#include <osgParticle/Particle>
21
22#include <osg/CopyOp>
23#include <osg/Object>
24#include <osg/Vec3>
25
26namespace osgParticle
27{
28
31 class AccelOperator: public Operator {
32 public:
33 inline AccelOperator();
34 inline AccelOperator(const AccelOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
35
37
39 inline const osg::Vec3& getAcceleration() const;
40
42 inline void setAcceleration(const osg::Vec3& v);
43
47 inline void setToGravity(float scale = 1);
48
50 inline void operate(Particle* P, double dt);
51
53 inline void beginOperate(Program *prg);
54
55 protected:
56 virtual ~AccelOperator() {}
57 AccelOperator &operator=(const AccelOperator &) { return *this; }
58
59 private:
60 osg::Vec3 _accel;
61 osg::Vec3 _xf_accel;
62 };
63
64 // INLINE FUNCTIONS
65
67 : Operator(), _accel(0, 0, 0)
68 {
69 }
70
71 inline AccelOperator::AccelOperator(const AccelOperator& copy, const osg::CopyOp& copyop)
72 : Operator(copy, copyop), _accel(copy._accel)
73 {
74 }
75
77 {
78 return _accel;
79 }
80
82 {
83 _accel = v;
84 }
85
86 inline void AccelOperator::setToGravity(float scale)
87 {
88 _accel.set(0, 0, -9.80665f * scale);
89 }
90
91 inline void AccelOperator::operate(Particle* P, double dt)
92 {
93 P->addVelocity(_xf_accel * dt);
94 }
95
97 {
99 _xf_accel = prg->rotateLocalToWorld(_accel);
100 } else {
101 _xf_accel = _accel;
102 }
103 }
104
105}
106
107
108#endif
Vec3f Vec3
Definition Vec3:21
The osgParticle library is a NodeKit that extends the core scene graph to support particle effects.
Definition AccelOperator:27
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
void set(value_type x, value_type y, value_type z)
Definition Vec3f:67
void beginOperate(Program *prg)
Perform some initializations. Do not call this method manually.
Definition AccelOperator:96
void setToGravity(float scale=1)
Quickly set the acceleration vector to the gravity on earth (0, 0, -9.81).
Definition AccelOperator:86
AccelOperator & operator=(const AccelOperator &)
Definition AccelOperator:57
AccelOperator()
Definition AccelOperator:66
void operate(Particle *P, double dt)
Apply the acceleration to a particle. Do not call this method manually.
Definition AccelOperator:91
const osg::Vec3 & getAcceleration() const
Get the acceleration vector.
Definition AccelOperator:76
void setAcceleration(const osg::Vec3 &v)
Set the acceleration vector.
Definition AccelOperator:81
META_Object(osgParticle, AccelOperator)
virtual ~AccelOperator()
Definition AccelOperator:56
Operator()
Definition Operator:92
Implementation of a particle.
Definition Particle:47
void addVelocity(const osg::Vec3 &dv)
Add a vector to the velocity vector.
Definition Particle:493
@ RELATIVE_RF
Definition ParticleProcessor:42
ReferenceFrame getReferenceFrame() const
Get the reference frame.
Definition ParticleProcessor:179
osg::Vec3 rotateLocalToWorld(const osg::Vec3 &P)
Transform a vector from local to world coordinates, discarding translation (valid only during cull tr...
Definition ParticleProcessor:315
An abstract ParticleProcessor descendant for modifying particles "on the fly" during the cull travers...
Definition Program:36

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.