taisei/src/move.c

45 lines
1 KiB
C
Raw Normal View History

/*
2019-10-04 05:04:12 +02:00
* This software is licensed under the terms of the MIT License.
* See COPYING for further information.
* ---
2024-05-16 23:30:41 +02:00
* Copyright (c) 2011-2024, Lukas Weber <laochailan@web.de>.
* Copyright (c) 2012-2024, Andrei Alexeyev <akari@taisei-project.org>.
*/
#include "move.h"
2019-07-25 02:31:02 +02:00
#include "util/miscmath.h"
2019-12-18 15:19:13 +01:00
cmplx move_update(cmplx *restrict pos, MoveParams *restrict p) {
MoveParams o = *p;
cmplx orig_velocity = o.velocity;
*pos += orig_velocity;
2023-09-23 13:59:51 +02:00
o.velocity = o.acceleration + cmul_finite(o.retention, o.velocity);
if(o.attraction) {
cmplx av = o.attraction_point - *pos;
if(LIKELY(o.attraction_exponent == 1)) {
2023-09-23 13:59:51 +02:00
o.velocity += cmul_finite(o.attraction, av);
} else {
real m = cabs2(av);
assume(m >= 0);
m = pow(m, o.attraction_exponent - 0.5);
assert(isfinite(m));
2023-09-23 13:59:51 +02:00
o.velocity += cmul_finite(o.attraction, av * m);
}
2019-07-25 02:31:02 +02:00
}
p->velocity = o.velocity;
return orig_velocity;
}
2019-10-06 12:50:58 +02:00
2019-12-18 15:19:13 +01:00
cmplx move_update_multiple(uint times, cmplx *restrict pos, MoveParams *restrict p) {
cmplx v = p->velocity;
2019-10-06 12:50:58 +02:00
while(times--) {
move_update(pos, p);
}
return v;
}