gravity

emulation of a bouncing ball with dampening factor when it "hits" the floor, friction factor because of the "air" and a bouncing ceiling for if you throw it too hard into the air ;) gravity sets the rate the speed of the ball will change over time. height sets the starting position of the ball when a trigger is received in the trigger input. throw sets the starting speed of the ball when a trigger is received in the trigger input.
Author: Remco van der Most
License: BSD
Github: sss/env/gravity.axo

Inlets

bool32 trig

Outlets

frac32 out

bool32 gate

Parameters

frac32.u.map height

frac32.u.map gravity

frac32.u.map damp

frac32.u.map friction

frac32.s.map throw

Declaration
int32_t height;
int32_t speed;
int trig;
int32_t gravity;
Init
height = 1 << 27;
Control Rate
if ((inlet_trig > 0) && !trig) {
  trig = 1;
  // height=1<<27;
  height = param_height;
  speed = param_throw >> 7;
}
if (inlet_trig < 1) {
  trig = 0;
}
gravity = ___SMMUL(param_gravity << 3, param_gravity << 2);
outlet_gate = 0;
if (height <= 0) {
  speed = speed > 0 ? speed : -speed;
  speed = ___SMMUL(speed << 3, param_damp << 2);
  outlet_gate = (1 << 27);
}
if (height >= (1 << 27)) {
  speed = speed > 0 ? -speed : speed;
}
speed -= (gravity >> 12);
speed =
    speed - ___SMMUL(___SMMUL(speed << 6, (speed > 0 ? speed : -speed) << 7),
                     param_friction >> 3);
height += speed;
height = height < 0 ? 0 : height;
outlet_out = height;

Privacy

© 2024 Zrna Research