Open source remastering of the Freespace 2 engine
physics.cpp File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "ai/ai_profiles.h"
#include "freespace2/freespace.h"
#include "io/timer.h"
#include "mission/missionparse.h"
#include "mod_table/mod_table.h"
#include "physics/physics.h"
#include "ship/ship.h"

Go to the source code of this file.


#define MAX_TURN_LIMIT   0.2618f
#define ROTVEL_TOL   0.1
#define ROTVEL_CAP   14.0
#define DEAD_ROTVEL_CAP   16.3
#define MAX_SHIP_SPEED   500
#define RESET_SHIP_SPEED   440
#define SW_ROT_FACTOR   5
#define SW_BLAST_DURATION   2000
#define REDUCED_DAMP_VEL   30
#define REDUCED_DAMP_TIME   2000
#define WEAPON_SHAKE_TIME   500
#define SPECIAL_WARP_T_CONST   0.651
#define WHACK_LIMIT   0.001f
#define ROTVEL_WHACK_CONST   0.12
#define STD_PRESSURE   1000
#define MIN_RADIUS   10
#define MAX_RADIUS   50
#define MAX_ROTVEL   0.4
#define MAX_SHAKE   0.1
#define MAX_VEL   8


void update_reduced_damp_timestamp (physics_info *pi, float impulse)
float velocity_ramp (float v_in, float v_goal, float time_const, float t)
float glide_ramp (float v_in, float v_goal, float ramp_time_const, float accel_mult, float t)
void physics_init (physics_info *pi)
void apply_physics (float damping, float desired_vel, float initial_vel, float t, float *new_vel, float *delta_pos)
void physics_set_viewer (physics_info *p, int dir)
void physics_sim_rot (matrix *orient, physics_info *pi, float sim_time)
void physics_sim_rot_editor (matrix *orient, physics_info *pi, float sim_time)
void physics_sim_vel (vec3d *position, physics_info *pi, float sim_time, matrix *orient)
void physics_sim (vec3d *position, matrix *orient, physics_info *pi, float sim_time)
void physics_sim_editor (vec3d *position, matrix *orient, physics_info *pi, float sim_time)
void physics_predict_pos (physics_info *pi, float delta_time, vec3d *predicted_pos)
void physics_predict_vel (physics_info *pi, float delta_time, vec3d *predicted_vel)
void physics_predict_pos_and_vel (physics_info *pi, float delta_time, vec3d *predicted_vel, vec3d *predicted_pos)
void physics_read_flying_controls (matrix *orient, physics_info *pi, control_info *ci, float sim_time, vec3d *wash_rot)
void physics_set_rotvel_and_saturate (float *dest, float delta)
void physics_apply_whack (vec3d *impulse, vec3d *pos, physics_info *pi, matrix *orient, float mass)
void physics_apply_shock (vec3d *direction_vec, float pressure, physics_info *pi, matrix *orient, vec3d *min, vec3d *max, float radius)
void physics_collide_whack (vec3d *impulse, vec3d *world_delta_rotvel, physics_info *pi, matrix *orient, bool is_landing)
int check_rotvel_limit (physics_info *pi)


float Physics_viewer_bank = 0.0f
int Physics_viewer_direction = PHYSICS_VIEWER_FRONT
physics_infoViewer_physics_info = NULL

Macro Definition Documentation


Definition at line 443 of file physics.cpp.

#define DEAD_ROTVEL_CAP   16.3

Definition at line 32 of file physics.cpp.

#define MAX_RADIUS   50

Definition at line 903 of file physics.cpp.

#define MAX_ROTVEL   0.4

Definition at line 904 of file physics.cpp.

#define MAX_SHAKE   0.1

Definition at line 905 of file physics.cpp.

#define MAX_SHIP_SPEED   500

Definition at line 34 of file physics.cpp.

#define MAX_TURN_LIMIT   0.2618f

Definition at line 28 of file physics.cpp.

#define MAX_VEL   8

Definition at line 906 of file physics.cpp.

#define MIN_RADIUS   10

Definition at line 902 of file physics.cpp.


Definition at line 39 of file physics.cpp.

#define REDUCED_DAMP_TIME   2000

Definition at line 41 of file physics.cpp.

#define REDUCED_DAMP_VEL   30

Definition at line 40 of file physics.cpp.

