Nilorea Library
C utilities for networking, threading, graphics
PHYSICS: simple 3D movement simulation

Data Structures

struct  PHYSICS
 structure of the physics of an object More...
 

Macros

#define copy_point(__src_, __dst_)    memcpy( __dst_ , __src_ , sizeof( VECTOR3D ) );
 VECTOR3D copy wrapper. More...
 
#define MOVE_INTER   1
 PHYSICS object state for move interpolated between two position. More...
 
#define MOVE_SIMU   2
 PHYSICS object state for move simulated from latest update. More...
 
#define MOVE_STOPPED   0
 PHYSICS object state for STOPPED. More...
 
#define VECTOR3D_COLLINEAR   -1
 value when the two VECTOR3D are collinear More...
 
#define VECTOR3D_DO_INTERSECT   0
 value when the two VECTOR3D are intersecting More...
 
#define VECTOR3D_DONT_INTERSECT   -2
 value when the two VECTOR3D are not connected More...
 
#define VECTOR3D_SET(VECTOR, X, Y, Z)
 helper to set a VECTOR3D position More...
 

Typedefs

typedef double VECTOR3D[3]
 struct of a point More...
 

Functions

double distance (VECTOR3D *p1, VECTOR3D *p2)
 compute the distance between two VECTOR3D points More...
 
int update_physics_position (PHYSICS *object, double delta_t)
 Update object position, reversed. More...
 
int update_physics_position_nb (PHYSICS *object, int it, double delta_t)
 Update object position componant. More...
 
int update_physics_position_reverse (PHYSICS *object, double delta_t)
 Update object position, reversed. More...
 
int update_physics_position_reverse_nb (PHYSICS *object, int it, double delta_t)
 Update object position componant, reversed. More...
 
double vector_angle_between (VECTOR3D *vec1, VECTOR3D *vec2)
 Compute angle beteen two VECTOR3D. More...
 
double vector_dot_product (VECTOR3D *vec1, VECTOR3D *vec2)
 Compute the dot product of two VECTOR3D. More...
 
int vector_intersect (VECTOR3D *p0, VECTOR3D *p1, VECTOR3D *p2, VECTOR3D *p3, VECTOR3D *px)
 Compute if two vectors are intersecting or not. More...
 
double vector_normalize (VECTOR3D *vec)
 Return the normalized value of vec. More...
 

Detailed Description


Data Structure Documentation

◆ PHYSICS

struct PHYSICS

structure of the physics of an object

Examples
ex_gui_particles.c.

Definition at line 49 of file n_3d.h.

+ Collaboration diagram for PHYSICS:
Data Fields
VECTOR3D acceleration ax,ay,az actual acceleration
VECTOR3D angular_acceleration rax,ray,raz actual angular acceleration
VECTOR3D angular_speed rvx,rvy,rvz actual angular speed
int can_jump ability
time_t delta_t last delta_t used
VECTOR3D gravity gx , gy , gz gravity
VECTOR3D orientation ax,ay,az actual rotation position
VECTOR3D position x,y,z actual position
VECTOR3D speed vx,vy,vz actual speed
int sz size
int type optionnal type id

Macro Definition Documentation

◆ copy_point

#define copy_point (   __src_,
  __dst_ 
)     memcpy( __dst_ , __src_ , sizeof( VECTOR3D ) );

VECTOR3D copy wrapper.

Definition at line 95 of file n_3d.h.

◆ MOVE_INTER

#define MOVE_INTER   1

PHYSICS object state for move interpolated between two position.

Definition at line 27 of file n_3d.h.

◆ MOVE_SIMU

#define MOVE_SIMU   2

PHYSICS object state for move simulated from latest update.

Definition at line 29 of file n_3d.h.

◆ MOVE_STOPPED

#define MOVE_STOPPED   0

PHYSICS object state for STOPPED.

Definition at line 25 of file n_3d.h.

◆ VECTOR3D_COLLINEAR

#define VECTOR3D_COLLINEAR   -1

value when the two VECTOR3D are collinear

Definition at line 34 of file n_3d.h.

◆ VECTOR3D_DO_INTERSECT

#define VECTOR3D_DO_INTERSECT   0

value when the two VECTOR3D are intersecting

Definition at line 36 of file n_3d.h.

◆ VECTOR3D_DONT_INTERSECT

#define VECTOR3D_DONT_INTERSECT   -2

value when the two VECTOR3D are not connected

Definition at line 32 of file n_3d.h.

◆ VECTOR3D_SET

