Bläddra i källkod

relative set_fluid_pos

David Rose 21 år sedan
förälder
incheckning
0fe1abded6
3 ändrade filer med 74 tillägg och 1 borttagningar
  1. 13 0
      panda/src/pgraph/nodePath.I
  2. 56 1
      panda/src/pgraph/nodePath.cxx
  3. 5 0
      panda/src/pgraph/nodePath.h

+ 13 - 0
panda/src/pgraph/nodePath.I

@@ -796,6 +796,19 @@ set_pos(const NodePath &other, float x, float y, float 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::
 get_x(const NodePath &other) const {
   return get_pos(other)[0];

+ 56 - 1
panda/src/pgraph/nodePath.cxx

@@ -1204,8 +1204,8 @@ set_pos(const NodePath &other, const LVecBase3f &pos) {
     // If we didn't have a componentwise transform already, never
     // mind.
     set_transform(other, rel_transform->set_pos(pos));
-    node()->reset_prev_transform();
   }
+  node()->reset_prev_transform();
 }
 
 void NodePath::
@@ -1232,6 +1232,61 @@ set_z(const NodePath &other, float z) {
   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
 //       Access: Published

+ 5 - 0
panda/src/pgraph/nodePath.h

@@ -351,6 +351,11 @@ PUBLISHED:
   void set_x(const NodePath &other, float x);
   void set_y(const NodePath &other, float y);
   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;
   INLINE float get_x(const NodePath &other) const;
   INLINE float get_y(const NodePath &other) const;