Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_trajectory.c File Reference
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "nilorea/n_common.h"
#include "nilorea/n_log.h"
#include "nilorea/n_trajectory.h"
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_font.h>
Include dependency graph for ex_trajectory.c:

Go to the source code of this file.

Data Structures

struct  WAYPOINT3D

Macros

#define ALLEGRO_UNSTABLE   1
#define DT   (1.0 / FPS)
#define FPS   60.0
#define HEIGHT   600
#define M_PI   3.14159265358979323846
#define MAX_TRAIL   300
#define MAX_WP2D   50
#define NUM_WP3D   7
#define PANEL_W   400
#define WIDTH   800

Functions

static void draw_2d_panel (ALLEGRO_FONT *font)
static void draw_3d_axes (ALLEGRO_FONT *font)
static void draw_3d_panel (ALLEGRO_FONT *font)
static void draw_arrow (float x1, float y1, float x2, float y2, ALLEGRO_COLOR color, float thickness)
static void draw_full_path_2d (void)
static void draw_full_path_3d (void)
static void draw_ground_grid (void)
static void draw_trail (float trail[][2], int count, int head, ALLEGRO_COLOR base_color)
static void handle_click_2d (float mx, float my)
static void init_3d (void)
static void init_physics_2d (PHYSICS *p, double px, double py, double vx, double vy)
static void init_physics_3d (PHYSICS *p, double px, double py, double pz, double vx, double vy, double vz)
int main (int argc, char *argv[])
static void project_3d (double x, double y, double z, float *sx, float *sy)
static void rebuild_2d_trajectory (void)
static void reset_2d (void)
static void trail_push_2d (float x, float y)
static void trail_push_3d (float x, float y)
static void update_3d_logic (void)

Variables

static int running_2d = 0
static double time_2d = 0.0
static double time_3d = 0.0
static double time_3d_end = 0.0
static float trail_2d [300][2]
static int trail_2d_count = 0
static int trail_2d_head = 0
static float trail_3d [300][2]
static int trail_3d_count = 0
static int trail_3d_head = 0
static TRAJECTORY * traj_2d = NULL
static TRAJECTORY * traj_3d = NULL
static const WAYPOINT3D waypoints_3d [7]
static int wp2d_count = 0
static const double WP2D_SPEED = 80.0
static double wp2d_t [50]
static double wp2d_x [50]
static double wp2d_y [50]
static const double WP3D_DUR = 4.0

Data Structure Documentation

◆ WAYPOINT3D

struct WAYPOINT3D
Examples
ex_trajectory.c.

Definition at line 91 of file ex_trajectory.c.

Collaboration diagram for WAYPOINT3D:
Data Fields
double vx
double vy
double vz
double x
double y
double z

Macro Definition Documentation

◆ ALLEGRO_UNSTABLE

#define ALLEGRO_UNSTABLE   1

Definition at line 41 of file ex_trajectory.c.

◆ DT

#define DT   (1.0 / FPS)
Examples
ex_trajectory.c.

Definition at line 47 of file ex_trajectory.c.

Referenced by main(), and update_3d_logic().

◆ FPS

#define FPS   60.0

Definition at line 46 of file ex_trajectory.c.

◆ HEIGHT

#define HEIGHT   600

Definition at line 44 of file ex_trajectory.c.

◆ M_PI

#define M_PI   3.14159265358979323846

Definition at line 63 of file ex_trajectory.c.

◆ MAX_TRAIL

#define MAX_TRAIL   300
Examples
ex_trajectory.c.

Definition at line 48 of file ex_trajectory.c.

Referenced by draw_trail(), trail_push_2d(), and trail_push_3d().

◆ MAX_WP2D

#define MAX_WP2D   50
Examples
ex_trajectory.c.

Definition at line 72 of file ex_trajectory.c.

Referenced by handle_click_2d().

◆ NUM_WP3D

#define NUM_WP3D   7
Examples
ex_trajectory.c.

Definition at line 95 of file ex_trajectory.c.

