![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Trajectory interpolation and dead reckoning for 2D/3D. More...
Include dependency graph for n_trajectory.c:Go to the source code of this file.
Functions | |
| static double | hermite_d2h00 (double s) |
| Second derivative of h00: d2h00/ds2 = 12s - 6. | |
| static double | hermite_d2h01 (double s) |
| Second derivative of h01: d2h01/ds2 = -12s + 6. | |
| static double | hermite_d2h10 (double s) |
| Second derivative of h10: d2h10/ds2 = 6s - 4. | |
| static double | hermite_d2h11 (double s) |
| Second derivative of h11: d2h11/ds2 = 6s - 2. | |
| static double | hermite_dh00 (double s) |
| First derivative of h00: dh00/ds = 6s^2 - 6s. | |
| static double | hermite_dh01 (double s) |
| First derivative of h01: dh01/ds = -6s^2 + 6s. | |
| static double | hermite_dh10 (double s) |
| First derivative of h10: dh10/ds = 3s^2 - 4s + 1. | |
| static double | hermite_dh11 (double s) |
| First derivative of h11: dh11/ds = 3s^2 - 2s. | |
| static double | hermite_h00 (double s) |
| Hermite basis function h00: weights the start position. | |
| static double | hermite_h01 (double s) |
| Hermite basis function h01: weights the end position. | |
| static double | hermite_h10 (double s) |
| Hermite basis function h10: weights the start tangent. | |
| static double | hermite_h11 (double s) |
| Hermite basis function h11: weights the end tangent. | |
| int | trajectory_add_point (TRAJECTORY *traj, const PHYSICS *state, double time_val) |
| Add a waypoint to the multi-point trajectory path. | |
| int | trajectory_clear_points (TRAJECTORY *traj) |
| Clear all waypoints from the multi-point path. | |
| int | trajectory_compute (TRAJECTORY *traj, double time_val) |
| Compute the full state (position, speed, acceleration, orientation, angular_speed) at a given time using cubic Hermite interpolation (within the interval) or quadratic extrapolation (outside the interval). | |
| static void | trajectory_compute_tangents (TRAJECTORY *traj) |
| Recompute the Hermite tangent vectors from current start/end states. | |
| void | trajectory_delete (TRAJECTORY **traj) |
| Free a TRAJECTORY and set the pointer to NULL. | |
| double | trajectory_distance (TRAJECTORY *traj, double time_a, double time_b, int steps) |
| Compute the approximate arc length (distance traveled) along the trajectory between two times, using numerical integration with the given number of steps. | |
| int | trajectory_get_acceleration (TRAJECTORY *traj, double time_val, VECTOR3D out) |
| Compute acceleration at a given time. | |
| int | trajectory_get_orientation (TRAJECTORY *traj, double time_val, VECTOR3D out) |
| Compute orientation at a given time. | |
| int | trajectory_get_position (TRAJECTORY *traj, double time_val, VECTOR3D out) |
| Compute position at a given time. | |
| int | trajectory_get_speed (TRAJECTORY *traj, double time_val, VECTOR3D out) |
| Compute velocity at a given time. | |
| static void | trajectory_load_segment (TRAJECTORY *traj, double time_val) |
| Load the correct spline segment for a given time when using multi-point paths. | |
| TRAJECTORY * | trajectory_new (int nb_components) |
| Allocate and initialize a new TRAJECTORY. | |
| int | trajectory_set_end (TRAJECTORY *traj, const PHYSICS *state, double time_val) |
| Set the terminal (end) state and time of the trajectory. | |
| int | trajectory_set_start (TRAJECTORY *traj, const PHYSICS *state, double time_val) |
| Set the initial (start) state and time of the trajectory. | |
| int | trajectory_update (TRAJECTORY *traj, const PHYSICS *new_end, double time_val) |
| Update the trajectory with a new end state (dead reckoning shift). | |
Trajectory interpolation and dead reckoning for 2D/3D.
Implements the "Defeating Lag With Cubic Splines" approach from GameDev.net Article 914 by Nicholas Van Caldwell, using cubic Hermite spline interpolation with quadratic extrapolation.
Cubic Hermite spline formula: P(s) = h00(s)*P0 + h10(s)*M0 + h01(s)*P1 + h11(s)*M1
Where s is normalized time in [0,1], P0/P1 are endpoint positions, M0/M1 are tangent vectors (velocity * duration), and: h00(s) = 2s^3 - 3s^2 + 1 (start position weight) h10(s) = s^3 - 2s^2 + s (start tangent weight) h01(s) = -2s^3 + 3s^2 (end position weight) h11(s) = s^3 - s^2 (end tangent weight)
Definition in file n_trajectory.c.
|
static |
Second derivative of h00: d2h00/ds2 = 12s - 6.
| s | normalized time in [0,1] |
Definition at line 122 of file n_trajectory.c.
Referenced by trajectory_compute(), and trajectory_get_acceleration().
Here is the caller graph for this function:
|
static |
Second derivative of h01: d2h01/ds2 = -12s + 6.
| s | normalized time in [0,1] |
Definition at line 140 of file n_trajectory.c.
Referenced by trajectory_compute(), and trajectory_get_acceleration().
Here is the caller graph for this function:
|
static |
Second derivative of h10: d2h10/ds2 = 6s - 4.
| s | normalized time in [0,1] |
Definition at line 131 of file n_trajectory.c.
Referenced by trajectory_compute(), and trajectory_get_acceleration().
Here is the caller graph for this function:
|
static |
Second derivative of h11: d2h11/ds2 = 6s - 2.
| s | normalized time in [0,1] |
Definition at line 149 of file n_trajectory.c.
Referenced by trajectory_compute(), and trajectory_get_acceleration().
Here is the caller graph for this function:
|
static |
First derivative of h00: dh00/ds = 6s^2 - 6s.
| s | normalized time in [0,1] |
Definition at line 86 of file n_trajectory.c.
Referenced by trajectory_compute(), and trajectory_get_speed().
Here is the caller graph for this function:
|
static |
First derivative of h01: dh01/ds = -6s^2 + 6s.
| s | normalized time in [0,1] |
Definition at line 104 of file n_trajectory.c.
Referenced by trajectory_compute(), and trajectory_get_speed().
Here is the caller graph for this function:
|
static |
First derivative of h10: dh10/ds = 3s^2 - 4s + 1.
| s | normalized time in [0,1] |
Definition at line 95 of file n_trajectory.c.
Referenced by trajectory_compute(), and trajectory_get_speed().
Here is the caller graph for this function:
|
static |
First derivative of h11: dh11/ds = 3s^2 - 2s.
| s | normalized time in [0,1] |
Definition at line 113 of file n_trajectory.c.
Referenced by trajectory_compute(), and trajectory_get_speed().
Here is the caller graph for this function:
|
static |
Hermite basis function h00: weights the start position.
| s | normalized time in [0,1] |
Definition at line 50 of file n_trajectory.c.
Referenced by trajectory_compute(), trajectory_get_orientation(), and trajectory_get_position().
Here is the caller graph for this function:
|
static |
Hermite basis function h01: weights the end position.
| s | normalized time in [0,1] |
Definition at line 68 of file n_trajectory.c.
Referenced by trajectory_compute(), trajectory_get_orientation(), and trajectory_get_position().
Here is the caller graph for this function:
|
static |
Hermite basis function h10: weights the start tangent.
| s | normalized time in [0,1] |
Definition at line 59 of file n_trajectory.c.
Referenced by trajectory_compute(), trajectory_get_orientation(), and trajectory_get_position().
Here is the caller graph for this function:
|
static |
Hermite basis function h11: weights the end tangent.
| s | normalized time in [0,1] |
Definition at line 77 of file n_trajectory.c.
Referenced by trajectory_compute(), trajectory_get_orientation(), and trajectory_get_position().
Here is the caller graph for this function:
|
static |
Recompute the Hermite tangent vectors from current start/end states.
Tangents are: m = velocity * duration (for position) and angular_speed * duration (for orientation)
| traj | The trajectory to update tangents for |
Definition at line 158 of file n_trajectory.c.
References PHYSICS::angular_speed, TRAJECTORY::duration, TRAJECTORY::end, TRAJECTORY::m0, TRAJECTORY::m0_orient, TRAJECTORY::m1, TRAJECTORY::m1_orient, TRAJECTORY::nb_components, PHYSICS::speed, and TRAJECTORY::start.
Referenced by trajectory_load_segment(), trajectory_set_end(), trajectory_set_start(), and trajectory_update().
Here is the caller graph for this function:
|
static |
Load the correct spline segment for a given time when using multi-point paths.
Searches forward/backward from current_segment for efficiency with sequential access. Updates traj->start, end, start_time, end_time, duration, and tangents for the found segment.
| traj | The trajectory (must have nb_points >= 2) |
| time_val | The time to find the segment for |
Definition at line 174 of file n_trajectory.c.
References TRAJECTORY::current_segment, TRAJECTORY::duration, TRAJECTORY::end, TRAJECTORY::end_time, TRAJECTORY::nb_points, TRAJECTORY::points, TRAJECTORY::start, TRAJECTORY::start_time, TRAJECTORY_POINT::state, TRAJECTORY_POINT::time_val, and trajectory_compute_tangents().
Referenced by trajectory_add_point(), trajectory_compute(), trajectory_get_acceleration(), trajectory_get_orientation(), trajectory_get_position(), and trajectory_get_speed().
Here is the call graph for this function:
Here is the caller graph for this function: