Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_trajectory.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
47#ifndef _N_TRAJECTORY_HEADER
48#define _N_TRAJECTORY_HEADER
49
50#ifdef __cplusplus
51extern "C" {
52#endif
53
59#include "n_3d.h"
60
62#define TRAJECTORY_INTERP 1
64#define TRAJECTORY_EXTRAP 2
66#define TRAJECTORY_BEFORE 3
67
69#define TRAJECTORY_2D 2
71#define TRAJECTORY_3D 3
72
80
122
124TRAJECTORY* trajectory_new(int nb_components);
126void trajectory_delete(TRAJECTORY** traj);
127
129int trajectory_set_start(TRAJECTORY* traj, const PHYSICS* state, double time_val);
131int trajectory_set_end(TRAJECTORY* traj, const PHYSICS* state, double time_val);
133int trajectory_update(TRAJECTORY* traj, const PHYSICS* new_end, double time_val);
134
136int trajectory_compute(TRAJECTORY* traj, double time_val);
138int trajectory_get_position(TRAJECTORY* traj, double time_val, VECTOR3D out);
140int trajectory_get_speed(TRAJECTORY* traj, double time_val, VECTOR3D out);
142int trajectory_get_acceleration(TRAJECTORY* traj, double time_val, VECTOR3D out);
144int trajectory_get_orientation(TRAJECTORY* traj, double time_val, VECTOR3D out);
145
147int trajectory_add_point(TRAJECTORY* traj, const PHYSICS* state, double time_val);
150
152double trajectory_distance(TRAJECTORY* traj, double time_a, double time_b, int steps);
153
158#ifdef __cplusplus
159}
160#endif
161
162#endif // header guard
double VECTOR3D[3]
struct of a point
Definition n_3d.h:58
structure of the physics of an object
Definition n_3d.h:69
VECTOR3D m0_orient
Hermite tangent at start for orientation (start.angular_speed * duration)
PHYSICS current
current computed state at current_time
VECTOR3D m0
Hermite tangent at start for position (start.speed * duration)
VECTOR3D m1_orient
Hermite tangent at end for orientation (end.angular_speed * duration)
int nb_points_allocated
allocated capacity of the points array
int nb_points
number of waypoints in the points array
double current_time
last computed time
PHYSICS end
state at trajectory end (terminal known state)
double time_val
timestamp of this waypoint
double duration
duration = end_time - start_time
TRAJECTORY_POINT * points
array of waypoints for multi-point paths (NULL if single segment)
int current_segment
index of the currently loaded segment (points[i] -> points[i+1]), -1 if none
PHYSICS state
physics state (position, speed, etc.) at this waypoint
int mode
current computation mode: TRAJECTORY_INTERP, TRAJECTORY_EXTRAP, or TRAJECTORY_BEFORE
VECTOR3D m1
Hermite tangent at end for position (end.speed * duration)
PHYSICS start
state at trajectory start (initial known state)
int nb_components
number of components to process: TRAJECTORY_2D (2) or TRAJECTORY_3D (3)
double start_time
timestamp of start state
double end_time
timestamp of end state
int trajectory_get_position(TRAJECTORY *traj, double time_val, VECTOR3D out)
compute only position at given time, stores result in out
TRAJECTORY * trajectory_new(int nb_components)
allocate a new trajectory for 2D or 3D use
int trajectory_set_start(TRAJECTORY *traj, const PHYSICS *state, double time_val)
set the initial state and time of the trajectory
int trajectory_add_point(TRAJECTORY *traj, const PHYSICS *state, double time_val)
add a waypoint to the multi-point path (times must be strictly increasing)
void trajectory_delete(TRAJECTORY **traj)
free a trajectory
int trajectory_get_orientation(TRAJECTORY *traj, double time_val, VECTOR3D out)
compute only orientation at given time, stores result in out
int trajectory_get_acceleration(TRAJECTORY *traj, double time_val, VECTOR3D out)
compute only acceleration at given time, stores result in out
int trajectory_compute(TRAJECTORY *traj, double time_val)
compute full state (position, speed, acceleration, orientation) at given time
int trajectory_set_end(TRAJECTORY *traj, const PHYSICS *state, double time_val)
set the terminal state and time of the trajectory, recomputes Hermite tangents
int trajectory_get_speed(TRAJECTORY *traj, double time_val, VECTOR3D out)
compute only speed at given time, stores result in out
int trajectory_clear_points(TRAJECTORY *traj)
clear all waypoints from the multi-point path
int trajectory_update(TRAJECTORY *traj, const PHYSICS *new_end, double time_val)
shift: old end becomes new start, set a new end state (for continuous dead reckoning updates)
double trajectory_distance(TRAJECTORY *traj, double time_a, double time_b, int steps)
distance along the trajectory between two times
structure holding all data for trajectory interpolation / extrapolation
a single waypoint in a multi-point trajectory path
Simple 3D movement simulation.