瀏覽代碼

integrate changes from Schell Games

David Rose 16 年之前
父節點
當前提交
1ce2ce2413

+ 21 - 4
direct/src/directutil/Mopath.py

@@ -7,7 +7,7 @@ class Mopath(DirectObject):
 
 
     nameIndex = 1
     nameIndex = 1
 
 
-    def __init__(self, name = None, fluid = 1):
+    def __init__(self, name = None, fluid = 1, objectToLoad = None, upVectorNodePath = None, reverseUpVector = False):
         if (name == None):
         if (name == None):
             name = 'mopath%d' % self.nameIndex
             name = 'mopath%d' % self.nameIndex
             self.nameIndex = self.nameIndex + 1
             self.nameIndex = self.nameIndex + 1
@@ -19,7 +19,15 @@ class Mopath(DirectObject):
         self.tangentVec = Vec3(0)
         self.tangentVec = Vec3(0)
         self.fFaceForward = 0
         self.fFaceForward = 0
         self.timeScale = 1
         self.timeScale = 1
+        self.upVectorNodePath = upVectorNodePath
+        self.reverseUpVector = reverseUpVector
         self.reset()
         self.reset()
+        if isinstance( objectToLoad, NodePath ):
+            self.loadNodePath( objectToLoad )
+        elif isinstance( objectToLoad, str ):
+            self.loadFile( objectToLoad )
+        elif objectToLoad is not None:
+            print "Mopath: Unable to load object '%s', objectToLoad must be a file name string or a NodePath" % objectToLoad
 
 
     def getMaxT(self):
     def getMaxT(self):
         return self.maxT * self.timeScale
         return self.maxT * self.timeScale
@@ -45,7 +53,7 @@ class Mopath(DirectObject):
         elif (self.hprNurbsCurve != None):
         elif (self.hprNurbsCurve != None):
             self.maxT = self.hprNurbsCurve.getMaxT()
             self.maxT = self.hprNurbsCurve.getMaxT()
         else:
         else:
-            print 'Mopath: no valid curves in file.'
+            print 'Mopath: no valid curves in nodePath: %s' % nodePath
 
 
 
 
     def reset(self):
     def reset(self):
@@ -67,7 +75,7 @@ class Mopath(DirectObject):
                 if (self.xyzNurbsCurve == None):
                 if (self.xyzNurbsCurve == None):
                     self.xyzNurbsCurve = node
                     self.xyzNurbsCurve = node
                 else:
                 else:
-                    print 'Mopath: got a PCT_NONE curve and an XYZ Curve!'
+                    print 'Mopath: got a PCT_NONE curve and an XYZ Curve in nodePath: %s' % nodePath
             elif (node.getCurveType() == PCTT):
             elif (node.getCurveType() == PCTT):
                 self.tNurbsCurve.append(node)
                 self.tNurbsCurve.append(node)
         else:
         else:
@@ -111,7 +119,16 @@ class Mopath(DirectObject):
             node.setHpr(self.hprPoint)
             node.setHpr(self.hprPoint)
         elif (self.fFaceForward and (self.xyzNurbsCurve != None)):
         elif (self.fFaceForward and (self.xyzNurbsCurve != None)):
             self.xyzNurbsCurve.getTangent(self.playbackTime, self.tangentVec)
             self.xyzNurbsCurve.getTangent(self.playbackTime, self.tangentVec)
-            node.lookAt(Point3(self.posPoint + self.tangentVec))
+            #use the self.upVectorNodePath position if it exists to create an up vector for lookAt
+            if (self.upVectorNodePath is None):
+                node.lookAt(Point3(self.posPoint + self.tangentVec))
+            else:
+                if (self.reverseUpVector == False):
+                     node.lookAt(Point3(self.posPoint + self.tangentVec),
+                                 self.upVectorNodePath.getPos() - self.posPoint)
+                else:
+                     node.lookAt(Point3(self.posPoint + self.tangentVec),
+                                 self.posPoint - self.upVectorNodePath.getPos())
 
 
     def play(self, node, time = 0.0, loop = 0):
     def play(self, node, time = 0.0, loop = 0):
         if (self.xyzNurbsCurve == None) and (self.hprNurbsCurve == None):
         if (self.xyzNurbsCurve == None) and (self.hprNurbsCurve == None):

