From 463cc7be4f5ef038d6a3bb86a5fe554ead656f33 Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Fri, 20 Oct 2006 16:34:55 +0000 Subject: [PATCH] added lateral distance monitoring --- direct/src/deadrec/smoothMover.I | 14 ++++++++++++++ direct/src/deadrec/smoothMover.cxx | 12 +++++++++++- direct/src/deadrec/smoothMover.h | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/direct/src/deadrec/smoothMover.I b/direct/src/deadrec/smoothMover.I index ef4f2aac21..8a0d412dc2 100644 --- a/direct/src/deadrec/smoothMover.I +++ b/direct/src/deadrec/smoothMover.I @@ -428,6 +428,20 @@ get_smooth_forward_velocity() const { return _smooth_forward_velocity; } +//////////////////////////////////////////////////////////////////// +// Function: SmoothMover::get_smooth_lateral_velocity +// Access: Published +// Description: Returns the speed at which the avatar is moving, in +// feet per second, along its own lateral axis (after +// applying the avatar's hpr). This will be a positive +// number if the avatar is moving right, and a +// negative number if it is moving left. +//////////////////////////////////////////////////////////////////// +INLINE float SmoothMover:: +get_smooth_lateral_velocity() const { + return _smooth_lateral_velocity; +} + //////////////////////////////////////////////////////////////////// // Function: SmoothMover::get_smooth_rotational_velocity // Access: Published diff --git a/direct/src/deadrec/smoothMover.cxx b/direct/src/deadrec/smoothMover.cxx index ee5612c49a..c1778ee098 100644 --- a/direct/src/deadrec/smoothMover.cxx +++ b/direct/src/deadrec/smoothMover.cxx @@ -50,6 +50,7 @@ SmoothMover() { _computed_forward_axis = true; _smooth_forward_velocity = 0.0; + _smooth_lateral_velocity = 0.0; _smooth_rotational_velocity = 0.0; _last_point_before = -1; @@ -184,6 +185,7 @@ clear_positions(bool reset_velocity) { if (reset_velocity) { _smooth_forward_velocity = 0.0; + _smooth_lateral_velocity = 0.0; _smooth_rotational_velocity = 0.0; } } @@ -214,6 +216,7 @@ compute_smooth_position(double timestamp) { double age = timestamp - _smooth_timestamp; if (age > _reset_velocity_age) { _smooth_forward_velocity = 0.0; + _smooth_lateral_velocity = 0.0; _smooth_rotational_velocity = 0.0; } } @@ -288,6 +291,7 @@ compute_smooth_position(double timestamp) { const SamplePoint &point = _points[point_after]; set_smooth_pos(point._pos, point._hpr, timestamp); _smooth_forward_velocity = 0.0; + _smooth_lateral_velocity = 0.0; _smooth_rotational_velocity = 0.0; _last_point_before = point_before; _last_point_after = point_after; @@ -342,6 +346,7 @@ compute_smooth_position(double timestamp) { // local timestamps, not on the other client's reported // timestamps. _smooth_forward_velocity = 0.0; + _smooth_lateral_velocity = 0.0; _smooth_rotational_velocity = 0.0; } @@ -425,6 +430,7 @@ get_latest_position() { const SamplePoint &point = _points.back(); set_smooth_pos(point._pos, point._hpr, point._timestamp); _smooth_forward_velocity = 0.0; + _smooth_lateral_velocity = 0.0; _smooth_rotational_velocity = 0.0; return true; } @@ -565,9 +571,13 @@ compute_velocity(const LVector3f &pos_delta, const LVecBase3f &hpr_delta, //cerr << " compute forward_axis = " << _forward_axis << "\n"; } + LVector3f lateral_axis = _forward_axis.cross(LVector3f(0.0,0.0,1.0)); + float forward_distance = pos_delta.dot(_forward_axis); - + float lateral_distance = pos_delta.dot(lateral_axis); + _smooth_forward_velocity = forward_distance / age; + _smooth_lateral_velocity = lateral_distance / age; _smooth_rotational_velocity = hpr_delta[0] / age; //cerr << " compute_velocity = " << _smooth_forward_velocity << "\n"; diff --git a/direct/src/deadrec/smoothMover.h b/direct/src/deadrec/smoothMover.h index 5fcc769ca4..c377a60c25 100644 --- a/direct/src/deadrec/smoothMover.h +++ b/direct/src/deadrec/smoothMover.h @@ -103,6 +103,7 @@ PUBLISHED: INLINE void compute_and_apply_smooth_mat(NodePath &node); INLINE float get_smooth_forward_velocity() const; + INLINE float get_smooth_lateral_velocity() const; INLINE float get_smooth_rotational_velocity() const; INLINE const LVecBase3f &get_forward_axis() const; @@ -181,6 +182,7 @@ private: bool _computed_forward_axis; double _smooth_forward_velocity; + double _smooth_lateral_velocity; double _smooth_rotational_velocity; typedef CircBuffer Points;