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.
|
|
|
|
* ---
|
|
|
|
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
|
|
|
|
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef IGUARD_move_h
|
|
|
|
#define IGUARD_move_h
|
|
|
|
|
|
|
|
#include "taisei.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simple generalized projectile movement based on laochailan's idea
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct MoveParams {
|
|
|
|
complex velocity, acceleration, retention;
|
2019-08-11 09:07:40 +02:00
|
|
|
complex attraction;
|
2019-07-25 02:31:02 +02:00
|
|
|
complex attraction_point;
|
2019-08-11 09:07:40 +02:00
|
|
|
double attraction_max_speed;
|
2019-07-20 15:15:51 +02:00
|
|
|
} MoveParams;
|
|
|
|
|
2019-07-25 02:31:02 +02:00
|
|
|
complex move_update(complex *restrict pos, MoveParams *restrict params);
|
2019-10-06 12:50:58 +02:00
|
|
|
complex move_update_multiple(uint times, complex *restrict pos, MoveParams *restrict params);
|
2019-07-20 15:15:51 +02:00
|
|
|
|
2019-08-04 00:40:46 +02:00
|
|
|
INLINE MoveParams move_linear(complex vel) {
|
2019-07-20 15:15:51 +02:00
|
|
|
return (MoveParams) { vel, 0, 1 };
|
|
|
|
}
|
|
|
|
|
2019-08-04 00:40:46 +02:00
|
|
|
INLINE MoveParams move_accelerated(complex vel, complex accel) {
|
2019-07-20 15:15:51 +02:00
|
|
|
return (MoveParams) { vel, accel, 1 };
|
|
|
|
}
|
|
|
|
|
2019-08-04 00:40:46 +02:00
|
|
|
INLINE MoveParams move_asymptotic(complex vel0, complex vel1, complex retention) {
|
2019-07-20 15:15:51 +02:00
|
|
|
// NOTE: retention could be derived by something like: exp(-1 / halflife)
|
|
|
|
return (MoveParams) { vel0, vel1 * (1 - retention), retention };
|
|
|
|
}
|
|
|
|
|
2019-08-04 00:40:46 +02:00
|
|
|
INLINE MoveParams move_asymptotic_simple(complex vel, double boost_factor) {
|
2019-07-24 19:40:19 +02:00
|
|
|
// NOTE: this matches the old asymptotic rule semantics exactly
|
|
|
|
double retention = 0.8;
|
|
|
|
return move_asymptotic(vel * (1 + boost_factor * retention), vel, retention);
|
|
|
|
}
|
|
|
|
|
2019-09-01 02:23:36 +02:00
|
|
|
INLINE MoveParams move_towards(complex target, complex attraction) {
|
|
|
|
return (MoveParams) {
|
|
|
|
.attraction = attraction,
|
|
|
|
.attraction_point = target,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-10-06 12:50:58 +02:00
|
|
|
INLINE MoveParams move_stop(complex retention) {
|
|
|
|
return (MoveParams) { .retention = retention };
|
|
|
|
}
|
|
|
|
|
2019-07-20 15:15:51 +02:00
|
|
|
#endif // IGUARD_move_h
|