mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
add angular velocity
This commit is contained in:
parent
e789201a5e
commit
12a8319f8e
@ -263,12 +263,21 @@ class Particles(ParticleSystem.ParticleSystem):
|
||||
file.write('# Z Spin factory parameters\n')
|
||||
file.write(targ + '.factory.setInitialAngle(%.4f)\n' % \
|
||||
self.factory.getInitialAngle())
|
||||
file.write(targ + '.factory.setFinalAngle(%.4f)\n' % \
|
||||
self.factory.getFinalAngle())
|
||||
file.write(targ + '.factory.setInitialAngleSpread(%.4f)\n' % \
|
||||
self.factory.getInitialAngleSpread())
|
||||
file.write(targ + '.factory.setFinalAngleSpread(%.4f)\n' % \
|
||||
file.write(targ + '.factory.enableAngularVelocity(%d)\n' % \
|
||||
self.factory.getAngularVelocityEnabled())
|
||||
if(self.factory.getAngularVelocityEnabled()):
|
||||
file.write(targ + '.factory.setAngularVelocity(%.4f)\n' % \
|
||||
self.factory.getAngularVelocity())
|
||||
file.write(targ + '.factory.setAngularVelocitySpread(%.4f)\n' % \
|
||||
self.factory.getAngularVelocitySpread())
|
||||
else:
|
||||
file.write(targ + '.factory.setFinalAngle(%.4f)\n' % \
|
||||
self.factory.getFinalAngle())
|
||||
file.write(targ + '.factory.setFinalAngleSpread(%.4f)\n' % \
|
||||
self.factory.getFinalAngleSpread())
|
||||
|
||||
elif (self.factoryType == "OrientedParticleFactory"):
|
||||
file.write('# Oriented factory parameters\n')
|
||||
file.write(targ + '.factory.setInitialOrientation(%.4f)\n' % \
|
||||
|
@ -269,7 +269,8 @@ class ParticlePanel(AppShell):
|
||||
('Factory', 'Terminal Vel. Spread',
|
||||
'Variation in terminal velocity',
|
||||
self.setFactoryTerminalVelocitySpread,
|
||||
0.0, None))
|
||||
0.0, None),
|
||||
)
|
||||
self.createFloaters(factoryPage, factoryWidgets)
|
||||
|
||||
self.factoryNotebook = Pmw.NoteBook(factoryPage, tabpos = None)
|
||||
@ -277,6 +278,23 @@ class ParticlePanel(AppShell):
|
||||
factoryPointPage = self.factoryNotebook.add('PointParticleFactory')
|
||||
# Z spin page #
|
||||
zSpinPage = self.factoryNotebook.add('ZSpinParticleFactory')
|
||||
|
||||
self.createCheckbutton(
|
||||
zSpinPage, 'Z Spin Factory', 'Enable Angular Velocity',
|
||||
("On: angular velocity is used; " +
|
||||
"Off: final angle is used"),
|
||||
self.toggleAngularVelocity, 0, side = TOP),
|
||||
|
||||
self.createFloater(
|
||||
zSpinPage, 'Z Spin Factory', 'Angular Velocity',
|
||||
'How fast sprites rotate',
|
||||
command = self.setFactoryZSpinAngularVelocity)
|
||||
|
||||
self.createFloater(
|
||||
zSpinPage, 'Z Spin Factory', 'Angular Velocity Spread',
|
||||
'Variation in how fast sprites rotate',
|
||||
command = self.setFactoryZSpinAngularVelocitySpread)
|
||||
|
||||
self.createAngleDial(zSpinPage, 'Z Spin Factory', 'Initial Angle',
|
||||
'Starting angle in degrees',
|
||||
fRollover = 1,
|
||||
@ -1172,6 +1190,10 @@ class ParticlePanel(AppShell):
|
||||
self.particles.factory.setFinalAngle(angle)
|
||||
def setFactoryZSpinFinalAngleSpread(self, spread):
|
||||
self.particles.factory.setFinalAngleSpread(spread)
|
||||
def setFactoryZSpinAngularVelocity(self, vel):
|
||||
self.particles.factory.setAngularVelocity(vel)
|
||||
def setFactoryZSpinAngularVelocitySpread(self, spread):
|
||||
self.particles.factory.setAngularVelocitySpread(spread)
|
||||
|
||||
## EMITTER PAGE ##
|
||||
def selectEmitterType(self, type):
|
||||
@ -1599,6 +1621,11 @@ class ParticlePanel(AppShell):
|
||||
def toggleRendererSpriteAnimAngle(self):
|
||||
self.particles.renderer.setAnimAngleFlag(
|
||||
self.getVariable('Sprite Renderer', 'Anim Angle').get())
|
||||
|
||||
def toggleAngularVelocity(self):
|
||||
self.particles.factory.enableAngularVelocity(
|
||||
self.getVariable('Z Spin Factory', 'Enable Angular Velocity').get())
|
||||
|
||||
def setRendererSpriteInitialXScale(self, xScale):
|
||||
self.particles.renderer.setInitialXScale(xScale)
|
||||
def setRendererSpriteFinalXScale(self, xScale):
|
||||
|
@ -51,3 +51,25 @@ INLINE float ZSpinParticle::
|
||||
get_final_angle(void) const {
|
||||
return _final_angle;
|
||||
}
|
||||
|
||||
INLINE float ZSpinParticle::
|
||||
get_angular_velocity(void) const {
|
||||
return _angular_velocity;
|
||||
}
|
||||
|
||||
INLINE void ZSpinParticle::
|
||||
set_angular_velocity(float v) {
|
||||
_angular_velocity = v;
|
||||
}
|
||||
|
||||
INLINE void ZSpinParticle::
|
||||
enable_angular_velocity(bool bEnabled) {
|
||||
_bUseAngularVelocity = bEnabled;
|
||||
}
|
||||
|
||||
INLINE bool ZSpinParticle::
|
||||
get_angular_velocity_enabled(void) const {
|
||||
return _bUseAngularVelocity;
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,6 +29,8 @@ ZSpinParticle(void) :
|
||||
_initial_angle = 0.0f;
|
||||
_final_angle = 0.0f;
|
||||
_cur_angle = 0.0f;
|
||||
_angular_velocity = 0.0f;
|
||||
_bUseAngularVelocity = false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -42,6 +44,8 @@ ZSpinParticle(const ZSpinParticle ©) :
|
||||
_initial_angle = copy._initial_angle;
|
||||
_final_angle = copy._final_angle;
|
||||
_cur_angle = copy._cur_angle;
|
||||
_angular_velocity = copy._angular_velocity;
|
||||
_bUseAngularVelocity = copy._bUseAngularVelocity;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -79,17 +83,23 @@ init(void) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ZSpinParticle::
|
||||
update(void) {
|
||||
float t = get_parameterized_age();
|
||||
// if using final_angle, want age to range from [0,1] over lifespan, so use parameterized_age
|
||||
// for angular velocity, should be allowed to range freely upward, use regular age
|
||||
|
||||
// interpolate the current orientation
|
||||
_cur_angle = _initial_angle + (t * (_final_angle - _initial_angle));
|
||||
if(_bUseAngularVelocity) {
|
||||
// interpolate the current orientation
|
||||
_cur_angle = _initial_angle + (get_age() * _angular_velocity);
|
||||
} else {
|
||||
_cur_angle = _initial_angle + (get_parameterized_age() * (_final_angle - _initial_angle));
|
||||
}
|
||||
|
||||
// normalize the result to [0..360)
|
||||
_cur_angle = fmod(_cur_angle, 360.0f);
|
||||
|
||||
// if _cur_angle was negative, it is still negative after fmod,
|
||||
// but greater than -360.
|
||||
// wrap it around by adding 360
|
||||
|
||||
// is this really necessary? should be in range of sin/cos
|
||||
if(_cur_angle < 0.0f)
|
||||
_cur_angle += 360.0f;
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ private:
|
||||
float _initial_angle;
|
||||
float _final_angle;
|
||||
float _cur_angle;
|
||||
float _angular_velocity;
|
||||
bool _bUseAngularVelocity;
|
||||
|
||||
public:
|
||||
ZSpinParticle(void);
|
||||
@ -53,6 +55,14 @@ public:
|
||||
|
||||
INLINE void set_final_angle(float t);
|
||||
INLINE float get_final_angle(void) const;
|
||||
|
||||
// 'set_final_angle' and 'angular_velocity' are mutually exclusive apis
|
||||
// if angular-velocity is specified, final_angle is ignored
|
||||
INLINE void set_angular_velocity(float v);
|
||||
INLINE float get_angular_velocity(void) const;
|
||||
|
||||
INLINE void enable_angular_velocity(bool bEnabled);
|
||||
INLINE bool get_angular_velocity_enabled(void) const;
|
||||
};
|
||||
|
||||
#include "zSpinParticle.I"
|
||||
|
@ -88,3 +88,39 @@ INLINE float ZSpinParticleFactory::
|
||||
get_final_angle_spread(void) const {
|
||||
return _final_angle_spread;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function : get_angular_velocity
|
||||
// Access : public
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE float ZSpinParticleFactory::
|
||||
get_angular_velocity(void) const {
|
||||
return _angular_velocity;
|
||||
}
|
||||
|
||||
INLINE void ZSpinParticleFactory::
|
||||
set_angular_velocity(float v) {
|
||||
_angular_velocity = v;
|
||||
}
|
||||
|
||||
INLINE float ZSpinParticleFactory::
|
||||
get_angular_velocity_spread(void) const {
|
||||
return _angular_velocity_spread;
|
||||
}
|
||||
|
||||
INLINE void ZSpinParticleFactory::
|
||||
set_angular_velocity_spread(float spread) {
|
||||
_angular_velocity_spread = spread;
|
||||
}
|
||||
|
||||
|
||||
INLINE void ZSpinParticleFactory::
|
||||
enable_angular_velocity(bool bEnabled) {
|
||||
_bUseAngularVelocity = bEnabled;
|
||||
}
|
||||
|
||||
INLINE bool ZSpinParticleFactory::
|
||||
get_angular_velocity_enabled(void) const {
|
||||
return _bUseAngularVelocity;
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,9 @@ ZSpinParticleFactory(void) :
|
||||
_final_angle = 0.0f;
|
||||
_initial_angle_spread = 0.0f;
|
||||
_final_angle_spread = 0.0f;
|
||||
_angular_velocity = 0.0f;
|
||||
_angular_velocity_spread = 0.0f;
|
||||
_bUseAngularVelocity = false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -45,6 +48,9 @@ ZSpinParticleFactory(const ZSpinParticleFactory ©) :
|
||||
_final_angle = copy._final_angle;
|
||||
_initial_angle_spread = copy._initial_angle_spread;
|
||||
_final_angle_spread = copy._final_angle_spread;
|
||||
_angular_velocity = copy._angular_velocity;
|
||||
_angular_velocity_spread = copy._angular_velocity_spread;
|
||||
_bUseAngularVelocity = copy._bUseAngularVelocity;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -77,4 +83,6 @@ populate_child_particle(BaseParticle *bp) const {
|
||||
|
||||
zsp->set_initial_angle(_initial_angle + SPREAD(_initial_angle_spread));
|
||||
zsp->set_final_angle(_final_angle + SPREAD(_final_angle_spread));
|
||||
zsp->set_angular_velocity(_angular_velocity + SPREAD(_angular_velocity_spread));
|
||||
zsp->enable_angular_velocity(_bUseAngularVelocity);
|
||||
}
|
||||
|
@ -31,10 +31,11 @@ private:
|
||||
virtual void populate_child_particle(BaseParticle *bp) const;
|
||||
virtual BaseParticle *alloc_particle(void) const;
|
||||
|
||||
float _initial_angle;
|
||||
float _final_angle;
|
||||
float _initial_angle_spread;
|
||||
float _final_angle_spread;
|
||||
float _initial_angle,_initial_angle_spread;
|
||||
float _final_angle,_final_angle_spread;
|
||||
float _angular_velocity,_angular_velocity_spread;
|
||||
bool _bUseAngularVelocity;
|
||||
|
||||
|
||||
PUBLISHED:
|
||||
ZSpinParticleFactory(void);
|
||||
@ -50,6 +51,15 @@ PUBLISHED:
|
||||
INLINE float get_final_angle(void) const;
|
||||
INLINE float get_initial_angle_spread(void) const;
|
||||
INLINE float get_final_angle_spread(void) const;
|
||||
|
||||
INLINE void set_angular_velocity(float v);
|
||||
INLINE float get_angular_velocity(void) const;
|
||||
|
||||
INLINE void set_angular_velocity_spread(float spread);
|
||||
INLINE float get_angular_velocity_spread(void) const;
|
||||
|
||||
INLINE void enable_angular_velocity(bool bEnabled);
|
||||
INLINE bool get_angular_velocity_enabled(void) const;
|
||||
};
|
||||
|
||||
#include "zSpinParticleFactory.I"
|
||||
|
Loading…
x
Reference in New Issue
Block a user