add set_hpr_scale and friends

This commit is contained in:
Dave Schuyler 2001-09-18 00:36:34 +00:00
parent c35ec7cca6
commit 9852625d2b
6 changed files with 202 additions and 0 deletions

View File

@ -39,6 +39,7 @@ ConfigureFn(config_sgmanip) {
HprLerpFunctor::init_type();
ScaleLerpFunctor::init_type();
PosHprLerpFunctor::init_type();
HprScaleLerpFunctor::init_type();
PosHprScaleLerpFunctor::init_type();
ColorLerpFunctor::init_type();
ColorScaleLerpFunctor::init_type();

View File

@ -683,6 +683,19 @@ set_pos_hpr(float x, float y, float z, float h, float p, float r) {
set_pos_hpr(LVecBase3f(x, y, z), LVecBase3f(h, p, r));
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::set_hpr_scale
// Access: Published
// Description: Sets the rotation and scale components of the
// transform, leaving translation untouched. This, or
// set_pos_hpr_scale, is the preferred way to update a
// transform when both hpr and scale are to be changed.
////////////////////////////////////////////////////////////////////
INLINE void NodePath::
set_hpr_scale(float h, float p, float r, float sx, float sy, float sz) {
set_hpr_scale(LVecBase3f(h, p, r), LVecBase3f(sx, sy, sz));
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::set_pos_hpr_scale
// Access: Published
@ -978,6 +991,20 @@ set_pos_hpr(const NodePath &other,
set_pos_hpr(other, LVecBase3f(x, y, z), LVecBase3f(h, p, r));
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::set_hpr_scale
// Access: Published
// Description: Sets the rotation and scale components of the
// transform, leaving translation untouched. This, or
// set_pos_hpr_scale, is the preferred way to update a
// transform when both hpr and scale are to be changed.
////////////////////////////////////////////////////////////////////
INLINE void NodePath::
set_hpr_scale(const NodePath &other,
float h, float p, float r, float sx, float sy, float sz) {
set_hpr_scale(other, LVecBase3f(h, p, r), LVecBase3f(sx, sy, sz));
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::set_pos_hpr_scale
// Access: Published

View File

@ -1380,6 +1380,24 @@ set_pos_hpr(const LVecBase3f &pos, const LVecBase3f &hpr) {
set_mat(mat);
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::set_hpr_scale
// Access: Published
// Description: Sets the rotation and scale components of the
// transform, leaving translation untouched. This, or
// set_pos_hpr_scale, is the preferred way to update a
// transform when both hpr and scale are to be changed.
////////////////////////////////////////////////////////////////////
void NodePath::
set_hpr_scale(const LVecBase3f &hpr, const LVecBase3f &scale) {
nassertv(has_arcs());
LMatrix4f mat = get_mat();
LVecBase3f old_pos;
mat.get_row3(old_pos, 3);
compose_matrix(mat, scale, hpr, old_pos);
set_mat(mat);
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::set_pos_hpr_scale
// Access: Published
@ -1769,6 +1787,24 @@ set_pos_hpr(const NodePath &other, const LVecBase3f &pos,
set_mat(other, mat);
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::set_hpr_scale
// Access: Published
// Description: Sets the rotation and scale components of the
// transform, leaving translation untouched. This, or
// set_pos_hpr_scale, is the preferred way to update a
// transform when both hpr and scale are to be changed.
////////////////////////////////////////////////////////////////////
void NodePath::
set_hpr_scale(const NodePath &other, const LVecBase3f &hpr, const LVecBase3f &scale) {
nassertv(has_arcs());
LMatrix4f mat = get_mat(other);
LVecBase3f old_pos;
mat.get_row3(old_pos, 3);
compose_matrix(mat, scale, hpr, old_pos);
set_mat(other, mat);
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::set_pos_hpr_scale
// Access: Published

View File

@ -302,6 +302,11 @@ PUBLISHED:
float h, float p, float r);
void set_pos_hpr(const LVecBase3f &pos,
const LVecBase3f &hpr);
INLINE void set_hpr_scale(float h, float p, float r,
float sx, float sy, float sz);
void set_hpr_scale(const LVecBase3f &hpr,
const LVecBase3f &scale);
INLINE void set_pos_hpr_scale(float x, float y, float z,
float h, float p, float r,
float sx, float sy, float sz);
@ -388,6 +393,12 @@ PUBLISHED:
void set_pos_hpr(const NodePath &other,
const LVecBase3f &pos,
const LVecBase3f &hpr);
INLINE void set_hpr_scale(const NodePath &other,
float h, float p, float r,
float sx, float sy, float sz);
void set_hpr_scale(const NodePath &other,
const LVecBase3f &hpr,
const LVecBase3f &scale);
INLINE void set_pos_hpr_scale(const NodePath &other,
float x, float y, float z,
float h, float p, float r,

View File

@ -23,6 +23,7 @@ TypeHandle HprLerpFunctor::_type_handle;
TypeHandle ScaleLerpFunctor::_type_handle;
TypeHandle ColorLerpFunctor::_type_handle;
TypeHandle PosHprLerpFunctor::_type_handle;
TypeHandle HprScaleLerpFunctor::_type_handle;
TypeHandle PosHprScaleLerpFunctor::_type_handle;
TypeHandle ColorScaleLerpFunctor::_type_handle;
@ -173,6 +174,55 @@ void PosHprLerpFunctor::operator()(float t) {
_node_path.set_pos_hpr(p, h);
}
HprScaleLerpFunctor::HprScaleLerpFunctor(const HprScaleLerpFunctor& c)
: LerpFunctor(c), _node_path(c._node_path) {}
void HprScaleLerpFunctor::take_shortest(void) {
// so long as these are actually degrees
for (int i=0; i!=3; ++i)
if (this->_hdiff_cache[i] < -180.)
_hstart[i] -= 360.;
else if (this->_hdiff_cache[i] > 180.)
_hstart[i] += 360.;
this->_hdiff_cache = this->_hend - this->_hstart;
}
void HprScaleLerpFunctor::take_longest(void) {
// so long as these are actually degrees
for (int i=0; i!=3; ++i)
if ((this->_hdiff_cache[i] < 0.) && (this->_hdiff_cache[i] > -180.))
_hstart[i] -= 360.;
else if ((this->_hdiff_cache[i] >= 0.) && (this->_hdiff_cache[i] < 180))
_hstart[i] += 360.;
this->_hdiff_cache = this->_hend - this->_hstart;
}
HprScaleLerpFunctor::~HprScaleLerpFunctor(void)
{
}
HprScaleLerpFunctor&
HprScaleLerpFunctor::operator=(const HprScaleLerpFunctor& c) {
_node_path = c._node_path;
_hstart = c._hstart;
_hend = c._hend;
_hdiff_cache = c._hdiff_cache;
_sstart = c._sstart;
_send = c._send;
_sdiff_cache = c._sdiff_cache;
LerpFunctor::operator=(c);
return *this;
}
void HprScaleLerpFunctor::operator()(float t) {
LVecBase3f h = ((t * _hdiff_cache) + _hstart);
LVecBase3f s = ((t * _sdiff_cache) + _sstart);
if (_is_wrt)
_node_path.set_hpr_scale(_wrt_path, h, s);
else
_node_path.set_hpr_scale(h, s);
}
PosHprScaleLerpFunctor::PosHprScaleLerpFunctor(const PosHprScaleLerpFunctor& c)
: LerpFunctor(c), _node_path(c._node_path) {}

View File

@ -305,6 +305,83 @@ private:
static TypeHandle _type_handle;
};
////////////////////////////////////////////////////////////////////
// Class : HprScaleLerpFunctor
// Description : Class for Lerping between orientation
// and scale
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA HprScaleLerpFunctor : public LerpFunctor {
private:
NodePath _node_path;
LVecBase3f _hstart;
LVecBase3f _hend;
LVecBase3f _hdiff_cache;
LVecBase3f _sstart;
LVecBase3f _send;
LVecBase3f _sdiff_cache;
bool _is_wrt;
NodePath _wrt_path;
PUBLISHED:
HprScaleLerpFunctor(NodePath np,
LVecBase3f hstart, LVecBase3f hend, LVecBase3f sstart,
LVecBase3f send)
: LerpFunctor(), _node_path(np),
_hstart(hstart), _hend(hend),
_hdiff_cache(hend-hstart), _sstart(sstart), _send(send),
_sdiff_cache(send-sstart), _is_wrt(false) {}
HprScaleLerpFunctor(NodePath np, float hsx, float hsy,
float hsz, float hex, float hey, float hez, float ssx,
float ssy, float ssz, float sex, float sey, float sez)
: LerpFunctor(), _node_path(np),
_hstart(hsx, hsy, hsz), _hend(hex, hey, hez),
_hdiff_cache(_hend-_hstart), _sstart(ssx, ssy, ssz),
_send(sex, sey, sez), _sdiff_cache(_send-_sstart), _is_wrt(false) {}
HprScaleLerpFunctor(NodePath np,
LVecBase3f hstart, LVecBase3f hend, LVecBase3f sstart,
LVecBase3f send, NodePath wrt)
: LerpFunctor(), _node_path(np), _hstart(hstart), _hend(hend),
_hdiff_cache(hend-hstart), _sstart(sstart), _send(send),
_sdiff_cache(send-sstart), _is_wrt(true), _wrt_path(wrt) {}
HprScaleLerpFunctor(NodePath np, float hsx, float hsy,
float hsz, float hex, float hey, float hez, float ssx,
float ssy, float ssz, float sex, float sey, float sez,
NodePath wrt)
: LerpFunctor(), _node_path(np),
_hstart(hsx, hsy, hsz), _hend(hex, hey, hez),
_hdiff_cache(_hend-_hstart), _sstart(ssx, ssy, ssz),
_send(sex, sey, sez), _sdiff_cache(_send-_sstart), _is_wrt(true),
_wrt_path(wrt) {}
void take_shortest(void);
void take_longest(void);
public:
HprScaleLerpFunctor(const HprScaleLerpFunctor&);
virtual ~HprScaleLerpFunctor(void);
HprScaleLerpFunctor& operator=(const HprScaleLerpFunctor&);
virtual void operator()(float);
public:
// now for typehandle stuff
static TypeHandle get_class_type(void) {
return _type_handle;
}
static void init_type(void) {
LerpFunctor::init_type();
register_type(_type_handle, "HprScaleLerpFunctor",
LerpFunctor::get_class_type());
}
virtual TypeHandle get_type(void) const {
return get_class_type();
}
virtual TypeHandle force_init_type(void) {
init_type();
return get_class_type();
}
private:
static TypeHandle _type_handle;
};
////////////////////////////////////////////////////////////////////
// Class : PosHprScaleLerpFunctor
// Description : Class for Lerping between position, orientation,