+ 37 - 5
direct/src/interval/Interval.py

@@ -346,11 +346,43 @@ class Interval(DirectObject):
                     self.__clockStart += numLoops * timePerLoop
                     self.__clockStart += numLoops * timePerLoop
 
 
         else:
         else:
-            # Playing backwards.  Not supported at the moment for
-            # Python-style intervals.  To add support, copy the code
-            # from C++-style intervals in cInterval.cxx, and modify it
-            # for Python (as the above).
-            pass
+            # Playing backwards
+            t = (now - self.__clockStart) * self.__playRate + self.__endT
+
+            if t >= self.__startT:
+                # In the middle of the interval, not a problem.
+                if self.isStopped():
+                    self.privInitialize(t)
+                else:
+                    self.privStep(t)
+            else:
+                # Past the ending point; time to finalize.
+                if self.__startTAtStart:
+                    # Only finalize if the playback cycle includes the
+                    # whole interval.
+                    if self.isStopped():
+                        if self.getOpenEnded() or self.__loopCount != 0:
+                            self.privReverseInstant()
+                    else:
+                        self.privReverseFinalize()
+                else:
+                    if self.isStopped():
+                        self.privReverseInitialize(self.__startT)
+                    else:
+                        self.privStep(self.__startT)
+
+                # Advance the clock for the next loop cycle.
+                if self.__endT == self.__startT:
+                    # If the interval has no length, we loop exactly once.
+                    self.__loopCount += 1
+
+                else:
+                    # Otherwise, figure out how many loops we need to
+                    # skip.
+                    timePerLoop = (self.__endT - self.__startT) / -self.__playRate
+                    numLoops = math.floor((now - self.__clockStart) / timePerLoop)
+                    self.__loopCount += numLoops
+                    self.__clockStart += numLoops * timePerLoop
 
 
         shouldContinue = (self.__loopCount == 0 or self.__doLoop)
         shouldContinue = (self.__loopCount == 0 or self.__doLoop)
 
 

+ 10 - 0
direct/src/interval/Sources.pp

@@ -16,6 +16,11 @@
     config_interval.cxx config_interval.h \
     config_interval.cxx config_interval.h \
     cInterval.cxx cInterval.I cInterval.h \
     cInterval.cxx cInterval.I cInterval.h \
     cIntervalManager.cxx cIntervalManager.I cIntervalManager.h \
     cIntervalManager.cxx cIntervalManager.I cIntervalManager.h \
+    cConstraintInterval.cxx cConstraintInterval.I cConstraintInterval.h \
+    cConstrainTransformInterval.cxx cConstrainTransformInterval.I cConstrainTransformInterval.h \
+    cConstrainPosInterval.cxx cConstrainPosInterval.I cConstrainPosInterval.h \
+    cConstrainHprInterval.cxx cConstrainHprInterval.I cConstrainHprInterval.h \
+    cConstrainPosHprInterval.cxx cConstrainPosHprInterval.I cConstrainPosHprInterval.h \
     cLerpInterval.cxx cLerpInterval.I cLerpInterval.h \
     cLerpInterval.cxx cLerpInterval.I cLerpInterval.h \
     cLerpNodePathInterval.cxx cLerpNodePathInterval.I cLerpNodePathInterval.h \
     cLerpNodePathInterval.cxx cLerpNodePathInterval.I cLerpNodePathInterval.h \
     cLerpAnimEffectInterval.cxx cLerpAnimEffectInterval.I cLerpAnimEffectInterval.h \
     cLerpAnimEffectInterval.cxx cLerpAnimEffectInterval.I cLerpAnimEffectInterval.h \
