void BuildStick(Vector3 position, int linkCount, out List<Bone> bones, out List<Entity> boneEntities) { //Set up a bone chain. bones = new List<Bone>(); boneEntities = new List<Entity>(); var previousBoneEntity = new Cylinder(position, 1, .2f); var previousBone = new Bone(previousBoneEntity.Position, previousBoneEntity.Orientation, previousBoneEntity.Radius, previousBoneEntity.Height); bones.Add(previousBone); boneEntities.Add(previousBoneEntity); for (int i = 1; i < linkCount; i++) { var boneEntity = new Cylinder(previousBone.Position + new Vector3(0, 1, 0), 1, .2f); var bone = new Bone(boneEntity.Position, boneEntity.Orientation, boneEntity.Radius, boneEntity.Height); bones.Add(bone); boneEntities.Add(boneEntity); //Make a relationship between the two bones and entities. CollisionRules.AddRule(previousBoneEntity, boneEntity, CollisionRule.NoBroadPhase); Vector3 anchor = (previousBoneEntity.Position + boneEntity.Position) / 2; //var dynamicsBallSocketJoint = new BallSocketJoint(previousBoneEntity, boneEntity, anchor); //var dynamicsAngularFriction = new NoRotationJoint(previousBoneEntity, boneEntity); //Space.Add(dynamicsBallSocketJoint); //Space.Add(dynamicsAngularFriction); var ballSocket = new IKBallSocketJoint(previousBone, bone, anchor); var angularJoint = new IKAngularJoint(previousBone, bone); previousBone = bone; previousBoneEntity = boneEntity; } }
void BuildChain(Vector3 position) { //Set up a bone chain. int linkCount = 100; var previousBoneEntity = new Cylinder(position, 1, .2f, 10); var previousBone = new Bone(previousBoneEntity.Position, previousBoneEntity.Orientation, previousBoneEntity.Radius, previousBoneEntity.Height); bones.Add(new BoneRelationship(previousBone, previousBoneEntity)); Space.Add(previousBoneEntity); for (int i = 1; i < linkCount; i++) { var boneEntity = new Cylinder(previousBone.Position + new Vector3(0, 1, 0), 1, .2f, 10); var bone = new Bone(boneEntity.Position, boneEntity.Orientation, boneEntity.Radius, boneEntity.Height); bones.Add(new BoneRelationship(bone, boneEntity)); Space.Add(boneEntity); //Make a relationship between the two bones and entities. CollisionRules.AddRule(previousBoneEntity, boneEntity, CollisionRule.NoBroadPhase); Vector3 anchor = (previousBoneEntity.Position + boneEntity.Position) / 2; var dynamicsBallSocketJoint = new BallSocketJoint(previousBoneEntity, boneEntity, anchor); var dynamicsAngularFriction = new AngularMotor(previousBoneEntity, boneEntity); dynamicsAngularFriction.Settings.Mode = MotorMode.VelocityMotor; dynamicsAngularFriction.Settings.MaximumForce = 200; Space.Add(dynamicsBallSocketJoint); Space.Add(dynamicsAngularFriction); var ikBallSocketJoint = new IKBallSocketJoint(previousBone, bone, anchor); //(the joint is auto-added to the bones; no solver-add is needed) joints.Add(ikBallSocketJoint); previousBone = bone; previousBoneEntity = boneEntity; } }
void BuildStick(Vector3 position) { //Set up a bone chain. float fullLength = 20; int linkCount = 20; float linkLength = fullLength / linkCount; float linkRadius = linkLength * 0.2f; var previousBoneEntity = new Cylinder(position, linkLength, linkRadius, 100); var previousBone = new Bone(previousBoneEntity.Position, previousBoneEntity.Orientation, previousBoneEntity.Radius, previousBoneEntity.Height); bones.Add(new BoneRelationship(previousBone, previousBoneEntity)); Space.Add(previousBoneEntity); for (int i = 1; i < linkCount; i++) { var boneEntity = new Cylinder(previousBone.Position + new Vector3(0, linkLength, 0), linkLength, linkRadius, 100); var bone = new Bone(boneEntity.Position, boneEntity.Orientation, boneEntity.Radius, boneEntity.Height); bones.Add(new BoneRelationship(bone, boneEntity)); Space.Add(boneEntity); //Make a relationship between the two bones and entities. CollisionRules.AddRule(previousBoneEntity, boneEntity, CollisionRule.NoBroadPhase); Vector3 anchor = (previousBoneEntity.Position + boneEntity.Position) / 2; var dynamicsBallSocketJoint = new BallSocketJoint(previousBoneEntity, boneEntity, anchor); var dynamicsAngularFriction = new NoRotationJoint(previousBoneEntity, boneEntity); Space.Add(dynamicsBallSocketJoint); Space.Add(dynamicsAngularFriction); var ikBallSocketJoint = new IKBallSocketJoint(previousBone, bone, anchor); //(the joint is auto-added to the bones; no solver-add is needed) var ikAngularJoint = new IKAngularJoint(previousBone, bone); joints.Add(ikBallSocketJoint); joints.Add(ikAngularJoint); previousBone = bone; previousBoneEntity = boneEntity; } }