Referenced by draw_3d_panel(), and init_3d().

◆ PANEL_W

#define PANEL_W   400

Definition at line 45 of file ex_trajectory.c.

◆ WIDTH

#define WIDTH   800

Definition at line 43 of file ex_trajectory.c.

Function Documentation

◆ draw_2d_panel()

void draw_2d_panel ( ALLEGRO_FONT * font)
static
Examples
ex_trajectory.c.

Definition at line 287 of file ex_trajectory.c.

References draw_arrow(), draw_full_path_2d(), draw_trail(), font, HEIGHT, mode, PANEL_W, running_2d, time_2d, trail_2d, trail_2d_count, trail_2d_head, traj_2d, TRAJECTORY_BEFORE, trajectory_compute(), TRAJECTORY_EXTRAP, TRAJECTORY_INTERP, wp2d_count, wp2d_x, and wp2d_y.

Referenced by main().

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

◆ draw_3d_axes()

void draw_3d_axes ( ALLEGRO_FONT * font)
static
Examples
ex_trajectory.c.

Definition at line 431 of file ex_trajectory.c.

References draw_arrow(), font, and project_3d().

Referenced by draw_3d_panel().

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

◆ draw_3d_panel()

void draw_3d_panel ( ALLEGRO_FONT * font)
static
Examples
ex_trajectory.c.

Definition at line 488 of file ex_trajectory.c.

References draw_3d_axes(), draw_arrow(), draw_full_path_3d(), draw_ground_grid(), draw_trail(), font, HEIGHT, NUM_WP3D, PANEL_W, project_3d(), time_3d, trail_3d, trail_3d_count, trail_3d_head, traj_3d, trajectory_compute(), waypoints_3d, and WIDTH.

Referenced by main().

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

◆ draw_arrow()

void draw_arrow ( float x1,
float y1,
float x2,
float y2,
ALLEGRO_COLOR color,
float thickness )
static
Examples
ex_trajectory.c.

Definition at line 148 of file ex_trajectory.c.

Referenced by draw_2d_panel(), draw_3d_axes(), and draw_3d_panel().

Here is the caller graph for this function:

◆ draw_full_path_2d()

void draw_full_path_2d ( void )
static
Examples
ex_trajectory.c.

Definition at line 250 of file ex_trajectory.c.

References traj_2d, and trajectory_get_position().

Referenced by draw_2d_panel().

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

◆ draw_full_path_3d()

void draw_full_path_3d ( void )
static
Examples
ex_trajectory.c.

Definition at line 464 of file ex_trajectory.c.

References project_3d(), traj_3d, and trajectory_get_position().

Referenced by draw_3d_panel().

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

◆ draw_ground_grid()

void draw_ground_grid ( void )
static
Examples
ex_trajectory.c.

Definition at line 451 of file ex_trajectory.c.

References project_3d().

Referenced by draw_3d_panel().

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

◆ draw_trail()

void draw_trail ( float trail[][2],
int count,
int head,
ALLEGRO_COLOR base_color )
static
Examples
ex_trajectory.c.

Definition at line 160 of file ex_trajectory.c.

References MAX_TRAIL.

Referenced by draw_2d_panel(), and draw_3d_panel().

Here is the caller graph for this function:

◆ handle_click_2d()

void handle_click_2d ( float mx,
float my )
static
Examples
ex_trajectory.c.

Definition at line 222 of file ex_trajectory.c.

References MAX_WP2D, PANEL_W, rebuild_2d_trajectory(), wp2d_count, WP2D_SPEED, wp2d_t, wp2d_x, and wp2d_y.

Referenced by main().

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

◆ init_3d()

void init_3d ( void )
static
Examples
ex_trajectory.c.

Definition at line 392 of file ex_trajectory.c.

References init_physics_3d(), NUM_WP3D, time_3d, time_3d_end, trail_3d_count, trail_3d_head, traj_3d, TRAJECTORY_3D, trajectory_add_point(), trajectory_new(), WAYPOINT3D::vx, WAYPOINT3D::vy, WAYPOINT3D::vz, waypoints_3d, WP3D_DUR, WAYPOINT3D::x, WAYPOINT3D::y, and WAYPOINT3D::z.

Referenced by main().

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

◆ init_physics_2d()

void init_physics_2d ( PHYSICS * p,
double px,
double py,
double vx,
double vy )
static
Examples
ex_trajectory.c.

Definition at line 109 of file ex_trajectory.c.

References PHYSICS::position, PHYSICS::speed, and VECTOR3D_SET.

Referenced by rebuild_2d_trajectory().

Here is the caller graph for this function:

◆ init_physics_3d()

void init_physics_3d ( PHYSICS * p,
double px,
double py,
double pz,
double vx,
double vy,
double vz )
static
Examples
ex_trajectory.c.

Definition at line 115 of file ex_trajectory.c.

References PHYSICS::position, PHYSICS::speed, and VECTOR3D_SET.

Referenced by init_3d().

Here is the caller graph for this function:

◆ main()

◆ project_3d()

void project_3d ( double x,
double y,
double z,
float * sx,
float * sy )
static
Examples
ex_trajectory.c.

Definition at line 137 of file ex_trajectory.c.

References HEIGHT, M_PI, and PANEL_W.

Referenced by draw_3d_axes(), draw_3d_panel(), draw_full_path_3d(), draw_ground_grid(), and update_3d_logic().

Here is the caller graph for this function:

◆ rebuild_2d_trajectory()

void rebuild_2d_trajectory ( void )
static
Examples
ex_trajectory.c.

Definition at line 180 of file ex_trajectory.c.

References init_physics_2d(), running_2d, traj_2d, trajectory_add_point(), trajectory_clear_points(), wp2d_count, wp2d_t, wp2d_x, and wp2d_y.

Referenced by handle_click_2d().

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

◆ reset_2d()

void reset_2d ( void )
static
Examples
ex_trajectory.c.

Definition at line 212 of file ex_trajectory.c.

References running_2d, time_2d, trail_2d_count, trail_2d_head, traj_2d, TRAJECTORY_2D, trajectory_delete(), trajectory_new(), and wp2d_count.

Referenced by main().

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

◆ trail_push_2d()

void trail_push_2d ( float x,
float y )
static
Examples
ex_trajectory.c.

Definition at line 121 of file ex_trajectory.c.

References MAX_TRAIL, trail_2d, trail_2d_count, and trail_2d_head.

Referenced by main().

Here is the caller graph for this function:

◆ trail_push_3d()

void trail_push_3d ( float x,
float y )
static
Examples
ex_trajectory.c.

Definition at line 128 of file ex_trajectory.c.

References MAX_TRAIL, trail_3d, trail_3d_count, and trail_3d_head.

Referenced by update_3d_logic().

Here is the caller graph for this function:

◆ update_3d_logic()

void update_3d_logic ( void )
static
Examples
ex_trajectory.c.

Definition at line 411 of file ex_trajectory.c.

References DT, project_3d(), time_3d, time_3d_end, trail_3d_count, trail_3d_head, trail_push_3d(), traj_3d, and trajectory_compute().

Referenced by main().

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

Variable Documentation

◆ running_2d

int running_2d = 0
static
Examples
ex_trajectory.c.

Definition at line 69 of file ex_trajectory.c.

Referenced by draw_2d_panel(), main(), rebuild_2d_trajectory(), and reset_2d().

◆ time_2d

double time_2d = 0.0
static
Examples
ex_trajectory.c.

Definition at line 68 of file ex_trajectory.c.

Referenced by draw_2d_panel(), main(), and reset_2d().

◆ time_3d

double time_3d = 0.0
static
Examples
ex_trajectory.c.

Definition at line 83 of file ex_trajectory.c.

Referenced by draw_3d_panel(), init_3d(), and update_3d_logic().

◆ time_3d_end

double time_3d_end = 0.0
static
Examples
ex_trajectory.c.

Definition at line 84 of file ex_trajectory.c.