@@ -29,6 +34,11 @@
     config_interval.h \
     config_interval.h \
     cInterval.I cInterval.h \
     cInterval.I cInterval.h \
     cIntervalManager.I cIntervalManager.h \
     cIntervalManager.I cIntervalManager.h \
+    cConstraintInterval.I cConstraintInterval.h \
+    cConstrainTransformInterval.I cConstrainTransformInterval.h \
+    cConstrainPosInterval.I cConstrainPosInterval.h \
+    cConstrainHprInterval.I cConstrainHprInterval.h \
+    cConstrainPosHprInterval.I cConstrainPosHprInterval.h \
     cLerpInterval.I cLerpInterval.h \
     cLerpInterval.I cLerpInterval.h \
     cLerpNodePathInterval.I cLerpNodePathInterval.h \
     cLerpNodePathInterval.I cLerpNodePathInterval.h \
     cLerpAnimEffectInterval.I cLerpAnimEffectInterval.h \
     cLerpAnimEffectInterval.I cLerpAnimEffectInterval.h \

+ 38 - 0
direct/src/interval/cConstrainHprInterval.I

@@ -0,0 +1,38 @@
+// Filename: cConstrainHprInterval.I
+// Created by:  pratt (10Mar08)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2008, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainHprInterval::get_node
+//       Access: Published
+//  Description: Returns the "source" node.
+////////////////////////////////////////////////////////////////////
+INLINE const NodePath &CConstrainHprInterval::
+get_node() const {
+  return _node;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainHprInterval::get_target
+//       Access: Published
+//  Description: Returns the "target" node.
+////////////////////////////////////////////////////////////////////
+INLINE const NodePath &CConstrainHprInterval::
+get_target() const {
+  return _target;
+}

+ 88 - 0
direct/src/interval/cConstrainHprInterval.cxx

@@ -0,0 +1,88 @@
+// Filename: cConstrainHprInterval.cxx
+// Created by:  pratt (10Mar08)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2008, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "cConstrainHprInterval.h"
+#include "config_interval.h"
+#include "lvecBase3.h"
+
+TypeHandle CConstrainHprInterval::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainHprInterval::Constructor
+//       Access: Published
+//  Description: Constructs a constraint interval that will constrain
+//               the orientation of one node to the orientation of
+//               another, possibly with an added rotation.
+//
+//               If wrt is true, the node's orientation will be
+//               transformed into the target node's parent's  space
+//               before being copied.  If wrt is false, the target
+//               node's local orientation will be copied unaltered.
+////////////////////////////////////////////////////////////////////
+CConstrainHprInterval::
+CConstrainHprInterval(const string &name, double duration,
+                      const NodePath &node, const NodePath &target,
+                      bool wrt, const LVecBase3f hprOffset) :
+  CConstraintInterval(name, duration),
+  _node(node),
+  _target(target),
+  _wrt(wrt)
+{
+  _quatOffset.set_hpr(hprOffset);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainHprInterval::step
+//       Access: Published, Virtual
+//  Description: Advances the time on the interval.  The time may
+//               either increase (the normal case) or decrease
+//               (e.g. if the interval is being played by a slider).
+////////////////////////////////////////////////////////////////////
+void CConstrainHprInterval::
+priv_step(double t) {
+  check_started(get_class_type(), "priv_step");
+  _state = S_started;
+  _curr_t = t;
+
+  if(! _target.is_empty()) {
+    if(_wrt) {
+      if(! _node.is_same_graph(_target)){
+        interval_cat.warning()
+          << "Unable to copy orientation in CConstrainHprInterval::priv_step;\n"
+          << "node (" << _node.get_name()
+          << ") and target (" << _target.get_name()
+          << ") are not in the same graph.\n";
+        return;
+      }
+      _target.set_quat(_node, _quatOffset);
+    } else {
+      _target.set_quat(_quatOffset*_node.get_quat());
+    }
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainHprInterval::output
+//       Access: Published, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void CConstrainHprInterval::
+output(ostream &out) const {
+  out << get_name() << ":";
+  out << " dur " << get_duration();
+}

+ 72 - 0
direct/src/interval/cConstrainHprInterval.h

@@ -0,0 +1,72 @@
+// Filename: cConstrainHprInterval.h
+// Created by:  pratt (10Mar08)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2008, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef CCONSTRAINHPRINTERVAL_H
+#define CCONSTRAINHPRINTERVAL_H
+
+#include "directbase.h"
+#include "cConstraintInterval.h"
+#include "nodePath.h"
+#include "lvecBase3.h"
+#include "lquaternion.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : CConstrainHprInterval
+// Description : A constraint interval that will constrain the
+//               orientation of one node to the orientation of another.
+////////////////////////////////////////////////////////////////////
+class EXPCL_DIRECT CConstrainHprInterval : public CConstraintInterval {
+PUBLISHED:
+  CConstrainHprInterval(const string &name, double duration,
+                        const NodePath &node, const NodePath &target,
+                        bool wrt, const LVecBase3f hprOffset=LVector3f::zero());
+
+  INLINE const NodePath &get_node() const;
+  INLINE const NodePath &get_target() const;
+
+  virtual void priv_step(double t);
+  virtual void output(ostream &out) const;
+
+private:
+  NodePath _node;
+  NodePath _target;
+  bool _wrt;
+  LQuaternionf _quatOffset;
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    CConstraintInterval::init_type();
+    register_type(_type_handle, "CConstrainHprInterval",
+                  CConstraintInterval::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "cConstrainHprInterval.I"
+
+#endif
+

+ 38 - 0
direct/src/interval/cConstrainPosHprInterval.I

@@ -0,0 +1,38 @@
+// Filename: cConstrainPosHprInterval.I
+// Created by:  pratt (10Mar08)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2008, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainPosHprInterval::get_node
+//       Access: Published
+//  Description: Returns the "source" node.
+////////////////////////////////////////////////////////////////////
+INLINE const NodePath &CConstrainPosHprInterval::
+get_node() const {
+  return _node;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainPosHprInterval::get_target
+//       Access: Published
+//  Description: Returns the "target" node.
+////////////////////////////////////////////////////////////////////
+INLINE const NodePath &CConstrainPosHprInterval::
+get_target() const {
+  return _target;
+}

+ 91 - 0
direct/src/interval/cConstrainPosHprInterval.cxx

@@ -0,0 +1,91 @@
+// Filename: cConstrainPosHprInterval.cxx
+// Created by:  pratt (10Mar08)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2008, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "cConstrainPosHprInterval.h"
+#include "config_interval.h"
+#include "lvecBase3.h"
+
+TypeHandle CConstrainPosHprInterval::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainPosHprInterval::Constructor
+//       Access: Published
+//  Description: Constructs a constraint interval that will constrain
+//               the position and orientation of one node to the
+//               position and orientation of another.
+//
+//               If wrt is true, the node's position and orientation
+//               will be transformed into the target node's parent's
+//               space before being copied.  If wrt is false, the
+//               target node's local position and orientation will be
+//               copied unaltered.
+////////////////////////////////////////////////////////////////////
+CConstrainPosHprInterval::
+CConstrainPosHprInterval(const string &name, double duration,
+                         const NodePath &node, const NodePath &target,
+                         bool wrt, const LVecBase3f posOffset,
+                         const LVecBase3f hprOffset) :
+  CConstraintInterval(name, duration),
+  _node(node),
+  _target(target),
+  _wrt(wrt),
+  _posOffset(posOffset)
+{
+  _quatOffset.set_hpr(hprOffset);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainPosHprInterval::step
+//       Access: Published, Virtual
+//  Description: Advances the time on the interval.  The time may
+//               either increase (the normal case) or decrease
+//               (e.g. if the interval is being played by a slider).
+////////////////////////////////////////////////////////////////////
+void CConstrainPosHprInterval::
+priv_step(double t) {
+  check_started(get_class_type(), "priv_step");
+  _state = S_started;
+  _curr_t = t;
+
+  if(! _target.is_empty()) {
+    if(_wrt) {
+      if(! _node.is_same_graph(_target)){
+        interval_cat.warning()
+          << "Unable to copy position and orientation in CConstrainPosHprInterval::priv_step;\n"
+          << "node (" << _node.get_name()
+          << ") and target (" << _target.get_name()
+          << ") are not in the same graph.\n";
+        return;
+      }
+      _target.set_pos_quat(_node, _posOffset, _quatOffset);
+    } else {
+      _target.set_pos_quat(_node.get_pos() + _posOffset, _quatOffset*_node.get_quat());
+    }
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainPosHprInterval::output
+//       Access: Published, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void CConstrainPosHprInterval::
+output(ostream &out) const {
+  out << get_name() << ":";
+  out << " dur " << get_duration();
+}

+ 75 - 0
direct/src/interval/cConstrainPosHprInterval.h

@@ -0,0 +1,75 @@
+// Filename: cConstrainPosHprInterval.h
+// Created by:  pratt (10Mar08)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2008, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef CCONSTRAINPOSHPRINTERVAL_H
+#define CCONSTRAINPOSHPRINTERVAL_H
+
+#include "directbase.h"
+#include "cConstraintInterval.h"
+#include "nodePath.h"
+#include "lvecBase3.h"
+#include "lquaternion.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : CConstrainPosHprInterval
+// Description : A constraint interval that will constrain the
+//               position and orientation of one node to the
+//               position and orientation of another.
+////////////////////////////////////////////////////////////////////
+class EXPCL_DIRECT CConstrainPosHprInterval : public CConstraintInterval {
+PUBLISHED:
+  CConstrainPosHprInterval(const string &name, double duration,
+                           const NodePath &node, const NodePath &target,
+                           bool wrt, const LVecBase3f posOffset=LVector3f::zero(),
+                           const LVecBase3f hprOffset=LVector3f::zero());
+
+  INLINE const NodePath &get_node() const;
+  INLINE const NodePath &get_target() const;
+
+  virtual void priv_step(double t);
+  virtual void output(ostream &out) const;
+
+private:
+  NodePath _node;
+  NodePath _target;
+  bool _wrt;
+  LVecBase3f _posOffset;
+  LQuaternionf _quatOffset;
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    CConstraintInterval::init_type();
+    register_type(_type_handle, "CConstrainPosHprInterval",
+                  CConstraintInterval::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "cConstrainPosHprInterval.I"
+
+#endif
+

+ 38 - 0
direct/src/interval/cConstrainPosInterval.I

@@ -0,0 +1,38 @@
+// Filename: cConstrainPosInterval.I
+// Created by:  pratt (29Sep06)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainPosInterval::get_node
+//       Access: Published
+//  Description: Returns the "source" node.
+////////////////////////////////////////////////////////////////////
+INLINE const NodePath &CConstrainPosInterval::
+get_node() const {
+  return _node;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainPosInterval::get_target
+//       Access: Published
+//  Description: Returns the "target" node.
+////////////////////////////////////////////////////////////////////
+INLINE const NodePath &CConstrainPosInterval::
+get_target() const {
+  return _target;
+}

+ 91 - 0
direct/src/interval/cConstrainPosInterval.cxx

@@ -0,0 +1,91 @@
+// Filename: cConstrainPosInterval.cxx
+// Created by:  pratt (29Sep06)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "cConstrainPosInterval.h"
+#include "config_interval.h"
+#include "lvecBase3.h"
+
+TypeHandle CConstrainPosInterval::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainPosInterval::Constructor
+//       Access: Published
+//  Description: Constructs a constraint interval that will constrain
+//               the position of one node to the position of another.
+//
+//               If wrt is true, the node's position will be
+//               transformed into the target node's parent's  space
+//               before being copied.  If wrt is false, the target
+//               node's local position will be copied unaltered.
+////////////////////////////////////////////////////////////////////
+CConstrainPosInterval::
+CConstrainPosInterval(const string &name, double duration,
+                      const NodePath &node, const NodePath &target,
+                      bool wrt, const LVecBase3f posOffset) :
+  CConstraintInterval(name, duration),
+  _node(node),
+  _target(target),
+  _wrt(wrt),
+  _posOffset(posOffset)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainPosInterval::step
+//       Access: Published, Virtual
+//  Description: Advances the time on the interval.  The time may
+//               either increase (the normal case) or decrease
+//               (e.g. if the interval is being played by a slider).
+////////////////////////////////////////////////////////////////////
+void CConstrainPosInterval::
+priv_step(double t) {
+  check_started(get_class_type(), "priv_step");
+  _state = S_started;
+  _curr_t = t;
+
+  if(! _target.is_empty()) {
+    if(_wrt) {
+      if(! _node.is_same_graph(_target)){
+        interval_cat.warning()
+          << "Unable to copy position in CConstrainPosInterval::priv_step;\n"
+          << "node (" << _node.get_name()
+          << ") and target (" << _target.get_name()
+          << ") are not in the same graph.\n";
+        return;
+      }
+      _target.set_pos(_node, _posOffset);
+    } else {
+      if(_posOffset == LVector3f::zero()) {
+        _target.set_pos(_node.get_pos());
+      } else {
+        _target.set_pos(_node.get_pos() + _posOffset);
+      }
+    }
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainPosInterval::output
+//       Access: Published, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void CConstrainPosInterval::
+output(ostream &out) const {
+  out << get_name() << ":";
+  out << " dur " << get_duration();
+}

+ 71 - 0
direct/src/interval/cConstrainPosInterval.h

@@ -0,0 +1,71 @@
+// Filename: cConstrainPosInterval.h
+// Created by:  pratt (29Sep06)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef CCONSTRAINPOSINTERVAL_H
+#define CCONSTRAINPOSINTERVAL_H
+
+#include "directbase.h"
+#include "cConstraintInterval.h"
+#include "nodePath.h"
+#include "lvecBase3.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : CConstrainPosInterval
+// Description : A constraint interval that will constrain the
+//               position of one node to the position of another.
+////////////////////////////////////////////////////////////////////
+class EXPCL_DIRECT CConstrainPosInterval : public CConstraintInterval {
+PUBLISHED:
+  CConstrainPosInterval(const string &name, double duration,
+                        const NodePath &node, const NodePath &target,
+                        bool wrt, const LVecBase3f posOffset=LVector3f::zero());
+
+  INLINE const NodePath &get_node() const;
+  INLINE const NodePath &get_target() const;
+
+  virtual void priv_step(double t);
+  virtual void output(ostream &out) const;
+
+private:
+  NodePath _node;
+  NodePath _target;
+  bool _wrt;
+  LVecBase3f _posOffset;
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    CConstraintInterval::init_type();
+    register_type(_type_handle, "CConstrainPosInterval",
+                  CConstraintInterval::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "cConstrainPosInterval.I"
+
+#endif
+

+ 38 - 0
direct/src/interval/cConstrainTransformInterval.I

@@ -0,0 +1,38 @@
+// Filename: cConstrainTransformInterval.I
+// Created by:  pratt (29Sep06)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainTransformInterval::get_node
+//       Access: Published
+//  Description: Returns the "source" node.
+////////////////////////////////////////////////////////////////////
+INLINE const NodePath &CConstrainTransformInterval::
+get_node() const {
+  return _node;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainTransformInterval::get_target
+//       Access: Published
+//  Description: Returns the "target" node.
+////////////////////////////////////////////////////////////////////
+INLINE const NodePath &CConstrainTransformInterval::
+get_target() const {
+  return _target;
+}

+ 90 - 0
direct/src/interval/cConstrainTransformInterval.cxx

@@ -0,0 +1,90 @@
+// Filename: cConstrainTransformInterval.cxx
+// Created by:  pratt (29Sep06)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "cConstrainTransformInterval.h"
+#include "transformState.h"
+#include "config_interval.h"
+
+TypeHandle CConstrainTransformInterval::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainTransformInterval::Constructor
+//       Access: Published
+//  Description: Constructs a constraint interval that will constrain
+//               the transform of one node to the transform of another.
+//               To clarify, the transform of node will be copied to target.
+//
+//               If wrt is true, the node's transform will be
+//               transformed into the target node's parent's  space
+//               before being copied.  If wrt is false, the node's
+//               local transform will be copied unaltered.
+////////////////////////////////////////////////////////////////////
+CConstrainTransformInterval::
+CConstrainTransformInterval(const string &name, double duration,
+                            const NodePath &node, const NodePath &target,
+                            bool wrt) :
+  CConstraintInterval(name, duration),
+  _node(node),
+  _target(target),
+  _wrt(wrt)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainTransformInterval::step
+//       Access: Published, Virtual
+//  Description: Advances the time on the interval.  The time may
+//               either increase (the normal case) or decrease
+//               (e.g. if the interval is being played by a slider).
+////////////////////////////////////////////////////////////////////
+void CConstrainTransformInterval::
+priv_step(double t) {
+  check_started(get_class_type(), "priv_step");
+  _state = S_started;
+  _curr_t = t;
+
+  if(! _target.is_empty()) {
+    CPT(TransformState) transform;
+    if(_wrt) {
+      if(! _node.is_same_graph(_target)){
+        interval_cat.warning()
+          << "Unable to copy transform in CConstrainTransformInterval::priv_step;\n"
+          << "node (" << _node.get_name()
+          << ") and target (" << _target.get_name()
+          << ") are not in the same graph.\n";
+        return;
+      }
+      transform = _node.get_transform(_target.get_parent());
+    } else {
+      transform = _node.get_transform();
+    }
+
+    _target.set_transform(transform);
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstrainTransformInterval::output
+//       Access: Published, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void CConstrainTransformInterval::
+output(ostream &out) const {
+  out << get_name() << ":";
+  out << " dur " << get_duration();
+}

+ 69 - 0
direct/src/interval/cConstrainTransformInterval.h

@@ -0,0 +1,69 @@
+// Filename: cConstrainTransformInterval.h
+// Created by:  pratt (29Sep06)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef CCONSTRAINTRANSFORMINTERVAL_H
+#define CCONSTRAINTRANSFORMINTERVAL_H
+
+#include "directbase.h"
+#include "cConstraintInterval.h"
+#include "nodePath.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : CConstrainTransformInterval
+// Description : A constraint interval that will constrain the
+//               transform of one node to the transform of another.
+////////////////////////////////////////////////////////////////////
+class EXPCL_DIRECT CConstrainTransformInterval : public CConstraintInterval {
+PUBLISHED:
+  CConstrainTransformInterval(const string &name, double duration,
+                              const NodePath &node, const NodePath &target,
+                              bool wrt);
+
+  INLINE const NodePath &get_node() const;
+  INLINE const NodePath &get_target() const;
+
+  virtual void priv_step(double t);
+  virtual void output(ostream &out) const;
+
+private:
+  NodePath _node;
+  NodePath _target;
+  bool _wrt;
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    CConstraintInterval::init_type();
+    register_type(_type_handle, "CConstrainTransformInterval",
+                  CConstraintInterval::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "cConstrainTransformInterval.I"
+
+#endif
+

+ 19 - 0
direct/src/interval/cConstraintInterval.I

@@ -0,0 +1,19 @@
+// Filename: cConstraintInterval.I
+// Created by:  pratt (29Sep06)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+

+ 32 - 0
direct/src/interval/cConstraintInterval.cxx

@@ -0,0 +1,32 @@
+// Filename: cConstraintInterval.cxx
+// Created by:  pratt (29Sep06)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "cConstraintInterval.h"
+
+TypeHandle CConstraintInterval::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: CConstraintInterval::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+CConstraintInterval::
+CConstraintInterval(const string &name, double duration) :
+  CInterval(name, duration, true)
+{
+}

+ 58 - 0
direct/src/interval/cConstraintInterval.h

@@ -0,0 +1,58 @@
+// Filename: cConstraintInterval.h
+// Created by:  pratt (29Sep06)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef CCONSTRAINTINTERVAL_H
+#define CCONSTRAINTINTERVAL_H
+
+#include "directbase.h"
+#include "cInterval.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : CConstraintInterval
+// Description : The base class for a family of intervals that
+//               constrain some property to a value over time.
+////////////////////////////////////////////////////////////////////
+class EXPCL_DIRECT CConstraintInterval : public CInterval {
+PUBLISHED:
+ bool bogus_variable;
+
+public:
+  CConstraintInterval(const string &name, double duration);
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    CInterval::init_type();
+    register_type(_type_handle, "CConstraintInterval",
+                  CInterval::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "cConstraintInterval.I"
+
+#endif
+

+ 10 - 0
direct/src/interval/config_interval.cxx

@@ -14,6 +14,11 @@
 
 
 #include "config_interval.h"
 #include "config_interval.h"
 #include "cInterval.h"
 #include "cInterval.h"
+#include "cConstraintInterval.h"
+#include "cConstrainTransformInterval.h"
+#include "cConstrainPosInterval.h"
+#include "cConstrainHprInterval.h"
+#include "cConstrainPosHprInterval.h"
 #include "cLerpInterval.h"
 #include "cLerpInterval.h"
 #include "cLerpNodePathInterval.h"
 #include "cLerpNodePathInterval.h"
 #include "cLerpAnimEffectInterval.h"
 #include "cLerpAnimEffectInterval.h"
@@ -59,6 +64,11 @@ init_libinterval() {
   initialized = true;
   initialized = true;
 
 
   CInterval::init_type();
   CInterval::init_type();
+  CConstraintInterval::init_type();
+  CConstrainTransformInterval::init_type();
+  CConstrainPosInterval::init_type();
+  CConstrainHprInterval::init_type();
+  CConstrainPosHprInterval::init_type();
   CLerpInterval::init_type();
   CLerpInterval::init_type();
   CLerpNodePathInterval::init_type();
   CLerpNodePathInterval::init_type();
   CLerpAnimEffectInterval::init_type();
   CLerpAnimEffectInterval::init_type();

+ 5 - 0
direct/src/interval/interval_composite1.cxx

@@ -1,6 +1,11 @@
 #include "config_interval.cxx"
 #include "config_interval.cxx"
 #include "cInterval.cxx"
 #include "cInterval.cxx"
 #include "cIntervalManager.cxx"
 #include "cIntervalManager.cxx"
+#include "cConstraintInterval.cxx"
+#include "cConstrainTransformInterval.cxx"
+#include "cConstrainPosInterval.cxx"
+#include "cConstrainHprInterval.cxx"
+#include "cConstrainPosHprInterval.cxx"
 #include "cLerpInterval.cxx"
 #include "cLerpInterval.cxx"
 #include "cLerpNodePathInterval.cxx"
 #include "cLerpNodePathInterval.cxx"
 #include "cLerpAnimEffectInterval.cxx"
 #include "cLerpAnimEffectInterval.cxx"