private ICollisionJoint[] GetBridgeConstraints(List <ICollisionShape> shape) { ICollisionJoint[] constraints = new ICollisionJoint[30]; int idx = 0; double zValue = -1.8; double yValue = 1.2; for (int i = 0; i < 10; i++) { constraints[idx] = new BallAndSocketJoint( shape[i], shape[i + 1], new Vector3d(0.5, yValue, zValue), 0.9, 0.00016); idx++; constraints[idx] = new BallAndSocketJoint( shape[i], shape[i + 1], new Vector3d(-0.5, yValue, zValue), 0.9, 0.00016); idx++; constraints[idx] = new AngularJoint( shape[i], shape[i + 1], new Vector3d(-0.5, yValue, zValue), new Vector3d(1.0, 0.0, 0.0), new Vector3d(0.0, 1.0, 0.0), 0.5, 0.008, 0.008); idx++; zValue = -1.25; yValue = 0.0; } return(constraints); }
public ICollisionJoint[] LoadSimulationJoints( ICollisionShape[] objects) { var xmlDoc = new XmlDocument(); xmlDoc.Load(FileNameObjectProperties); XmlNodeList xmlList = xmlDoc.SelectNodes(nodePathJoints); ICollisionJoint[] joints = new ICollisionJoint[xmlList.Count]; for (int i = 0; i < xmlList.Count; i++) { //Object index A int indexA = Convert.ToInt32(xmlList[i][objectIndexAAttribute].InnerText); //Object index B int indexB = Convert.ToInt32(xmlList[i][objectIndexBAttribute].InnerText); XmlNodeList jointPropertiesList = xmlList[i].SelectNodes(jointProperties); ICollisionJoint[] joint = new ICollisionJoint[jointPropertiesList.Count]; for (int j = 0; j < jointPropertiesList.Count; j++) { //Joint type var jointType = (JointType)Convert.ToInt32(jointPropertiesList[j][this.jointType].InnerText); //Restore coefficient double K = Convert.ToDouble(jointPropertiesList[j][restoreCoeffAttribute].InnerText); //Stretch coefficient double C = Convert.ToDouble(jointPropertiesList[j][stretchCoeffAttribute].InnerText); //Position var startAnchorPosition = new Vector3d( Convert.ToDouble(jointPropertiesList[j][positionJointAttribute].Attributes["x"].Value), Convert.ToDouble(jointPropertiesList[j][positionJointAttribute].Attributes["y"].Value), Convert.ToDouble(jointPropertiesList[j][positionJointAttribute].Attributes["z"].Value)); //Action Axis var actionAxis = new Vector3d( Convert.ToDouble(jointPropertiesList[j][this.actionAxis].Attributes["x"].Value), Convert.ToDouble(jointPropertiesList[j][this.actionAxis].Attributes["y"].Value), Convert.ToDouble(jointPropertiesList[j][this.actionAxis].Attributes["z"].Value)); switch (jointType) { case JointType.Fixed: joint [j] = new FixedJoint( objects[indexA], objects[indexB], K, C); break; case JointType.BallAndSocket: joint[j] = new BallAndSocketJoint( objects[indexA], objects[indexB], startAnchorPosition, K, C); break; case JointType.Slider: joint[j] = new SliderJoint( objects[indexA], objects[indexB], startAnchorPosition, actionAxis, K, C); joint[j].SetLinearLimit(Convert.ToDouble(jointPropertiesList[j][linearLimitMin].InnerText), Convert.ToDouble(jointPropertiesList[j][linearLimitMax].InnerText)); break; case JointType.Piston: joint[j] = new PistonJoint( objects[indexA], objects[indexB], startAnchorPosition, actionAxis, K, C); joint[j].SetAxis1AngularLimit( Convert.ToDouble(jointPropertiesList[j][angularLimitMin].InnerText), Convert.ToDouble(jointPropertiesList[j][angularLimitMax].InnerText)); joint[j].SetLinearLimit( Convert.ToDouble(jointPropertiesList[j][linearLimitMin].InnerText), Convert.ToDouble(jointPropertiesList[j][linearLimitMax].InnerText)); break; case JointType.Hinge: joint[j] = new HingeJoint( objects[indexA], objects[indexB], startAnchorPosition, actionAxis, K, C); joint[j].SetAxis1AngularLimit( Convert.ToDouble(jointPropertiesList[j][angularLimitMin].InnerText), Convert.ToDouble(jointPropertiesList[j][angularLimitMax].InnerText)); joint[j].SetAxis1Motor(3.0, 0.15); break; case JointType.Universal: joint[j] = new UniversalJoint( objects[indexA], objects[indexB], startAnchorPosition, actionAxis, new Vector3d(1.0, 0.0, 0.0), K, C); joint[j].SetAxis1AngularLimit( Convert.ToDouble(jointPropertiesList[j][angularLimitMin].InnerText), Convert.ToDouble(jointPropertiesList[j][angularLimitMax].InnerText)); joint[j].SetAxis2AngularLimit( Convert.ToDouble(jointPropertiesList[j][angularLimitMin].InnerText), Convert.ToDouble(jointPropertiesList[j][angularLimitMax].InnerText)); break; case JointType.Hinge2: joint[j] = new Hinge2Joint( objects[indexA], objects[indexB], startAnchorPosition, actionAxis, new Vector3d(1.0, 0.0, 0.0), K, 1.0, C); joint[j].SetAxis1AngularLimit( Convert.ToDouble(jointPropertiesList[j][angularLimitMin].InnerText), Convert.ToDouble(jointPropertiesList[j][angularLimitMax].InnerText)); //joint[j].SetAxis2Motor(4.0, 3.0); break; case JointType.Angular: joint[j] = new AngularJoint( objects[indexA], objects[indexB], startAnchorPosition, new Vector3d(1.0, 0.0, 0.0), new Vector3d(0.0, 1.0, 0.0), 0.16, 0.008, 0.008); break; } joints[i] = joint[j]; } } return(joints); }