relative set_fluid_pos

This commit is contained in:
David Rose 2004-06-24 23:11:22 +00:00
parent 9a2ff1bac0
commit 0fe1abded6
3 changed files with 74 additions and 1 deletions

View File

@ -796,6 +796,19 @@ set_pos(const NodePath &other, float x, float y, float z) {
set_pos(other, LPoint3f(x, y, z)); set_pos(other, LPoint3f(x, y, z));
} }
////////////////////////////////////////////////////////////////////
// Function: NodePath::set_fluid_pos
// Access: Published
// Description: Sets the translation component, without changing the
// "previous" position, so that the collision system
// will see the node as moving fluidly from its previous
// position to its new position.
////////////////////////////////////////////////////////////////////
INLINE void NodePath::
set_fluid_pos(const NodePath &other, float x, float y, float z) {
set_fluid_pos(other, LPoint3f(x, y, z));
}
INLINE float NodePath:: INLINE float NodePath::
get_x(const NodePath &other) const { get_x(const NodePath &other) const {
return get_pos(other)[0]; return get_pos(other)[0];

View File

@ -1204,8 +1204,8 @@ set_pos(const NodePath &other, const LVecBase3f &pos) {
// If we didn't have a componentwise transform already, never // If we didn't have a componentwise transform already, never
// mind. // mind.
set_transform(other, rel_transform->set_pos(pos)); set_transform(other, rel_transform->set_pos(pos));
node()->reset_prev_transform();
} }
node()->reset_prev_transform();
} }
void NodePath:: void NodePath::
@ -1232,6 +1232,61 @@ set_z(const NodePath &other, float z) {
set_pos(other, pos); set_pos(other, pos);
} }
////////////////////////////////////////////////////////////////////
// Function: NodePath::set_fluid_pos
// Access: Published
// Description: Sets the translation component of the transform,
// relative to the other node.
////////////////////////////////////////////////////////////////////
void NodePath::
set_fluid_pos(const NodePath &other, const LVecBase3f &pos) {
nassertv_always(!is_empty());
CPT(TransformState) rel_transform = get_transform(other);
CPT(TransformState) orig_transform = get_transform();
if (orig_transform->has_components()) {
// If we had a componentwise transform before we started, we
// should be careful to preserve the other three components. We
// wouldn't need to do this, except for the possibility of
// numerical error or decompose ambiguity.
const LVecBase3f &orig_hpr = orig_transform->get_hpr();
const LVecBase3f &orig_scale = orig_transform->get_scale();
const LVecBase3f &orig_shear = orig_transform->get_shear();
set_transform(other, rel_transform->set_pos(pos));
set_pos_hpr_scale_shear(get_transform()->get_pos(), orig_hpr, orig_scale, orig_shear);
} else {
// If we didn't have a componentwise transform already, never
// mind.
set_transform(other, rel_transform->set_pos(pos));
}
}
void NodePath::
set_fluid_x(const NodePath &other, float x) {
nassertv_always(!is_empty());
LPoint3f pos = get_pos(other);
pos[0] = x;
set_fluid_pos(other, pos);
}
void NodePath::
set_fluid_y(const NodePath &other, float y) {
nassertv_always(!is_empty());
LPoint3f pos = get_pos(other);
pos[1] = y;
set_fluid_pos(other, pos);
}
void NodePath::
set_fluid_z(const NodePath &other, float z) {
nassertv_always(!is_empty());
LPoint3f pos = get_pos(other);
pos[2] = z;
set_fluid_pos(other, pos);
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: NodePath::get_pos // Function: NodePath::get_pos
// Access: Published // Access: Published

View File

@ -351,6 +351,11 @@ PUBLISHED:
void set_x(const NodePath &other, float x); void set_x(const NodePath &other, float x);
void set_y(const NodePath &other, float y); void set_y(const NodePath &other, float y);
void set_z(const NodePath &other, float z); void set_z(const NodePath &other, float z);
INLINE void set_fluid_pos(const NodePath &other, float x, float y, float z);
void set_fluid_pos(const NodePath &other, const LVecBase3f &pos);
void set_fluid_x(const NodePath &other, float x);
void set_fluid_y(const NodePath &other, float y);
void set_fluid_z(const NodePath &other, float z);
LPoint3f get_pos(const NodePath &other) const; LPoint3f get_pos(const NodePath &other) const;
INLINE float get_x(const NodePath &other) const; INLINE float get_x(const NodePath &other) const;
INLINE float get_y(const NodePath &other) const; INLINE float get_y(const NodePath &other) const;