20 return sqrt( ( (*p1)[ 0 ] - (*p2)[ 0 ] ) * ( (*p1)[ 0 ] - (*p2)[ 0 ] ) +
21 ( (*p1)[ 1 ] - (*p2)[ 1 ] ) * ( (*p1)[ 1 ] - (*p2)[ 1 ] ) +
22 ( (*p1)[ 2 ] - (*p2)[ 2 ] ) * ( (*p1)[ 2 ] - (*p2)[ 2 ] ) );
38 object -> speed[ it ] =
object -> speed[ it ] + (
object -> acceleration[ it ] * delta_t )/ 1000000.0 ;
39 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 ;
40 object -> angular_speed[ it ] =
object -> angular_speed[ it ] + (
object -> angular_acceleration[ it ] * delta_t ) / 1000000.0 ;
41 object -> speed[ it ] =
object -> speed[ it ] + (
object -> gravity[ it ] * delta_t ) / 1000000.0 ;
59 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 );
60 object -> speed[ it ] =
object -> speed[ it ] - (
object -> acceleration[ it ] * delta_t )/ 1000000.0 ;
61 object -> angular_speed[ it ] =
object -> angular_speed[ it ] - (
object -> angular_acceleration[ it ] * delta_t ) / 1000000.0 ;
75 for(
int it = 0 ; it < 3 ; it ++ )
77 object -> speed[ it ] = -
object -> speed[ it ] ;
78 object -> acceleration[ it ] = -
object -> acceleration[ it ] ;
79 object -> angular_speed[ it ] = -
object -> angular_speed[ it ];
83 object -> speed[ it ] = -
object -> speed[ it ] ;
84 object -> acceleration[ it ] = -
object -> acceleration[ it ] ;
85 object -> angular_speed[ it ] = -
object -> angular_speed[ it ] ;
100 object -> delta_t = delta_t ;
101 for(
int it = 0 ; it < 3 ; it ++ )
118 return (( a * b) >= 0 );
134 double a1 = 0, a2 = 0, b1 = 0, b2 = 0, c1 = 0, c2 = 0,
135 r1 = 0, r2 = 0, r3 = 0, r4 = 0,
136 denom = 0, offset = 0, num = 0 ;
140 a1 = (*p2)[ 1 ] - (*p1)[ 1 ];
141 b1 = (*p1)[ 0 ] - (*p2)[ 0 ];
142 c1 = ((*p2)[ 0 ] * (*p1)[ 1 ]) - ((*p1)[ 0 ] * (*p2)[ 1 ]);
145 r3 = ((a1 * (*p3)[ 0 ]) + (b1 * (*p3)[ 1 ]) + c1);
146 r4 = ((a1 * (*p4)[ 0 ]) + (b1 * (*p4)[ 1 ]) + c1);
150 if((r3 != 0) && (r4 != 0) &&
same_sign(r3, r4))
156 a2 = (*p4)[ 1 ] - (*p3)[ 1 ];
157 b2 = (*p3)[ 0 ] - (*p4)[ 0 ];
158 c2 = ((*p4)[ 0 ] * (*p3)[ 1 ]) - ((*p3)[ 0 ] * (*p4)[ 1 ]);
161 r1 = (a2 * (*p1)[ 0 ]) + (b2 * (*p1)[ 1 ]) + c2;
162 r2 = (a2 * (*p2)[ 0 ]) + (b2 * (*p2)[ 1 ]) + c2;
167 if( (r1 != 0) && (r2 != 0) &&
same_sign(r1, r2) )
173 denom = (a1 * b2) - (a2 * b1);
192 num = (b1 * c2) - (b2 * c1);
195 (*px)[ 0 ] = (num - offset) / denom;
199 (*px)[ 0 ] = (num + offset) / denom;
202 num = (a2 * c1) - (a1 * c2);
205 (*px)[ 1 ] = ( num - offset) / denom;
209 (*px)[ 1 ] = (num + offset) / denom;
226 return (*vec1)[ 0 ] * (*vec2)[ 0 ] + (*vec1)[ 1 ] * (*vec2)[ 1 ] + (*vec1)[ 2 ] * (*vec2)[ 2 ];
239 for(
int i=0 ; i < 3 ; i++ )
241 res += pow( (*vec)[ i ], 2 );
#define __n_assert(__ptr, __ret)
macro to assert things
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 beteen two VECTOR3D.
int update_physics_position_nb(PHYSICS *object, int it, double delta_t)
Update object position componant.
#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 componant, 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 walue are the same sign or not.
Simple 3D movement simulation.