Referenced by init_3d(), and update_3d_logic().

◆ trail_2d

float trail_2d[300][2]
static
Examples
ex_trajectory.c.

Definition at line 77 of file ex_trajectory.c.

Referenced by draw_2d_panel(), and trail_push_2d().

◆ trail_2d_count

int trail_2d_count = 0
static
Examples
ex_trajectory.c.

Definition at line 78 of file ex_trajectory.c.

Referenced by draw_2d_panel(), reset_2d(), and trail_push_2d().

◆ trail_2d_head

int trail_2d_head = 0
static
Examples
ex_trajectory.c.

Definition at line 79 of file ex_trajectory.c.

Referenced by draw_2d_panel(), reset_2d(), and trail_push_2d().

◆ trail_3d

float trail_3d[300][2]
static
Examples
ex_trajectory.c.

Definition at line 86 of file ex_trajectory.c.

Referenced by draw_3d_panel(), and trail_push_3d().

◆ trail_3d_count

int trail_3d_count = 0
static
Examples
ex_trajectory.c.

Definition at line 87 of file ex_trajectory.c.

Referenced by draw_3d_panel(), init_3d(), trail_push_3d(), and update_3d_logic().

◆ trail_3d_head

int trail_3d_head = 0
static
Examples
ex_trajectory.c.

Definition at line 88 of file ex_trajectory.c.

Referenced by draw_3d_panel(), init_3d(), trail_push_3d(), and update_3d_logic().

◆ traj_2d

TRAJECTORY* traj_2d = NULL
static

◆ traj_3d

TRAJECTORY* traj_3d = NULL
static
Examples
ex_trajectory.c.

Definition at line 82 of file ex_trajectory.c.

Referenced by draw_3d_panel(), draw_full_path_3d(), init_3d(), main(), and update_3d_logic().

◆ waypoints_3d

const WAYPOINT3D waypoints_3d[7]
static
Initial value:
= {
{0.0, 0.0, 0.0, 2.0, 1.0, 0.5},
{3.0, 2.0, 1.0, 1.0, 1.5, -0.5},
{4.0, 4.0, -1.0, -1.0, 1.0, -1.0},
{1.0, 5.0, -2.0, -2.0, 0.0, 0.5},
{-2.0, 3.0, 0.0, -1.0, -1.5, 1.0},
{-1.0, 1.0, 1.5, 1.0, -1.0, 0.0},
{0.0, 0.0, 0.0, 2.0, 1.0, 0.5},
}
Examples
ex_trajectory.c.

Definition at line 96 of file ex_trajectory.c.

Referenced by draw_3d_panel(), and init_3d().

◆ wp2d_count

int wp2d_count = 0
static
Examples
ex_trajectory.c.

Definition at line 74 of file ex_trajectory.c.

Referenced by draw_2d_panel(), handle_click_2d(), rebuild_2d_trajectory(), and reset_2d().

◆ WP2D_SPEED

const double WP2D_SPEED = 80.0
static
Examples
ex_trajectory.c.

Definition at line 75 of file ex_trajectory.c.

Referenced by handle_click_2d().

◆ wp2d_t

double wp2d_t[50]
static
Examples
ex_trajectory.c.

Definition at line 73 of file ex_trajectory.c.

Referenced by handle_click_2d(), and rebuild_2d_trajectory().

◆ wp2d_x

double wp2d_x[50]
static
Examples
ex_trajectory.c.

Definition at line 73 of file ex_trajectory.c.

Referenced by draw_2d_panel(), handle_click_2d(), and rebuild_2d_trajectory().

◆ wp2d_y

double wp2d_y[50]
static
Examples
ex_trajectory.c.

Definition at line 73 of file ex_trajectory.c.

Referenced by draw_2d_panel(), handle_click_2d(), and rebuild_2d_trajectory().

◆ WP3D_DUR

const double WP3D_DUR = 4.0
static
Examples
ex_trajectory.c.

Definition at line 105 of file ex_trajectory.c.

Referenced by init_3d().