2019-07-20 15:15:51 +02:00
|
|
|
/*
|
2019-10-04 05:04:12 +02:00
|
|
|
* This software is licensed under the terms of the MIT License.
|
2019-07-20 15:15:51 +02:00
|
|
|
* 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>.
|
2019-07-20 15:15:51 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "move.h"
|
2019-07-25 02:31:02 +02:00
|
|
|
#include "util/miscmath.h"
|
2019-07-20 15:15:51 +02:00
|
|
|
|
2019-12-18 15:19:13 +01:00
|
|
|
cmplx move_update(cmplx *restrict pos, MoveParams *restrict p) {
|
2023-02-15 23:57:41 +01:00
|
|
|
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);
|
2023-02-15 23:57:41 +01:00
|
|
|
|
|
|
|
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);
|
2023-02-15 23:57:41 +01:00
|
|
|
} else {
|
2023-02-24 03:29:54 +01:00
|
|
|
real m = cabs2(av);
|
|
|
|
assume(m >= 0);
|
|
|
|
m = pow(m, o.attraction_exponent - 0.5);
|
2023-02-24 03:51:21 +01:00
|
|
|
assert(isfinite(m));
|
2023-09-23 13:59:51 +02:00
|
|
|
o.velocity += cmul_finite(o.attraction, av * m);
|
2023-02-15 23:57:41 +01:00
|
|
|
}
|
2019-07-25 02:31:02 +02:00
|
|
|
}
|
|
|
|
|
2023-02-15 23:57:41 +01:00
|
|
|
p->velocity = o.velocity;
|
|
|
|
return orig_velocity;
|
2019-07-20 15:15:51 +02:00
|
|
|
}
|
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;
|
|
|
|
}
|