![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Data Structures | |
| struct | TRAJECTORY |
| structure holding all data for trajectory interpolation / extrapolation More... | |
| struct | TRAJECTORY_POINT |
| a single waypoint in a multi-point trajectory path More... | |
Macros | |
| #define | TRAJECTORY_2D 2 |
| use 2 components (x,y) for trajectory computation | |
| #define | TRAJECTORY_3D 3 |
| use 3 components (x,y,z) for trajectory computation | |
| #define | TRAJECTORY_BEFORE 3 |
| trajectory is extrapolating before the start state using quadratic motion | |
| #define | TRAJECTORY_EXTRAP 2 |
| trajectory is extrapolating beyond the end state using quadratic motion | |
| #define | TRAJECTORY_INTERP 1 |
| trajectory is interpolating along the cubic Hermite spline between start and end | |
Functions | |
| 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) | |
| int | trajectory_clear_points (TRAJECTORY *traj) |
| clear all waypoints from the multi-point path | |
| int | trajectory_compute (TRAJECTORY *traj, double time_val) |
| compute full state (position, speed, acceleration, orientation) at given time | |
| void | trajectory_delete (TRAJECTORY **traj) |
| free a trajectory | |
| double | trajectory_distance (TRAJECTORY *traj, double time_a, double time_b, int steps) |
| distance along the trajectory between two times | |
| int | trajectory_get_acceleration (TRAJECTORY *traj, double time_val, VECTOR3D out) |
| compute only acceleration at given time, stores result in out | |
| int | trajectory_get_orientation (TRAJECTORY *traj, double time_val, VECTOR3D out) |
| compute only orientation at given time, stores result in out | |
| int | trajectory_get_position (TRAJECTORY *traj, double time_val, VECTOR3D out) |
| compute only position at given time, stores result in out | |
| int | trajectory_get_speed (TRAJECTORY *traj, double time_val, VECTOR3D out) |
| compute only speed 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_end (TRAJECTORY *traj, const PHYSICS *state, double time_val) |
| set the terminal state and time of the trajectory, recomputes Hermite tangents | |
| int | trajectory_set_start (TRAJECTORY *traj, const PHYSICS *state, double time_val) |
| set the initial state and time of the trajectory | |
| 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) | |
| struct TRAJECTORY |
structure holding all data for trajectory interpolation / extrapolation
Definition at line 82 of file n_trajectory.h.
Collaboration diagram for TRAJECTORY:| Data Fields | ||
|---|---|---|
| PHYSICS | current | current computed state at current_time |
| int | current_segment | index of the currently loaded segment (points[i] -> points[i+1]), -1 if none |
| double | current_time | last computed time |
| double | duration | duration = end_time - start_time |
| PHYSICS | end | state at trajectory end (terminal known state) |
| double | end_time | timestamp of end state |
| VECTOR3D | m0 | Hermite tangent at start for position (start.speed * duration) |
| VECTOR3D | m0_orient | Hermite tangent at start for orientation (start.angular_speed * duration) |
| VECTOR3D | m1 | Hermite tangent at end for position (end.speed * duration) |
| VECTOR3D | m1_orient | Hermite tangent at end for orientation (end.angular_speed * duration) |
| int | mode | current computation mode: TRAJECTORY_INTERP, TRAJECTORY_EXTRAP, or TRAJECTORY_BEFORE |
| int | nb_components | number of components to process: TRAJECTORY_2D (2) or TRAJECTORY_3D (3) |
| int | nb_points | number of waypoints in the points array |
| int | nb_points_allocated | allocated capacity of the points array |
| TRAJECTORY_POINT * | points | array of waypoints for multi-point paths (NULL if single segment) |
| PHYSICS | start | state at trajectory start (initial known state) |
| double | start_time | timestamp of start state |
| struct TRAJECTORY_POINT |
a single waypoint in a multi-point trajectory path
Definition at line 74 of file n_trajectory.h.
Collaboration diagram for TRAJECTORY_POINT:| Data Fields | ||
|---|---|---|
| PHYSICS | state | physics state (position, speed, etc.) at this waypoint |
| double | time_val | timestamp of this waypoint |
| #define TRAJECTORY_2D 2 |
use 2 components (x,y) for trajectory computation
Definition at line 69 of file n_trajectory.h.
| #define TRAJECTORY_3D 3 |
use 3 components (x,y,z) for trajectory computation
Definition at line 71 of file n_trajectory.h.
| #define TRAJECTORY_BEFORE 3 |
trajectory is extrapolating before the start state using quadratic motion
Definition at line 66 of file n_trajectory.h.
| #define TRAJECTORY_EXTRAP 2 |
trajectory is extrapolating beyond the end state using quadratic motion
Definition at line 64 of file n_trajectory.h.
| #define TRAJECTORY_INTERP 1 |
trajectory is interpolating along the cubic Hermite spline between start and end
Definition at line 62 of file n_trajectory.h.
| 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)
add a waypoint to the multi-point path (times must be strictly increasing)
Waypoints must be added in strictly increasing chronological order. When 2+ waypoints exist, trajectory_compute and trajectory_get_* functions automatically find and interpolate the correct segment.
| traj | The trajectory |
| state | The physics state at this waypoint |
| time_val | The timestamp of this waypoint (must be > previous point's time) |
Definition at line 616 of file n_trajectory.c.
References __n_assert, current_segment, LOG_ERR, n_log, nb_points, nb_points_allocated, points, Realloc, TRAJECTORY_POINT::state, TRAJECTORY_POINT::time_val, and trajectory_load_segment().
Referenced by demo_dead_reckoning(), init_3d(), and rebuild_2d_trajectory().
Here is the call graph for this function:
Here is the caller graph for this function:| int trajectory_clear_points | ( | TRAJECTORY * | traj | ) |
clear all waypoints from the multi-point path
clear all waypoints from the multi-point path
Keeps the allocated memory for reuse. Resets start/end/duration.
| traj | The trajectory |
Definition at line 655 of file n_trajectory.c.
References __n_assert, current_segment, duration, end, end_time, nb_points, start, and start_time.
Referenced by rebuild_2d_trajectory().
Here is the caller graph for this function:| int trajectory_compute | ( | TRAJECTORY * | traj, |
| double | time_val | ||
| ) |
compute full state (position, speed, acceleration, orientation) at given time
compute full state (position, speed, acceleration, orientation) at given time
| traj | The trajectory |
| time_val | The time at which to compute the state |
Definition at line 329 of file n_trajectory.c.
References __n_assert, PHYSICS::acceleration, PHYSICS::angular_acceleration, PHYSICS::angular_speed, current, current_time, duration, end, end_time, hermite_d2h00(), hermite_d2h01(), hermite_d2h10(), hermite_d2h11(), hermite_dh00(), hermite_dh01(), hermite_dh10(), hermite_dh11(), hermite_h00(), hermite_h01(), hermite_h10(), hermite_h11(), m0, m0_orient, m1, m1_orient, mode, nb_components, PHYSICS::orientation, PHYSICS::position, PHYSICS::speed, start, start_time, TRAJECTORY_BEFORE, TRAJECTORY_EXTRAP, TRAJECTORY_INTERP, and trajectory_load_segment().
Referenced by draw_2d_panel(), draw_3d_panel(), main(), and update_3d_logic().
Here is the call graph for this function:
Here is the caller graph for this function:| void trajectory_delete | ( | TRAJECTORY ** | traj | ) |
free a trajectory
free a trajectory
| traj | Pointer to the TRAJECTORY pointer to free |
Definition at line 234 of file n_trajectory.c.
References __n_assert, and Free.
Referenced by demo_dead_reckoning(), main(), and reset_2d().
Here is the caller graph for this function:| double trajectory_distance | ( | TRAJECTORY * | traj, |
| double | time_a, | ||
| double | time_b, | ||
| int | steps | ||
| ) |
distance along the trajectory between two times
distance along the trajectory between two times
| traj | The trajectory |
| time_a | Start time |
| time_b | End time |
| steps | Number of integration steps (higher = more precise, 100 is usually enough) |
Definition at line 678 of file n_trajectory.c.
References __n_assert, nb_components, and trajectory_get_position().
Here is the call graph for this function:| int trajectory_get_acceleration | ( | TRAJECTORY * | traj, |
| double | time_val, | ||
| VECTOR3D | out | ||
| ) |
compute only acceleration at given time, stores result in out
compute only acceleration at given time, stores result in out
| traj | The trajectory |
| time_val | The time at which to compute |
| out | VECTOR3D to store the result |
Definition at line 526 of file n_trajectory.c.
References __n_assert, PHYSICS::acceleration, duration, end, end_time, hermite_d2h00(), hermite_d2h01(), hermite_d2h10(), hermite_d2h11(), m0, m1, nb_components, PHYSICS::position, start, start_time, and trajectory_load_segment().
Here is the call graph for this function:| int trajectory_get_orientation | ( | TRAJECTORY * | traj, |
| double | time_val, | ||
| VECTOR3D | out | ||
| ) |
compute only orientation at given time, stores result in out
compute only orientation at given time, stores result in out
| traj | The trajectory |
| time_val | The time at which to compute |
| out | VECTOR3D to store the result |
Definition at line 568 of file n_trajectory.c.
References __n_assert, PHYSICS::angular_acceleration, PHYSICS::angular_speed, duration, end, end_time, hermite_h00(), hermite_h01(), hermite_h10(), hermite_h11(), m0_orient, m1_orient, nb_components, PHYSICS::orientation, start, start_time, and trajectory_load_segment().
Here is the call graph for this function:| int trajectory_get_position | ( | TRAJECTORY * | traj, |
| double | time_val, | ||
| VECTOR3D | out | ||
| ) |
compute only position at given time, stores result in out
compute only position at given time, stores result in out
This is a lightweight version of trajectory_compute that only computes position.
| traj | The trajectory |
| time_val | The time at which to compute |
| out | VECTOR3D to store the result |
Definition at line 435 of file n_trajectory.c.
References __n_assert, PHYSICS::acceleration, duration, end, end_time, hermite_h00(), hermite_h01(), hermite_h10(), hermite_h11(), m0, m1, nb_components, PHYSICS::position, PHYSICS::speed, start, start_time, and trajectory_load_segment().
Referenced by demo_dead_reckoning(), draw_full_path_2d(), draw_full_path_3d(), and trajectory_distance().
Here is the call graph for this function:
Here is the caller graph for this function:| int trajectory_get_speed | ( | TRAJECTORY * | traj, |
| double | time_val, | ||
| VECTOR3D | out | ||
| ) |
compute only speed at given time, stores result in out
compute only speed at given time, stores result in out
| traj | The trajectory |
| time_val | The time at which to compute |
| out | VECTOR3D to store the result |
Definition at line 480 of file n_trajectory.c.
References __n_assert, PHYSICS::acceleration, duration, end, end_time, hermite_dh00(), hermite_dh01(), hermite_dh10(), hermite_dh11(), m0, m1, nb_components, PHYSICS::position, PHYSICS::speed, start, start_time, and trajectory_load_segment().
Referenced by demo_dead_reckoning().
Here is the call graph for this function:
Here is the caller graph for this function:| TRAJECTORY * trajectory_new | ( | int | nb_components | ) |
allocate a new trajectory for 2D or 3D use
allocate a new trajectory for 2D or 3D use
| nb_components | TRAJECTORY_2D (2) or TRAJECTORY_3D (3) |
Definition at line 206 of file n_trajectory.c.
References __n_assert, current_segment, current_time, duration, end_time, LOG_ERR, Malloc, mode, n_log, nb_components, nb_points, nb_points_allocated, points, start_time, TRAJECTORY_2D, TRAJECTORY_3D, and TRAJECTORY_BEFORE.
Referenced by demo_dead_reckoning(), init_3d(), and reset_2d().
Here is the caller graph for this function:| int trajectory_set_end | ( | TRAJECTORY * | traj, |
| const PHYSICS * | state, | ||
| double | time_val | ||
| ) |
set the terminal state and time of the trajectory, recomputes Hermite tangents
set the terminal state and time of the trajectory, recomputes Hermite tangents
Recomputes the Hermite tangent vectors.
| traj | The trajectory to configure |
| state | The physics state at the end point |
| time_val | The timestamp of this state (must be > start_time) |
Definition at line 270 of file n_trajectory.c.
References __n_assert, duration, end, end_time, LOG_ERR, n_log, start_time, and trajectory_compute_tangents().
Here is the call graph for this function:| int trajectory_set_start | ( | TRAJECTORY * | traj, |
| const PHYSICS * | state, | ||
| double | time_val | ||
| ) |
set the initial state and time of the trajectory
set the initial state and time of the trajectory
| traj | The trajectory to configure |
| state | The physics state at the start point |
| time_val | The timestamp of this state |
Definition at line 247 of file n_trajectory.c.
References __n_assert, duration, end_time, start, start_time, and trajectory_compute_tangents().
Here is the call graph for this function:| 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)
shift: old end becomes new start, set a new end state (for continuous dead reckoning updates)
The previous end state becomes the new start state, and the new state becomes the end. This is the core function for continuous dead reckoning: call it each time a new network update arrives to create a smooth spline from the current endpoint to the new one.
| traj | The trajectory to update |
| new_end | The new physics state received (e.g. from a network packet) |
| time_val | The timestamp of the new state |
Definition at line 298 of file n_trajectory.c.
References __n_assert, duration, end, end_time, LOG_ERR, n_log, start, start_time, and trajectory_compute_tangents().
Here is the call graph for this function: