diff --git a/panda/src/chan/animChannelMatrixFixed.cxx b/panda/src/chan/animChannelMatrixFixed.cxx index 85b8a54968..e6be1aaf99 100644 --- a/panda/src/chan/animChannelMatrixFixed.cxx +++ b/panda/src/chan/animChannelMatrixFixed.cxx @@ -28,7 +28,9 @@ TypeHandle AnimChannelMatrixFixed::_type_handle; AnimChannelMatrixFixed:: AnimChannelMatrixFixed(AnimGroup *parent, const AnimChannelMatrixFixed ©) : AnimChannel(parent, copy), - _transform(copy._transform) + _pos(copy._pos), + _hpr(copy._hpr), + _scale(copy._scale) { } @@ -38,9 +40,9 @@ AnimChannelMatrixFixed(AnimGroup *parent, const AnimChannelMatrixFixed ©) : // Description: //////////////////////////////////////////////////////////////////// AnimChannelMatrixFixed:: -AnimChannelMatrixFixed(const string &name, const TransformState *transform) : +AnimChannelMatrixFixed(const string &name, const LVecBase3f &pos, const LVecBase3f &hpr, const LVecBase3f &scale) : AnimChannel(name), - _transform(transform) + _pos(pos), _hpr(hpr), _scale(scale) { } @@ -62,7 +64,7 @@ has_changed(int, double, int, double) { //////////////////////////////////////////////////////////////////// void AnimChannelMatrixFixed:: get_value(int, LMatrix4f &value) { - value = _transform->get_mat(); + compose_matrix(value, _scale, LVecBase3f::zero(), _hpr, _pos); } //////////////////////////////////////////////////////////////////// @@ -72,13 +74,9 @@ get_value(int, LMatrix4f &value) { // without any scale or shear information. //////////////////////////////////////////////////////////////////// void AnimChannelMatrixFixed:: -get_value_no_scale_shear(int frame, LMatrix4f &mat) { - if (_transform->has_scale() || _transform->has_shear()) { - compose_matrix(mat, LVecBase3f(1.0f, 1.0f, 1.0f), - _transform->get_hpr(), _transform->get_pos()); - } else { - mat = _transform->get_mat(); - } +get_value_no_scale_shear(int, LMatrix4f &mat) { + compose_matrix(mat, LVecBase3f(1.0f, 1.0f, 1.0f), LVecBase3f::zero(), + _hpr, _pos); } //////////////////////////////////////////////////////////////////// @@ -88,7 +86,7 @@ get_value_no_scale_shear(int frame, LMatrix4f &mat) { //////////////////////////////////////////////////////////////////// void AnimChannelMatrixFixed:: get_scale(int, LVecBase3f &scale) { - scale = _transform->get_scale(); + scale = _scale; } //////////////////////////////////////////////////////////////////// @@ -100,7 +98,7 @@ get_scale(int, LVecBase3f &scale) { //////////////////////////////////////////////////////////////////// void AnimChannelMatrixFixed:: get_hpr(int, LVecBase3f &hpr) { - hpr = _transform->get_hpr(); + hpr = _hpr; } //////////////////////////////////////////////////////////////////// @@ -112,7 +110,7 @@ get_hpr(int, LVecBase3f &hpr) { //////////////////////////////////////////////////////////////////// void AnimChannelMatrixFixed:: get_quat(int, LQuaternionf &quat) { - quat = _transform->get_quat(); + quat.set_hpr(_hpr); } //////////////////////////////////////////////////////////////////// @@ -124,7 +122,7 @@ get_quat(int, LQuaternionf &quat) { //////////////////////////////////////////////////////////////////// void AnimChannelMatrixFixed:: get_pos(int, LVecBase3f &pos) { - pos = _transform->get_pos(); + pos = _pos; } //////////////////////////////////////////////////////////////////// @@ -136,7 +134,7 @@ get_pos(int, LVecBase3f &pos) { //////////////////////////////////////////////////////////////////// void AnimChannelMatrixFixed:: get_shear(int, LVecBase3f &shear) { - shear = _transform->get_shear(); + shear = LVecBase3f::zero(); } //////////////////////////////////////////////////////////////////// @@ -147,5 +145,5 @@ get_shear(int, LVecBase3f &shear) { void AnimChannelMatrixFixed:: output(ostream &out) const { AnimChannel::output(out); - out << " = " << *_transform; + out << ": pos " << _pos << " hpr " << _hpr << " scale " << _scale; } diff --git a/panda/src/chan/animChannelMatrixFixed.h b/panda/src/chan/animChannelMatrixFixed.h index 8db4308e0b..1b6d3835d2 100644 --- a/panda/src/chan/animChannelMatrixFixed.h +++ b/panda/src/chan/animChannelMatrixFixed.h @@ -32,7 +32,7 @@ protected: AnimChannelMatrixFixed(AnimGroup *parent, const AnimChannelMatrixFixed ©); public: - AnimChannelMatrixFixed(const string &name, const TransformState *transform); + AnimChannelMatrixFixed(const string &name, const LVecBase3f &pos, const LVecBase3f &hpr, const LVecBase3f &scale); virtual bool has_changed(int last_frame, double last_frac, int this_frame, double this_frac); @@ -47,7 +47,7 @@ public: virtual void output(ostream &out) const; private: - CPT(TransformState) _transform; + LVecBase3f _pos, _hpr, _scale; public: virtual TypeHandle get_type() const { diff --git a/panda/src/chan/movingPartMatrix.cxx b/panda/src/chan/movingPartMatrix.cxx index 74c0730811..238b4b9904 100644 --- a/panda/src/chan/movingPartMatrix.cxx +++ b/panda/src/chan/movingPartMatrix.cxx @@ -48,7 +48,9 @@ MovingPartMatrix:: //////////////////////////////////////////////////////////////////// AnimChannelBase *MovingPartMatrix:: make_initial_channel() const { - return new AnimChannelMatrixFixed(get_name(), TransformState::make_mat(_initial_value)); + LVecBase3f pos, hpr, scale, shear; + decompose_matrix(_initial_value, pos, hpr, scale, shear); + return new AnimChannelMatrixFixed(get_name(), pos, hpr, scale); } //////////////////////////////////////////////////////////////////// @@ -373,7 +375,7 @@ get_blend_value(const PartBundle *root) { } //////////////////////////////////////////////////////////////////// -// Function: MovingPartMatrix::apply_freeze +// Function: MovingPartMatrix::apply_freeze_matrix // Access: Public, Virtual // Description: Freezes this particular joint so that it will always // hold the specified transform. Returns true if this @@ -382,8 +384,8 @@ get_blend_value(const PartBundle *root) { // PartBundle::freeze_joint(). //////////////////////////////////////////////////////////////////// bool MovingPartMatrix:: -apply_freeze(const TransformState *transform) { - _forced_channel = new AnimChannelMatrixFixed(get_name(), transform); +apply_freeze_matrix(const LVecBase3f &pos, const LVecBase3f &hpr, const LVecBase3f &scale) { + _forced_channel = new AnimChannelMatrixFixed(get_name(), pos, hpr, scale); return true; } diff --git a/panda/src/chan/movingPartMatrix.h b/panda/src/chan/movingPartMatrix.h index 5e7bc2e591..3f2971a70b 100644 --- a/panda/src/chan/movingPartMatrix.h +++ b/panda/src/chan/movingPartMatrix.h @@ -42,7 +42,7 @@ public: virtual AnimChannelBase *make_initial_channel() const; virtual void get_blend_value(const PartBundle *root); - virtual bool apply_freeze(const TransformState *transform); + virtual bool apply_freeze_matrix(const LVecBase3f &pos, const LVecBase3f &hpr, const LVecBase3f &scale); virtual bool apply_control(PandaNode *node); protected: diff --git a/panda/src/chan/movingPartScalar.cxx b/panda/src/chan/movingPartScalar.cxx index 65afd7e716..f5f7785620 100644 --- a/panda/src/chan/movingPartScalar.cxx +++ b/panda/src/chan/movingPartScalar.cxx @@ -115,7 +115,7 @@ get_blend_value(const PartBundle *root) { } //////////////////////////////////////////////////////////////////// -// Function: MovingPartScalar::apply_freeze +// Function: MovingPartScalar::apply_freeze_scalar // Access: Public, Virtual // Description: Freezes this particular joint so that it will always // hold the specified transform. Returns true if this @@ -124,8 +124,8 @@ get_blend_value(const PartBundle *root) { // PartBundle::freeze_joint(). //////////////////////////////////////////////////////////////////// bool MovingPartScalar:: -apply_freeze(const TransformState *transform) { - _forced_channel = new AnimChannelFixed(get_name(), transform->get_pos()[0]); +apply_freeze_scalar(float value) { + _forced_channel = new AnimChannelFixed(get_name(), value); return true; } diff --git a/panda/src/chan/movingPartScalar.h b/panda/src/chan/movingPartScalar.h index 348f703661..19673ae16c 100644 --- a/panda/src/chan/movingPartScalar.h +++ b/panda/src/chan/movingPartScalar.h @@ -39,7 +39,7 @@ public: virtual void get_blend_value(const PartBundle *root); - virtual bool apply_freeze(const TransformState *transform); + virtual bool apply_freeze_scalar(float value); virtual bool apply_control(PandaNode *node); protected: diff --git a/panda/src/chan/partBundle.cxx b/panda/src/chan/partBundle.cxx index 41b9ee25d3..65d36e8238 100644 --- a/panda/src/chan/partBundle.cxx +++ b/panda/src/chan/partBundle.cxx @@ -421,6 +421,58 @@ freeze_joint(const string &joint_name, const TransformState *transform) { return child->apply_freeze(transform); } +//////////////////////////////////////////////////////////////////// +// Function: PartBundle::freeze_joint +// Access: Published +// Description: Specifies that the joint with the indicated name +// should be frozen with the specified transform. It +// will henceforth always hold this fixed transform, +// regardless of any animations that may subsequently be +// bound to the joint. +// +// Returns true if the joint is successfully frozen, or +// false if the named child is not a joint (or slider) +// or does not exist. +//////////////////////////////////////////////////////////////////// +bool PartBundle:: +freeze_joint(const string &joint_name, const LVecBase3f &pos, const LVecBase3f &hpr, const LVecBase3f &scale) { + PartGroup *child = find_child(joint_name); + if (child == (PartGroup *)NULL) { + return false; + } + + CDWriter cdata(_cycler, false); + cdata->_anim_changed = true; + + return child->apply_freeze_matrix(pos, hpr, scale); +} + +//////////////////////////////////////////////////////////////////// +// Function: PartBundle::freeze_joint +// Access: Published +// Description: Specifies that the joint with the indicated name +// should be frozen with the specified transform. It +// will henceforth always hold this fixed transform, +// regardless of any animations that may subsequently be +// bound to the joint. +// +// Returns true if the joint is successfully frozen, or +// false if the named child is not a joint (or slider) +// or does not exist. +//////////////////////////////////////////////////////////////////// +bool PartBundle:: +freeze_joint(const string &joint_name, float value) { + PartGroup *child = find_child(joint_name); + if (child == (PartGroup *)NULL) { + return false; + } + + CDWriter cdata(_cycler, false); + cdata->_anim_changed = true; + + return child->apply_freeze_scalar(value); +} + //////////////////////////////////////////////////////////////////// // Function: PartBundle::control_joint // Access: Published diff --git a/panda/src/chan/partBundle.h b/panda/src/chan/partBundle.h index dfd744e38a..a8441c21c0 100644 --- a/panda/src/chan/partBundle.h +++ b/panda/src/chan/partBundle.h @@ -136,6 +136,8 @@ PUBLISHED: void wait_pending(); bool freeze_joint(const string &joint_name, const TransformState *transform); + bool freeze_joint(const string &joint_name, const LVecBase3f &pos, const LVecBase3f &hpr, const LVecBase3f &scale); + bool freeze_joint(const string &joint_name, float value); bool control_joint(const string &joint_name, PandaNode *node); bool release_joint(const string &joint_name); diff --git a/panda/src/chan/partGroup.cxx b/panda/src/chan/partGroup.cxx index 6b01d77bc3..2298bcacdd 100644 --- a/panda/src/chan/partGroup.cxx +++ b/panda/src/chan/partGroup.cxx @@ -148,7 +148,7 @@ find_child(const string &name) const { //////////////////////////////////////////////////////////////////// // Function: PartGroup::apply_freeze -// Access: Published, Virtual +// Access: Published // Description: Freezes this particular joint so that it will always // hold the specified transform. Returns true if this // is a joint that can be so frozen, false otherwise. @@ -159,9 +159,42 @@ find_child(const string &name) const { //////////////////////////////////////////////////////////////////// bool PartGroup:: apply_freeze(const TransformState *transform) { + return apply_freeze_matrix(transform->get_pos(), transform->get_hpr(), transform->get_scale()) || apply_freeze_scalar(transform->get_pos()[0]); +} + +//////////////////////////////////////////////////////////////////// +// Function: PartGroup::apply_freeze_matrix +// Access: Published, Virtual +// Description: Freezes this particular joint so that it will always +// hold the specified transform. Returns true if this +// is a joint that can be so frozen, false otherwise. +// +// This is normally only called internally by +// PartBundle::freeze_joint(), but you may also call it +// directly. +//////////////////////////////////////////////////////////////////// +bool PartGroup:: +apply_freeze_matrix(const LVecBase3f &pos, const LVecBase3f &hpr, const LVecBase3f &scale) { return false; } +//////////////////////////////////////////////////////////////////// +// Function: PartGroup::apply_freeze_scalar +// Access: Published, Virtual +// Description: Freezes this particular joint so that it will always +// hold the specified transform. Returns true if this +// is a joint that can be so frozen, false otherwise. +// +// This is normally only called internally by +// PartBundle::freeze_joint(), but you may also call it +// directly. +//////////////////////////////////////////////////////////////////// +bool PartGroup:: +apply_freeze_scalar(float value) { + return false; +} + + //////////////////////////////////////////////////////////////////// // Function: PartGroup::apply_control // Access: Published, Virtual diff --git a/panda/src/chan/partGroup.h b/panda/src/chan/partGroup.h index 9240c1ef07..f99d08ea3c 100644 --- a/panda/src/chan/partGroup.h +++ b/panda/src/chan/partGroup.h @@ -77,7 +77,9 @@ PUBLISHED: PartGroup *find_child(const string &name) const; - virtual bool apply_freeze(const TransformState *transform); + bool apply_freeze(const TransformState *transform); + virtual bool apply_freeze_matrix(const LVecBase3f &pos, const LVecBase3f &hpr, const LVecBase3f &scale); + virtual bool apply_freeze_scalar(float value); virtual bool apply_control(PandaNode *node); virtual bool clear_forced_channel(); virtual AnimChannelBase *get_forced_channel() const;