瀏覽代碼

More PyODE-like feedback system

rdb 16 年之前
父節點
當前提交
5d5a131026
共有 2 個文件被更改,包括 16 次插入2 次删除
  1. 14 0
      panda/src/ode/odeJoint.I
  2. 2 2
      panda/src/ode/odeJoint.h

+ 14 - 0
panda/src/ode/odeJoint.I

@@ -52,6 +52,20 @@ get_joint_type() const {
   return dJointGetType(_id);
   return dJointGetType(_id);
 }
 }
 
 
+INLINE void OdeJoint::
+set_feedback(bool flag) {
+  if (flag) {
+    if (dJointGetFeedback(_id) != NULL) {
+      return;
+    }
+    OdeJointFeedback* feedback = new OdeJointFeedback;
+    dJointSetFeedback(_id, (dJointFeedback*) feedback);
+  } else if (dJointFeedback* feedback = dJointGetFeedback(_id)) {
+    dJointSetFeedback(_id, NULL);
+    delete feedback;
+  }
+}
+
 INLINE void OdeJoint::
 INLINE void OdeJoint::
 set_feedback(OdeJointFeedback *feedback) {
 set_feedback(OdeJointFeedback *feedback) {
   dJointSetFeedback(_id, feedback);
   dJointSetFeedback(_id, feedback);

+ 2 - 2
panda/src/ode/odeJoint.h

@@ -23,14 +23,13 @@
 #include "odeWorld.h"      // Needed for derived classes
 #include "odeWorld.h"      // Needed for derived classes
 #include "odeJointGroup.h"
 #include "odeJointGroup.h"
 
 
-BEGIN_PUBLISH
 class EXPCL_PANDAODE OdeJointFeedback : public dJointFeedback {
 class EXPCL_PANDAODE OdeJointFeedback : public dJointFeedback {
+PUBLISHED:
   INLINE const LVector3f get_force1() const { return LVector3f(f1[0], f1[1], f1[2]); };
   INLINE const LVector3f get_force1() const { return LVector3f(f1[0], f1[1], f1[2]); };
   INLINE const LVector3f get_force2() const { return LVector3f(f2[0], f2[1], f2[2]); };
   INLINE const LVector3f get_force2() const { return LVector3f(f2[0], f2[1], f2[2]); };
   INLINE const LVector3f get_torque1() const { return LVector3f(t1[0], t1[1], t1[2]); };
   INLINE const LVector3f get_torque1() const { return LVector3f(t1[0], t1[1], t1[2]); };
   INLINE const LVector3f get_torque2() const { return LVector3f(t2[0], t2[1], t2[2]); };
   INLINE const LVector3f get_torque2() const { return LVector3f(t2[0], t2[1], t2[2]); };
 };
 };
-END_PUBLISH
 
 
 // Strange, we should be forced to include this by get_body()
 // Strange, we should be forced to include this by get_body()
 class OdeBody; 
 class OdeBody; 
@@ -85,6 +84,7 @@ PUBLISHED:
   INLINE int get_joint_type() const;
   INLINE int get_joint_type() const;
   OdeBody get_body(int index) const;
   OdeBody get_body(int index) const;
   INLINE void set_feedback(OdeJointFeedback *);
   INLINE void set_feedback(OdeJointFeedback *);
+  INLINE void set_feedback(bool flag = true);
   INLINE OdeJointFeedback *get_feedback();
   INLINE OdeJointFeedback *get_feedback();
    
    
   void attach_bodies(const OdeBody &body1, const OdeBody &body2);
   void attach_bodies(const OdeBody &body1, const OdeBody &body2);