18 return sqrt(((*p1)[0] - (*p2)[0]) * ((*p1)[0] - (*p2)[0]) +
19 ((*p1)[1] - (*p2)[1]) * ((*p1)[1] - (*p2)[1]) +
20 ((*p1)[2] - (*p2)[2]) * ((*p1)[2] - (*p2)[2]));
33 object->speed[it] =
object->speed[it] + (
object->acceleration[it] * delta_t) / 1000000.0;
34 object->position[it] =
object->position[it] + (
object->speed[it] * delta_t) / 1000000.0 + (object->
acceleration[it] * (delta_t / 1000000.0) * (delta_t / 1000000.0)) / 2.0;
35 object->angular_speed[it] =
object->angular_speed[it] + (
object->angular_acceleration[it] * delta_t) / 1000000.0;
36 object->speed[it] =
object->speed[it] + (
object->gravity[it] * delta_t) / 1000000.0;
51 object->position[it] =
object->position[it] - ((
object->speed[it] * delta_t) / 1000000.0 + (object->
acceleration[it] * (delta_t / 1000000.0) * (delta_t / 1000000.0)) / 2.0);
52 object->speed[it] =
object->speed[it] - (
object->acceleration[it] * delta_t) / 1000000.0;
53 object->angular_speed[it] =
object->angular_speed[it] - (
object->angular_acceleration[it] * delta_t) / 1000000.0;
65 for (
int it = 0; it < 3; it++) {
66 object->speed[it] = -
object->speed[it];
67 object->acceleration[it] = -
object->acceleration[it];
68 object->angular_speed[it] = -
object->angular_speed[it];
72 object->speed[it] = -
object->speed[it];
73 object->acceleration[it] = -
object->acceleration[it];
74 object->angular_speed[it] = -
object->angular_speed[it];
86 object->delta_t = delta_t;
87 for (
int it = 0; it < 3; it++) {
100 return ((a * b) >= 0);
113 double a1 = 0, a2 = 0, b1 = 0, b2 = 0, c1 = 0, c2 = 0,
114 r1 = 0, r2 = 0, r3 = 0, r4 = 0,
115 denom = 0, offset = 0, num = 0;
119 a1 = (*p2)[1] - (*p1)[1];
120 b1 = (*p1)[0] - (*p2)[0];
121 c1 = ((*p2)[0] * (*p1)[1]) - ((*p1)[0] * (*p2)[1]);
124 r3 = ((a1 * (*p3)[0]) + (b1 * (*p3)[1]) + c1);
125 r4 = ((a1 * (*p4)[0]) + (b1 * (*p4)[1]) + c1);
129 if ((r3 != 0) && (r4 != 0) &&
same_sign(r3, r4)) {
134 a2 = (*p4)[1] - (*p3)[1];
135 b2 = (*p3)[0] - (*p4)[0];
136 c2 = ((*p4)[0] * (*p3)[1]) - ((*p3)[0] * (*p4)[1]);
139 r1 = (a2 * (*p1)[0]) + (b2 * (*p1)[1]) + c2;
140 r2 = (a2 * (*p2)[0]) + (b2 * (*p2)[1]) + c2;
145 if ((r1 != 0) && (r2 != 0) &&
same_sign(r1, r2)) {
150 denom = (a1 * b2) - (a2 * b1);
165 num = (b1 * c2) - (b2 * c1);
167 (*px)[0] = (num - offset) / denom;
169 (*px)[0] = (num + offset) / denom;
172 num = (a2 * c1) - (a1 * c2);
174 (*px)[1] = (num - offset) / denom;
176 (*px)[1] = (num + offset) / denom;
190 return (*vec1)[0] * (*vec2)[0] + (*vec1)[1] * (*vec2)[1] + (*vec1)[2] * (*vec2)[2];
200 for (
int i = 0; i < 3; i++) {
201 res += pow((*vec)[i], 2);
#define __n_assert(__ptr, __ret)
macro to assert things
VECTOR3D acceleration
ax,ay,az actual acceleration
double vector_dot_product(VECTOR3D *vec1, VECTOR3D *vec2)
Compute the dot product of two VECTOR3D.
#define VECTOR3D_COLLINEAR
value when the two VECTOR3D are collinear
double distance(VECTOR3D *p1, VECTOR3D *p2)
compute the distance between two VECTOR3D points
#define VECTOR3D_DO_INTERSECT
value when the two VECTOR3D are intersecting
double VECTOR3D[3]
struct of a point
double vector_angle_between(VECTOR3D *vec1, VECTOR3D *vec2)
Compute angle between two VECTOR3D.
int update_physics_position_nb(PHYSICS *object, int it, double delta_t)
Update object position component.
#define VECTOR3D_DONT_INTERSECT
value when the two VECTOR3D are not connected
int update_physics_position_reverse(PHYSICS *object, double delta_t)
Update object position, reversed.
int update_physics_position_reverse_nb(PHYSICS *object, int it, double delta_t)
Update object position component, reversed.
double vector_normalize(VECTOR3D *vec)
Return the normalized value of vec.
int update_physics_position(PHYSICS *object, double delta_t)
Update object position, reversed.
int vector_intersect(VECTOR3D *p1, VECTOR3D *p2, VECTOR3D *p3, VECTOR3D *p4, VECTOR3D *px)
Compute if two vectors are intersecting or not.
structure of the physics of an object
static int same_sign(double a, double b)
Quickly check if two walues are the same sign or not.
Simple 3D movement simulation.