Explorar o código

Added slider constraint.

Lasse Öörni %!s(int64=13) %!d(string=hai) anos
pai
achega
4335295b87
Modificáronse 3 ficheiros con 30 adicións e 3 borrados
  1. 1 1
      Docs/Reference.dox
  2. 27 1
      Engine/Physics/Constraint.cpp
  3. 2 1
      Engine/Physics/Constraint.h

+ 1 - 1
Docs/Reference.dox

@@ -823,7 +823,7 @@ The other physics components are:
 
 
 - RigidBody: a physics object instance. Its parameters include mass, linear/angular velocities, friction and restitution.
 - RigidBody: a physics object instance. Its parameters include mass, linear/angular velocities, friction and restitution.
 - CollisionShape: defines physics collision geometry. The supported shapes are box, sphere, cylinder, capsule, cone, triangle mesh and convex hull.
 - CollisionShape: defines physics collision geometry. The supported shapes are box, sphere, cylinder, capsule, cone, triangle mesh and convex hull.
-- Constraint: connects two RigidBodies together, or one RigidBody to a static point in the world. Currently point and hinge constraints are supported.
+- Constraint: connects two RigidBodies together, or one RigidBody to a static point in the world. Currently point, hinge and slider constraints are supported.
 
 
 Both a RigidBody and at least one CollisionShape component must exist in a scene node for it to behave physically (a collision shape by itself does nothing.) Several collision shapes may exist in the same node to create compound shapes. An offset position and rotation relative to the node's transform can be specified for each. Triangle mesh and convex hull geometries require specifying a Model resource and the LOD level to use.
 Both a RigidBody and at least one CollisionShape component must exist in a scene node for it to behave physically (a collision shape by itself does nothing.) Several collision shapes may exist in the same node to create compound shapes. An offset position and rotation relative to the node's transform can be specified for each. Triangle mesh and convex hull geometries require specifying a Model resource and the LOD level to use.
 
 

+ 27 - 1
Engine/Physics/Constraint.cpp

@@ -34,6 +34,7 @@
 
 
 #include "BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h"
 #include "BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h"
 #include "BulletDynamics/ConstraintSolver/btHingeConstraint.h"
 #include "BulletDynamics/ConstraintSolver/btHingeConstraint.h"
+#include "BulletDynamics/ConstraintSolver/btSliderConstraint.h"
 #include <BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h>
 #include <BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h>
 
 
 #include "DebugNew.h"
 #include "DebugNew.h"
@@ -42,6 +43,7 @@ static const String typeNames[] =
 {
 {
     "Point",
     "Point",
     "Hinge",
     "Hinge",
+    "Slider",
     ""
     ""
 };
 };
 
 
@@ -195,6 +197,11 @@ void Constraint::SetLowLimit(float limit)
             btHingeConstraint* hingeConstraint = static_cast<btHingeConstraint*>(constraint_);
             btHingeConstraint* hingeConstraint = static_cast<btHingeConstraint*>(constraint_);
             hingeConstraint->setLimit(lowLimit_ * M_DEGTORAD, highLimit_ * M_DEGTORAD);
             hingeConstraint->setLimit(lowLimit_ * M_DEGTORAD, highLimit_ * M_DEGTORAD);
         }
         }
+        if (constraint_ && constraint_->getConstraintType() == SLIDER_CONSTRAINT_TYPE)
+        {
+            btSliderConstraint* sliderConstraint = static_cast<btSliderConstraint*>(constraint_);
+            sliderConstraint->setLowerLinLimit(lowLimit_);
+        }
     }
     }
 }
 }
 
 
@@ -209,6 +216,11 @@ void Constraint::SetHighLimit(float limit)
             btHingeConstraint* hingeConstraint = static_cast<btHingeConstraint*>(constraint_);
             btHingeConstraint* hingeConstraint = static_cast<btHingeConstraint*>(constraint_);
             hingeConstraint->setLimit(lowLimit_ * M_DEGTORAD, highLimit_ * M_DEGTORAD);
             hingeConstraint->setLimit(lowLimit_ * M_DEGTORAD, highLimit_ * M_DEGTORAD);
         }
         }
+        if (constraint_ && constraint_->getConstraintType() == SLIDER_CONSTRAINT_TYPE)
+        {
+            btSliderConstraint* sliderConstraint = static_cast<btSliderConstraint*>(constraint_);
+            sliderConstraint->setUpperLinLimit(highLimit_);
+        }
     }
     }
 }
 }
 
 
@@ -295,16 +307,30 @@ void Constraint::CreateConstraint()
         
         
     case CONSTRAINT_HINGE:
     case CONSTRAINT_HINGE:
         {
         {
-            btHingeConstraint* hingeConstraint;
             Quaternion ownRotation(Vector3::FORWARD, axis_);
             Quaternion ownRotation(Vector3::FORWARD, axis_);
             Quaternion otherRotation(Vector3::FORWARD, otherBodyAxis_);
             Quaternion otherRotation(Vector3::FORWARD, otherBodyAxis_);
             btTransform ownFrame(ToBtQuaternion(ownRotation), ToBtVector3(position_ * cachedWorldScale_));
             btTransform ownFrame(ToBtQuaternion(ownRotation), ToBtVector3(position_ * cachedWorldScale_));
             btTransform otherFrame(ToBtQuaternion(otherRotation), ToBtVector3(otherBodyPosition_));
             btTransform otherFrame(ToBtQuaternion(otherRotation), ToBtVector3(otherBodyPosition_));
             
             
+            btHingeConstraint* hingeConstraint;
             constraint_ = hingeConstraint = new btHingeConstraint(*ownBody, *otherBody, ownFrame, otherFrame);
             constraint_ = hingeConstraint = new btHingeConstraint(*ownBody, *otherBody, ownFrame, otherFrame);
             hingeConstraint->setLimit(lowLimit_ * M_DEGTORAD, highLimit_ * M_DEGTORAD);
             hingeConstraint->setLimit(lowLimit_ * M_DEGTORAD, highLimit_ * M_DEGTORAD);
         }
         }
         break;
         break;
+        
+    case CONSTRAINT_SLIDER:
+        {
+            Quaternion ownRotation(Vector3::RIGHT, axis_);
+            Quaternion otherRotation(Vector3::RIGHT, otherBodyAxis_);
+            btTransform ownFrame(ToBtQuaternion(ownRotation), ToBtVector3(position_ * cachedWorldScale_));
+            btTransform otherFrame(ToBtQuaternion(otherRotation), ToBtVector3(otherBodyPosition_));
+            
+            btSliderConstraint* sliderConstraint;
+            constraint_ = sliderConstraint = new btSliderConstraint(*ownBody, *otherBody, ownFrame, otherFrame, false);
+            sliderConstraint->setLowerLinLimit(lowLimit_);
+            sliderConstraint->setUpperLinLimit(highLimit_);
+        }
+        break;
     }
     }
     
     
     constraint_->setUserConstraintPtr(this);
     constraint_->setUserConstraintPtr(this);

+ 2 - 1
Engine/Physics/Constraint.h

@@ -30,7 +30,8 @@
 enum ConstraintType
 enum ConstraintType
 {
 {
     CONSTRAINT_POINT = 0,
     CONSTRAINT_POINT = 0,
-    CONSTRAINT_HINGE
+    CONSTRAINT_HINGE,
+    CONSTRAINT_SLIDER
 };
 };
 
 
 class PhysicsWorld;
 class PhysicsWorld;