taisei/src/move.c

42 lines
860 B
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.
* ---
* 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-25 02:31:02 +02:00
complex move_update(complex *restrict pos, MoveParams *restrict p) {
complex v = p->velocity;
2019-07-25 02:31:02 +02:00
*pos += v;
p->velocity = p->acceleration + p->retention * v;
2019-07-25 02:31:02 +02:00
if(p->attraction) {
2019-07-25 02:31:02 +02:00
complex av = p->attraction_point - *pos;
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;
}
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;
}