From 11cc062e844228c7a59573b0a70468eed3f90520 Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Wed, 29 Oct 2008 18:21:07 +0000 Subject: [PATCH] smoother uses setPosHpr instead of setMat, no longer affects scale --- direct/src/deadrec/smoothMover.I | 167 ++++++------------ direct/src/deadrec/smoothMover.cxx | 37 ---- direct/src/deadrec/smoothMover.h | 23 +-- .../src/distributed/DistributedSmoothNode.py | 20 ++- 4 files changed, 77 insertions(+), 170 deletions(-) diff --git a/direct/src/deadrec/smoothMover.I b/direct/src/deadrec/smoothMover.I index c2d8373e72..8b4470471b 100644 --- a/direct/src/deadrec/smoothMover.I +++ b/direct/src/deadrec/smoothMover.I @@ -13,73 +13,6 @@ //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function: SmoothMover::set_scale -// Access: Published -// Description: Specifies the current scale that should be applied to -// the transform. This is not smoothed along with pos -// and hpr, but rather takes effect immediately; it is -// only here at all so we can return a complete matrix -// in get_smooth_mat(). -//////////////////////////////////////////////////////////////////// -INLINE bool SmoothMover:: -set_scale(const LVecBase3f &scale) { - return set_sx(scale[0]) | set_sy(scale[1]) | set_sz(scale[2]); -} - -//////////////////////////////////////////////////////////////////// -// Function: SmoothMover::set_scale -// Access: Published -// Description: Specifies the current scale that should be applied to -// the transform. This is not smoothed along with pos -// and hpr, but rather takes effect immediately; it is -// only here at all so we can return a complete matrix -// in get_smooth_mat(). -//////////////////////////////////////////////////////////////////// -INLINE bool SmoothMover:: -set_scale(float sx, float sy, float sz) { - return set_sx(sx) | set_sy(sy) | set_sz(sz); -} - -//////////////////////////////////////////////////////////////////// -// Function: SmoothMover::set_sx -// Access: Published -// Description: Sets the X-axis scale only. See set_scale(). -//////////////////////////////////////////////////////////////////// -INLINE bool SmoothMover:: -set_sx(float sx) { - bool result = (sx != _scale[0]); - _scale[0] = sx; - _computed_smooth_mat = _computed_smooth_mat && !result; - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: SmoothMover::set_sy -// Access: Published -// Description: Sets the Y-axis scale only. See set_scale(). -//////////////////////////////////////////////////////////////////// -INLINE bool SmoothMover:: -set_sy(float sy) { - bool result = (sy != _scale[1]); - _scale[1] = sy; - _computed_smooth_mat = _computed_smooth_mat && !result; - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: SmoothMover::set_sz -// Access: Published -// Description: Sets the Z-axis scale only. See set_scale(). -//////////////////////////////////////////////////////////////////// -INLINE bool SmoothMover:: -set_sz(float sz) { - bool result = (sz != _scale[2]); - _scale[2] = sz; - _computed_smooth_mat = _computed_smooth_mat && !result; - return result; -} - //////////////////////////////////////////////////////////////////// // Function: SmoothMover::set_pos // Access: Published @@ -262,6 +195,47 @@ set_r(float r) { return result; } +//////////////////////////////////////////////////////////////////// +// Function: SmoothMover::set_pos_hpr +// Access: Published +// Description: Specifies the position and orientation of the SmoothMover at a +// particular time in the past. When mark_position() is +// called, this will be recorded (along with +// timestamp) in a position report, which will then be +// used along with all other position reports to +// determine the smooth position at any particular +// instant. +// +// The return value is true if any parameter has changed +// since the last call to set_pos_hpr(), or false if they +// are the same. +//////////////////////////////////////////////////////////////////// +INLINE bool SmoothMover:: +set_pos_hpr(const LVecBase3f &pos, const LVecBase3f &hpr) { + return (set_x(pos[0]) | set_y(pos[1]) | set_z(pos[2]) | + set_h(hpr[0]) | set_p(hpr[1]) | set_r(hpr[2])); +} + +//////////////////////////////////////////////////////////////////// +// Function: SmoothMover::set_pos_hpr +// Access: Published +// Description: Specifies the position of the SmoothMover at a +// particular time in the past. When mark_position() is +// called, this will be recorded (along with +// timestamp) in a position report, which will then be +// used along with all other position reports to +// determine the smooth position at any particular +// instant. +// +// The return value is true if any parameter has changed +// since the last call to set_pos_hpr(), or false if they +// are the same. +//////////////////////////////////////////////////////////////////// +INLINE bool SmoothMover:: +set_pos_hpr(float x, float y, float z, float h, float p, float r) { + return set_x(x) | set_y(y) | set_z(z) | set_h(h) | set_p(p) | set_r(r); +} + //////////////////////////////////////////////////////////////////// // Function: SmoothMover::get_sample_pos // Access: Published @@ -412,6 +386,22 @@ apply_smooth_pos(NodePath &node) const { node.set_pos(get_smooth_pos()); } +//////////////////////////////////////////////////////////////////// +// Function: SmoothMover::apply_smooth_pos_hpr +// Access: Published +// Description: Applies the smoothed position and orientation to the +// indicated NodePath. This is equivalent to calling +// node.set_pos_hpr(smooth_mover->get_smooth_pos(), +// smooth_mover->get_smooth_hpr()). It exists as an +// optimization only, to avoid the overhead of passing +// the return value through Python. +//////////////////////////////////////////////////////////////////// +INLINE void SmoothMover:: +apply_smooth_pos_hpr(NodePath &pos_node, NodePath &hpr_node) const { + pos_node.set_pos(get_smooth_pos()); + hpr_node.set_hpr(get_smooth_hpr()); +} + //////////////////////////////////////////////////////////////////// // Function: SmoothMover::apply_smooth_hpr // Access: Published @@ -426,20 +416,6 @@ apply_smooth_hpr(NodePath &node) const { node.set_hpr(get_smooth_hpr()); } -//////////////////////////////////////////////////////////////////// -// Function: SmoothMover::apply_smooth_mat -// Access: Published -// Description: Applies the smoothed transform to the indicated -// NodePath. This is equivalent to calling -// node.set_mat(smooth_mover->get_smooth_mat()). It -// exists as an optimization only, to avoid the overhead -// of passing the return value through Python. -//////////////////////////////////////////////////////////////////// -INLINE void SmoothMover:: -apply_smooth_mat(NodePath &node) { - node.set_mat(get_smooth_mat()); -} - //////////////////////////////////////////////////////////////////// // Function: SmoothMover::compute_and_apply_smooth_pos // Access: Published @@ -485,35 +461,6 @@ compute_and_apply_smooth_hpr(NodePath &hpr_node) { } } -//////////////////////////////////////////////////////////////////// -// Function: SmoothMover::compute_and_apply_smooth_mat -// Access: Published -// Description: A further optimization to reduce Python calls. This -// computes the smooth position and applies it to the -// indicated node in one call. -//////////////////////////////////////////////////////////////////// -INLINE void SmoothMover:: -compute_and_apply_smooth_mat(NodePath &node) { - if (compute_smooth_position()) { - apply_smooth_mat(node); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: SmoothMover::get_smooth_mat -// Access: Published -// Description: Returns the complete smoothed transformation matrix -// as computed by a previous call to -// compute_smooth_position(). -//////////////////////////////////////////////////////////////////// -INLINE const LMatrix4f &SmoothMover:: -get_smooth_mat() { - if (!_computed_smooth_mat) { - compose_smooth_mat(); - } - return _smooth_mat; -} - //////////////////////////////////////////////////////////////////// // Function: SmoothMover::get_smooth_forward_velocity // Access: Published diff --git a/direct/src/deadrec/smoothMover.cxx b/direct/src/deadrec/smoothMover.cxx index ed43a7c9ce..ee6e8ec95b 100644 --- a/direct/src/deadrec/smoothMover.cxx +++ b/direct/src/deadrec/smoothMover.cxx @@ -14,7 +14,6 @@ #include "smoothMover.h" #include "pnotify.h" -#include "compose_matrix.h" #include "config_deadrec.h" //////////////////////////////////////////////////////////////////// @@ -24,19 +23,16 @@ //////////////////////////////////////////////////////////////////// SmoothMover:: SmoothMover() { - _scale.set(1.0, 1.0, 1.0); _sample._pos.set(0.0, 0.0, 0.0); _sample._hpr.set(0.0, 0.0, 0.0); _sample._timestamp = 0.0; _smooth_pos.set(0.0, 0.0, 0.0); _smooth_hpr.set(0.0, 0.0, 0.0); - _smooth_mat = LMatrix4f::ident_mat(); _forward_axis.set(0.0, 1.0, 0.0); _smooth_timestamp = 0.0; _smooth_position_known = false; _smooth_position_changed = true; - _computed_smooth_mat = true; _computed_forward_axis = true; _smooth_forward_velocity = 0.0; @@ -75,23 +71,6 @@ SmoothMover:: ~SmoothMover() { } -//////////////////////////////////////////////////////////////////// -// Function: SmoothMover::set_mat -// Access: Published -// Description: Specifies the scale, hpr, and pos for the SmoothMover -// at some particular point, based on the matrix. -//////////////////////////////////////////////////////////////////// -bool SmoothMover:: -set_mat(const LMatrix4f &mat) { - bool result = false; - - LVecBase3f scale, hpr, pos; - if (decompose_matrix(mat, scale, hpr, pos)) { - result = set_scale(scale) | set_hpr(hpr) | set_pos(pos); - } - return result; -} - //////////////////////////////////////////////////////////////////// // Function: SmoothMover::mark_position // Access: Published @@ -615,12 +594,10 @@ set_smooth_pos(const LPoint3f &pos, const LVecBase3f &hpr, if (_smooth_pos != pos) { _smooth_pos = pos; _smooth_position_changed = true; - _computed_smooth_mat = false; } if (_smooth_hpr != hpr) { _smooth_hpr = hpr; _smooth_position_changed = true; - _computed_smooth_mat = false; _computed_forward_axis = false; } @@ -628,18 +605,6 @@ set_smooth_pos(const LPoint3f &pos, const LVecBase3f &hpr, _smooth_position_known = true; } -//////////////////////////////////////////////////////////////////// -// Function: SmoothMover::compose_smooth_mat -// Access: Private -// Description: Computes the smooth_mat based on smooth_pos and -// smooth_hpr. -//////////////////////////////////////////////////////////////////// -void SmoothMover:: -compose_smooth_mat() { - compose_matrix(_smooth_mat, _scale, _smooth_hpr, _smooth_pos); - _computed_smooth_mat = true; -} - //////////////////////////////////////////////////////////////////// // Function: SmoothMover::linear_interpolate // Access: Private @@ -810,8 +775,6 @@ handle_wrt_reparent(NodePath &old_parent, NodePath &new_parent) { _smooth_pos = np.get_pos(new_parent); _smooth_hpr = np.get_hpr(new_parent); - compose_smooth_mat(); - _computed_forward_axis = false; np.detach_node(); diff --git a/direct/src/deadrec/smoothMover.h b/direct/src/deadrec/smoothMover.h index 055fec9af7..b519e1eb92 100644 --- a/direct/src/deadrec/smoothMover.h +++ b/direct/src/deadrec/smoothMover.h @@ -49,15 +49,6 @@ PUBLISHED: SmoothMover(); ~SmoothMover(); - // This method is just used to specify a scale which is only used - // when composing the matrix for return by get_smooth_mat(). It - // might change from time to time, but it is not smoothed. - INLINE bool set_scale(const LVecBase3f &scale); - INLINE bool set_scale(float sx, float sy, float sz); - INLINE bool set_sx(float sx); - INLINE bool set_sy(float sy); - INLINE bool set_sz(float sz); - // These methods are used to specify each position update. Call the // appropriate set_* function(s), as needed, and then call // mark_position(). The return value of each function is true if @@ -75,11 +66,12 @@ PUBLISHED: INLINE bool set_p(float p); INLINE bool set_r(float r); + INLINE bool set_pos_hpr(const LVecBase3f &pos, const LVecBase3f &hpr); + INLINE bool set_pos_hpr(float x, float y, float z, float h, float p, float r); + INLINE const LPoint3f &get_sample_pos() const; INLINE const LVecBase3f &get_sample_hpr() const; - bool set_mat(const LMatrix4f &mat); - INLINE void set_phony_timestamp(); INLINE void set_timestamp(double timestamp); @@ -95,16 +87,14 @@ PUBLISHED: INLINE const LPoint3f &get_smooth_pos() const; INLINE const LVecBase3f &get_smooth_hpr() const; - INLINE const LMatrix4f &get_smooth_mat(); INLINE void apply_smooth_pos(NodePath &node) const; + INLINE void apply_smooth_pos_hpr(NodePath &pos_node, NodePath &hpr_node) const; INLINE void apply_smooth_hpr(NodePath &node) const; - INLINE void apply_smooth_mat(NodePath &node); INLINE void compute_and_apply_smooth_pos(NodePath &node); INLINE void compute_and_apply_smooth_pos_hpr(NodePath &pos_node, NodePath &hpr_node); INLINE void compute_and_apply_smooth_hpr(NodePath &hpr_node); - INLINE void compute_and_apply_smooth_mat(NodePath &node); INLINE float get_smooth_forward_velocity() const; INLINE float get_smooth_lateral_velocity() const; @@ -160,7 +150,6 @@ PUBLISHED: private: void set_smooth_pos(const LPoint3f &pos, const LVecBase3f &hpr, double timestamp); - void compose_smooth_mat(); void linear_interpolate(int point_before, int point_after, double timestamp); void compute_velocity(const LVector3f &pos_delta, const LVecBase3f &hpr_delta, @@ -169,8 +158,6 @@ private: void record_timestamp_delay(double timestamp); INLINE double get_avg_timestamp_delay() const; - LVecBase3f _scale; - public: // This internal class is declared public to work around compiler // issues. @@ -186,12 +173,10 @@ private: LPoint3f _smooth_pos; LVecBase3f _smooth_hpr; - LMatrix4f _smooth_mat; LVector3f _forward_axis; double _smooth_timestamp; bool _smooth_position_known; bool _smooth_position_changed; - bool _computed_smooth_mat; bool _computed_forward_axis; double _smooth_forward_velocity; diff --git a/direct/src/distributed/DistributedSmoothNode.py b/direct/src/distributed/DistributedSmoothNode.py index 28ca7109fd..3ef40baef6 100644 --- a/direct/src/distributed/DistributedSmoothNode.py +++ b/direct/src/distributed/DistributedSmoothNode.py @@ -112,7 +112,10 @@ class DistributedSmoothNode(DistributedNode.DistributedNode, smoothed position. This may be overridden by a derived class to specialize the behavior. """ - self.smoother.computeAndApplySmoothMat(self) + if hasattr(self.smoother, 'computeAndApplySmoothPosHpr'): + self.smoother.computeAndApplySmoothPosHpr(self, self) + else: + self.smoother.computeAndApplySmoothMat(self) def doSmoothTask(self, task): self.smoothPosition() @@ -164,7 +167,10 @@ class DistributedSmoothNode(DistributedNode.DistributedNode, #printStack() if (not self.isLocal()) and \ self.smoother.getLatestPosition(): - self.smoother.applySmoothMat(self) + if hasattr(self.smoother, 'applySmoothPosHpr'): + self.smoother.applySmoothPosHpr(self, self) + else: + self.smoother.applySmoothMat(self) self.smoother.clearPositions(1) def reloadPosition(self): @@ -175,7 +181,10 @@ class DistributedSmoothNode(DistributedNode.DistributedNode, it to stick. """ self.smoother.clearPositions(0) - self.smoother.setMat(self.getMat()) + if hasattr(self.smoother, 'setPosHpr'): + self.smoother.setPosHpr(self.getPos(), self.getHpr()) + else: + self.smoother.setMat(self.getMat()) self.smoother.setPhonyTimestamp() self.smoother.markPosition() @@ -358,7 +367,10 @@ class DistributedSmoothNode(DistributedNode.DistributedNode, if not self.localControl and not self.smoothStarted and \ self.smoother.getLatestPosition(): - self.smoother.applySmoothMat(self) + if hasattr(self.smoother, 'applySmoothPosHpr'): + self.smoother.applySmoothPosHpr(self, self) + else: + self.smoother.applyMat(self) @report(types = ['args'], dConfigParam = 'want-smoothnode-report') def clearSmoothing(self, bogus = None):