6 Module PHYSICS
gullradriel edited this page 2026-10-29 20:54:40 +01:00

PHYSICS: simple 3D movement simulation

Structures

Name
struct PHYSICS
structure of the physics of an object

Types

Name
typedef double[3] VECTOR3D
struct of a point

Functions

Name
double vector_normalize(VECTOR3D * vec)
vector normalize
int vector_intersect(VECTOR3D * p1, VECTOR3D * p2, VECTOR3D * p3, VECTOR3D * p4, VECTOR3D * px)
compute if two vector are colliding, storing the resulting point in px
double vector_dot_product(VECTOR3D * vec1, VECTOR3D * vec2)
dot product
double vector_angle_between(VECTOR3D * vec1, VECTOR3D * vec2)
vector angle with other vector
int update_physics_position_reverse_nb(PHYSICS * object, int it, double delta_t)
update component[ it ] of a VECTOR3D, reversed time
int update_physics_position_reverse(PHYSICS * object, double delta_t)
update the position of an object, using the delta time T to reverse update positions
int update_physics_position_nb(PHYSICS * object, int it, double delta_t)
update component[ it ] of a VECTOR3D
int update_physics_position(PHYSICS * object, double delta_t)
update the position of an object, using the delta time T to update positions
double distance(VECTOR3D * p1, VECTOR3D * p2)
distance between two points

Defines

Name
copy_point(_src, _dst)
VECTOR3D copy wrapper.
VECTOR3D_SET(VECTOR, X, Y, Z)
helper to set a VECTOR3D position
VECTOR3D_DO_INTERSECT
value when the two VECTOR3D are intersecting
VECTOR3D_DONT_INTERSECT
value when the two VECTOR3D are not connected
VECTOR3D_COLLINEAR
value when the two VECTOR3D are collinear
MOVE_STOPPED
PHYSICS object state for STOPPED.
MOVE_SIMU
PHYSICS object state for move simulated from latest update.
MOVE_INTER
PHYSICS object state for move interpolated between two position.

Types Documentation

typedef VECTOR3D

typedef double VECTOR3D[3];

struct of a point

Functions Documentation

function vector_normalize

double vector_normalize(
    VECTOR3D * vec
)

vector normalize

Parameters:

Return: normalized value of vec

Return the normalized value of vec.

vector normalize

function vector_intersect

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

compute if two vector are colliding, storing the resulting point in px

Parameters:

  • p1 First point of vector 1
  • p2 Second point of vector 1
  • p3 First point of vector 2
  • p4 Second point of vector 2
  • px Storage for the eventual point

Return: VECTOR3D_DONT_INTERSECT , VECTOR3D_COLLINEAR or VECTOR3D_DO_INTERSECT

Compute if two vectors are intersecting or not.

compute if two vector are colliding, storing the resulting point in px

function vector_dot_product

double vector_dot_product(
    VECTOR3D * vec1,
    VECTOR3D * vec2
)

dot product

Parameters:

Return: dot product value

Compute the dot product of two VECTOR3D.

dot product

function vector_angle_between

double vector_angle_between(
    VECTOR3D * vec1,
    VECTOR3D * vec2
)

vector angle with other vector

Parameters:

Return: angle between vectors in rad (todeg = returnval * 180/PI_2)

Compute angle between two VECTOR3D.

vector angle with other vector

function update_physics_position_reverse_nb

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

update component[ it ] of a VECTOR3D, reversed time

Parameters:

  • object The object physics to update
  • it component of VECTOR3D to update. it values : 0 -> x, 1 -> y , 2 -> z
  • delta_t Elapsed time since last call for component update computing

Return: TRUE or FALSE

Update object position component, reversed.

update component[ it ] of a VECTOR3D, reversed time

function update_physics_position_reverse

int update_physics_position_reverse(
    PHYSICS * object,
    double delta_t
)

update the position of an object, using the delta time T to reverse update positions

Parameters:

  • object The object physics to update
  • delta_t Elapsed time since last call for component update computing

Return: TRUE or FALSE

Update object position, reversed.

update the position of an object, using the delta time T to reverse update positions

Wrapper of update_physics_position_reverse_nb to update each component.

function update_physics_position_nb

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

update component[ it ] of a VECTOR3D

Parameters:

  • object The object physics to update
  • it component of VECTOR3D to update. it values : 0 -> x, 1 -> y , 2 -> z
  • delta_t Elapsed time since last call for component update computing

Return: TRUE or FALSE

Update object position component.

update component[ it ] of a VECTOR3D

function update_physics_position

int update_physics_position(
    PHYSICS * object,
    double delta_t
)

update the position of an object, using the delta time T to update positions

Parameters:

  • object The object physics to update
  • delta_t Elapsed time since last call for component update computing

Return: TRUE or FALSE

Update object position.

update the position of an object, using the delta time T to update positions

Wrapper of update_physics_position_nb to update each component.

function distance

double distance(
    VECTOR3D * p1,
    VECTOR3D * p2
)

distance between two points

Parameters:

  • p1 The first point
  • p2 The second point

Return: The computed distance

compute the distance between two VECTOR3D points

distance between two points

Macros Documentation

define copy_point

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

VECTOR3D copy wrapper.

define VECTOR3D_SET

#define VECTOR3D_SET(
    VECTOR,
    X,
    Y,
    Z
)
do {                              \
    VECTOR[0] = (X);              \
    VECTOR[1] = (Y);              \
    VECTOR[2] = (Z);              \
} while (0)

helper to set a VECTOR3D position

define VECTOR3D_DO_INTERSECT

#define VECTOR3D_DO_INTERSECT 0

value when the two VECTOR3D are intersecting

define VECTOR3D_DONT_INTERSECT

#define VECTOR3D_DONT_INTERSECT -2

value when the two VECTOR3D are not connected

define VECTOR3D_COLLINEAR

#define VECTOR3D_COLLINEAR -1

value when the two VECTOR3D are collinear

define MOVE_STOPPED

#define MOVE_STOPPED 0

PHYSICS object state for STOPPED.

define MOVE_SIMU

#define MOVE_SIMU 2

PHYSICS object state for move simulated from latest update.

define MOVE_INTER

#define MOVE_INTER 1

PHYSICS object state for move interpolated between two position.