53 lines
964 B
C++
53 lines
964 B
C++
|
|
#include "motion.hpp"
|
|
|
|
void
|
|
MotionInit(Motion* motion, float x, float y, float z, int tick)
|
|
{
|
|
motion->tick = tick;
|
|
|
|
if (tick == 0)
|
|
{
|
|
VectorCreate(motion->pos, x, y, z);
|
|
}
|
|
else
|
|
{
|
|
VectorCreate(motion->vel, x, y, z);
|
|
|
|
if (tick > 0)
|
|
{
|
|
VectorSubtract(motion->vel, motion->vel, motion->pos);
|
|
VectorScale(motion->vel, motion->vel, 1.0f / tick);
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
MotionDelta(Motion* motion, float x, float y, float z, int tick)
|
|
{
|
|
MotionInit(
|
|
motion,
|
|
motion->pos[0] + x,
|
|
motion->pos[1] + y,
|
|
motion->pos[2] + z,
|
|
tick);
|
|
}
|
|
|
|
void
|
|
MotionTick(Motion* motion)
|
|
{
|
|
if (motion->tick == 0)
|
|
{
|
|
if (motion->callback)
|
|
{
|
|
motion->callback(motion);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
VectorAddition(motion->pos, motion->pos, motion->vel);
|
|
if (motion->tick > 0) motion->tick--;
|
|
}
|
|
}
|
|
|
|
|