#define RESET_SHIP_SPEED   440

Definition at line 35 of file physics.cpp.

#define ROTVEL_CAP   14.0

Definition at line 31 of file physics.cpp.


Definition at line 1025 of file physics.cpp.

#define ROTVEL_TOL   0.1

Definition at line 30 of file physics.cpp.

#define ROTVEL_WHACK_CONST   0.12

Definition at line 775 of file physics.cpp.

#define SPECIAL_WARP_T_CONST   0.651

Definition at line 43 of file physics.cpp.

#define STD_PRESSURE   1000

Definition at line 901 of file physics.cpp.

#define SW_BLAST_DURATION   2000

Definition at line 38 of file physics.cpp.

#define SW_ROT_FACTOR   5

Definition at line 37 of file physics.cpp.

#define WEAPON_SHAKE_TIME   500

Definition at line 42 of file physics.cpp.

#define WHACK_LIMIT   0.001f

Definition at line 774 of file physics.cpp.

Function Documentation

void apply_physics ( float  damping,
float  desired_vel,
float  initial_vel,
float  t,
float new_vel,
float delta_pos 

Definition at line 108 of file physics.cpp.

int check_rotvel_limit ( physics_info pi)

Definition at line 1064 of file physics.cpp.

float glide_ramp ( float  v_in,
float  v_goal,
float  ramp_time_const,
float  accel_mult,
float  t 

Definition at line 857 of file physics.cpp.

void physics_apply_shock ( vec3d direction_vec,
float  pressure,
physics_info pi,
matrix orient,
vec3d min,
vec3d max,
float  radius 

Definition at line 907 of file physics.cpp.

void physics_apply_whack ( vec3d impulse,
vec3d pos,
physics_info pi,
matrix orient,
float  mass 

Definition at line 776 of file physics.cpp.

void physics_collide_whack ( vec3d impulse,
vec3d world_delta_rotvel,
physics_info pi,
matrix orient,
bool  is_landing 

Definition at line 1026 of file physics.cpp.

void physics_init ( physics_info pi)

Definition at line 49 of file physics.cpp.

void physics_predict_pos ( physics_info pi,
float  delta_time,
vec3d predicted_pos 

Definition at line 394 of file physics.cpp.

void physics_predict_pos_and_vel ( physics_info pi,
float  delta_time,
vec3d predicted_vel,
vec3d predicted_pos 

Definition at line 424 of file physics.cpp.

void physics_predict_vel ( physics_info pi,
float  delta_time,
vec3d predicted_vel 

Definition at line 407 of file physics.cpp.

void physics_read_flying_controls ( matrix orient,
physics_info pi,
control_info ci,
float  sim_time,
vec3d wash_rot 

Definition at line 449 of file physics.cpp.

void physics_set_rotvel_and_saturate ( float dest,
float  delta 

Definition at line 744 of file physics.cpp.

void physics_set_viewer ( physics_info p,
int  dir 

Definition at line 135 of file physics.cpp.

void physics_sim ( vec3d position,
matrix orient,
physics_info pi,
float  sim_time 

Definition at line 364 of file physics.cpp.

void physics_sim_editor ( vec3d position,
matrix orient,
physics_info pi,
float  sim_time 

Definition at line 385 of file physics.cpp.

void physics_sim_rot ( matrix orient,
physics_info pi,
float  sim_time 

Definition at line 151 of file physics.cpp.

void physics_sim_rot_editor ( matrix orient,
physics_info pi,
float  sim_time 

Definition at line 223 of file physics.cpp.

void physics_sim_vel ( vec3d position,
physics_info pi,
float  sim_time,
matrix orient 

Definition at line 263 of file physics.cpp.

void update_reduced_damp_timestamp ( physics_info pi,
float  impulse 

Definition at line 1111 of file physics.cpp.

float velocity_ramp ( float  v_in,
float  v_goal,
float  time_const,
float  t 

Definition at line 824 of file physics.cpp.

Variable Documentation

float Physics_viewer_bank = 0.0f

Definition at line 128 of file physics.cpp.

int Physics_viewer_direction = PHYSICS_VIEWER_FRONT

Definition at line 129 of file physics.cpp.

physics_info* Viewer_physics_info = NULL

Definition at line 130 of file physics.cpp.