prosperon/source/engine/gameobject.c

34 lines
913 B
C
Raw Normal View History

2021-11-30 21:29:18 -06:00
#include "gameobject.h"
2023-12-24 09:14:46 -06:00
#include "math.h"
2024-10-29 12:41:17 -05:00
#include <chipmunk/chipmunk.h>
2021-11-30 21:29:18 -06:00
2022-08-26 09:19:17 -05:00
#include "stb_ds.h"
static void velocityFn(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt)
{
2024-10-29 12:41:17 -05:00
/* gameobject *go = body2go(body);
2024-05-28 13:39:02 -05:00
gameobject_apply(go);
2024-01-04 08:14:37 -06:00
cpVect pos = cpBodyGetPosition(body);
2024-04-12 13:53:00 -05:00
HMM_Vec2 g = warp_force((HMM_Vec3){pos.x, pos.y, 0}, go->warp_mask).xy;
2023-11-20 07:49:14 -06:00
if (!go) {
2024-01-04 08:14:37 -06:00
cpBodyUpdateVelocity(body,g.cp,damping,dt);
2023-11-20 07:49:14 -06:00
return;
}
2024-03-13 16:30:55 -05:00
// cpFloat d = isfinite(go->damping) ? go->damping : damping;
cpFloat d = damping;
2023-11-20 07:49:14 -06:00
2024-01-04 08:14:37 -06:00
cpBodyUpdateVelocity(body,g.cp,d,dt*go->timescale);
2023-12-26 15:39:46 -06:00
if (isfinite(go->maxvelocity))
cpBodySetVelocity(body, cpvclamp(cpBodyGetVelocity(body), go->maxvelocity));
2023-11-20 07:49:14 -06:00
2023-12-26 15:39:46 -06:00
if (isfinite(go->maxangularvelocity)) {
float av = cpBodyGetAngularVelocity(body);
if (fabs(av) > go->maxangularvelocity)
cpBodySetAngularVelocity(body, copysignf(go->maxangularvelocity, av));
}
2024-10-29 12:41:17 -05:00
*/
2021-11-30 21:29:18 -06:00
}