#define VECTOR3D_SET (   VECTOR,
  X,
  Y,
 
)
Value:
VECTOR[ 0 ] = (X) ; \
VECTOR[ 1 ] = (Y) ; \
VECTOR[ 2 ] = (Z) ;

helper to set a VECTOR3D position

Examples
ex_gui_particles.c.

Definition at line 43 of file n_3d.h.

Typedef Documentation

◆ VECTOR3D

typedef double VECTOR3D[3]

struct of a point

Definition at line 39 of file n_3d.h.

Function Documentation

◆ distance()

double distance ( VECTOR3D p1,
VECTOR3D p2 
)

compute the distance between two VECTOR3D points

Parameters
p1The first point
p2The second point
Returns
The computed distance

Definition at line 18 of file n_3d.c.

◆ update_physics_position()

int update_physics_position ( PHYSICS object,
double  delta_t 
)

Update object position, reversed.

Wrapper of update_physics_position_reverse_nb to update each componants.

Parameters
objectThe object physics to update
delta_tElapsed time since last call for componant update computing
Returns
TRUE or FALSE

Definition at line 98 of file n_3d.c.

References update_physics_position_nb().

Referenced by manage_particle_ex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update_physics_position_nb()

int update_physics_position_nb ( PHYSICS object,
int  it,
double  delta_t 
)

Update object position componant.

Parameters
objectThe object physics to update
itComponant of VECTOR3D to update. it values : 0 -> x, 1 -> y , 2 -> z
delta_tElapsed time since last call for componant update computing
Returns
TRUE or FALSE

Definition at line 34 of file n_3d.c.

References __n_assert.

Referenced by update_physics_position(), and update_physics_position_reverse().

+ Here is the caller graph for this function:

◆ update_physics_position_reverse()

int update_physics_position_reverse ( PHYSICS object,
double  delta_t 
)

Update object position, reversed.

Wrapper of update_physics_position_reverse_nb to update each componants.

Parameters
objectThe object physics to update
delta_tElapsed time since last call for componant update computing
Returns
TRUE or FALSE

Definition at line 73 of file n_3d.c.

References update_physics_position_nb().

+ Here is the call graph for this function:

◆ update_physics_position_reverse_nb()

int update_physics_position_reverse_nb ( PHYSICS object,
int  it,
double  delta_t 
)

Update object position componant, reversed.

Parameters
objectThe object physics to update
itComponant of VECTOR3D to update. it values : 0 -> x, 1 -> y , 2 -> z
delta_tElapsed time since last call for componant update computing
Returns
TRUE or FALSE

Definition at line 55 of file n_3d.c.

References __n_assert.

◆ vector_angle_between()

double vector_angle_between ( VECTOR3D vec1,
VECTOR3D vec2 
)

Compute angle beteen two VECTOR3D.

Parameters
vec1first VECTOR3D
vec2second VECTOR3D
Returns
angle between vectors in rad (todeg = returnval * 180/PI_2)

Definition at line 254 of file n_3d.c.

References vector_dot_product(), and vector_normalize().

+ Here is the call graph for this function:

◆ vector_dot_product()

double vector_dot_product ( VECTOR3D vec1,
VECTOR3D vec2 
)

Compute the dot product of two VECTOR3D.

Parameters
vec1first VECTOR3D
vec2second VECTOR3D
Returns
dot product value

Definition at line 224 of file n_3d.c.

Referenced by vector_angle_between().

+ Here is the caller graph for this function:

◆ vector_intersect()

int vector_intersect ( VECTOR3D p1,
VECTOR3D p2,
VECTOR3D p3,
VECTOR3D p4,
VECTOR3D px 
)

Compute if two vectors are intersecting or not.

Parameters
p1First point of vector 1
p2Second poinf of vector 1
p3First point of vector 2
p4Second point of vector 2
pxStorage for the eventual point
Returns
VECTOR3D_DONT_INTERSECT , VECTOR3D_COLLINEAR or VECTOR3D_DO_INTERSECT

Definition at line 132 of file n_3d.c.

References same_sign(), VECTOR3D_COLLINEAR, VECTOR3D_DO_INTERSECT, and VECTOR3D_DONT_INTERSECT.

+ Here is the call graph for this function:

◆ vector_normalize()

double vector_normalize ( VECTOR3D vec)

Return the normalized value of vec.

Parameters
vecVECTOR3D to normalize
Returns
normalized value of vec

Definition at line 236 of file n_3d.c.

Referenced by vector_angle_between().

+ Here is the caller graph for this function: