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>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "taisei.h"
|
|
|
|
|
|
|
|
#include "move.h"
|
2019-07-25 02:31:02 +02:00
|
|
|
#include "util/miscmath.h"
|
2019-07-20 15:15:51 +02:00
|
|
|
|
2019-07-25 02:31:02 +02:00
|
|
|
complex move_update(complex *restrict pos, MoveParams *restrict p) {
|
2019-07-20 15:15:51 +02:00
|
|
|
complex v = p->velocity;
|
2019-07-25 02:31:02 +02:00
|
|
|
|
|
|
|
*pos += v;
|
2019-07-20 15:15:51 +02:00
|
|
|
p->velocity = p->acceleration + p->retention * v;
|
2019-07-25 02:31:02 +02:00
|
|
|
|
2019-08-11 09:07:40 +02:00
|
|
|
if(p->attraction) {
|
2019-07-25 02:31:02 +02:00
|
|
|
complex av = p->attraction_point - *pos;
|
2019-08-11 09:07:40 +02:00
|
|
|
|
|
|
|
if(p->attraction_max_speed) {
|
|
|
|
av = cclampabs(av, p->attraction_max_speed);
|
|
|
|
}
|
|
|
|
|
2019-07-25 02:31:02 +02:00
|
|
|
p->velocity += p->attraction * av;
|
|
|
|
}
|
|
|
|
|
2019-07-20 15:15:51 +02:00
|
|
|
return v;
|
|
|
|
}
|
2019-10-06 12:50:58 +02:00
|
|
|
|
|
|
|
complex move_update_multiple(uint times, complex *restrict pos, MoveParams *restrict p) {
|
|
|
|
complex v = p->velocity;
|
|
|
|
|
|
|
|
while(times--) {
|
|
|
|
move_update(pos, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|