Explorar o código

DynamicJoint: add lock axis

lviguier hai 6 meses
pai
achega
55a7a87969
Modificáronse 3 ficheiros con 26 adicións e 1 borrados
  1. 1 0
      h3d/anim/Skin.hx
  2. 10 1
      h3d/prim/ModelDatabase.hx
  3. 15 0
      h3d/scene/Skin.hx

+ 1 - 0
h3d/anim/Skin.hx

@@ -46,6 +46,7 @@ class DynamicJoint extends Joint {
 
 	// Parameters
 	public var additive : Bool = false;
+	public var lockAxis : h3d.Vector = new Vector(0, 0, 0);
 	public var damping : Float = 1;
 	public var stiffness : Float = 1;
 	public var resistance : Float = 1;

+ 10 - 1
h3d/prim/ModelDatabase.hx

@@ -159,6 +159,7 @@ class ModelDatabase {
 			newJ.slackness = jConf.slackness;
 			newJ.stiffness = jConf.stiffness;
 			newJ.additive = jConf.additive;
+			newJ.lockAxis = jConf.lockAxis == null ? new Vector(0, 0, 0): new Vector(jConf.lockAxis?.x, jConf.lockAxis?.y, jConf.lockAxis?.z);
 			newJ.globalForce = new Vector(jConf.globalForce.x, jConf.globalForce.y, jConf.globalForce.z);
 			skinData.allJoints[j.index] = newJ;
 
@@ -213,7 +214,15 @@ class ModelDatabase {
 			if (dynJ == null)
 				continue;
 
-			dynamicJoints.push({ name: dynJ.name, slackness: dynJ.slackness, stiffness: dynJ.stiffness, resistance: dynJ.resistance, damping: dynJ.damping, additive: dynJ.additive, globalForce: dynJ.globalForce });
+			dynamicJoints.push({
+				name: dynJ.name,
+				slackness: dynJ.slackness,
+				stiffness: dynJ.stiffness,
+				resistance: dynJ.resistance,
+				damping: dynJ.damping,
+				additive: dynJ.additive,
+				globalForce: dynJ.globalForce,
+				lockAxis: dynJ.lockAxis });
 		}
 
 		if (dynamicJoints.length == 0) {

+ 15 - 0
h3d/scene/Skin.hx

@@ -195,6 +195,21 @@ class DynamicJointData extends JointData {
 		expectedPos.load(skin.jointsData[j.parent.index].currentAbsPose.getPosition() + dirToParent * lengthToParent);
 		newWorldPos.lerp(expectedPos, newWorldPos, j.slackness);
 
+		// Apply lock axis
+		skin.jointsData[j.parent.index].currentAbsPose.getInverse(Skin.TMP_MAT);
+		tmpVec.load(newWorldPos);
+		tmpVec.transform(Skin.TMP_MAT);
+		tmpVec2.load(jData.currentAbsPose.getPosition());
+		tmpVec2.transform(Skin.TMP_MAT);
+		if (j.lockAxis.x > 0.0)
+			tmpVec.x = tmpVec2.x;
+		if (j.lockAxis.y > 0.0)
+			tmpVec.y = tmpVec2.y;
+		if (j.lockAxis.z > 0.0)
+			tmpVec.z = tmpVec2.z;
+		tmpVec.transform(skin.jointsData[j.parent.index].currentAbsPose);
+		newWorldPos.load(tmpVec);
+
 		// Apply computed position to joint
 		jData.speed.load((jData.speed + (newWorldPos - absPos.getPosition()) * (1.0 / hxd.Timer.dt)) * 0.5);
 		jData.currentAbsPose.setPosition(newWorldPos);