private static void AttachWeapon_HookupNew(MapObjectTransferArgs args, ref JointBase weaponAttachJoint, ref Weapon weapon, Weapon newWeapon) { weapon = newWeapon; if (weapon != null) { Point3D position = args.Bot.PositionWorld; // Move the weapon into position weapon.MoveToAttachPoint(position); JointBallAndSocket ballAndSocket = JointBallAndSocket.CreateBallAndSocket(args.World, position, args.Bot.PhysicsBody, weapon.PhysicsBody); ballAndSocket.ShouldLinkedBodiesCollideEachOther = false; weaponAttachJoint = ballAndSocket; weapon.Gravity = args.Gravity; } }
private void addJoined1_AddJoint(object sender, AddJoinedBodiesArgs e) { try { // Figure out the centerpoint Point3D centerPoint = Math3D.GetRandomVector_Spherical(CREATEOBJECTBOUNDRY).ToPoint(); // Get a random rotation //TODO: Figure out why it fails when I give it a rotation //Quaternion finalRotation = new Quaternion(Math3D.GetRandomVectorSpherical(_rand, 10), Math3D.GetNearZeroValue(_rand, 360d)); Quaternion finalRotation = new Quaternion(new Vector3D(0, 0, 1), 0); // All bodies will be the same color Color color = UtilityWPF.GetRandomColor(64, 192); Body[] bodies = null; #region Get Bodies switch (e.JointType) { case AddJointType.BallAndSocket: case AddJointType.Hinge: case AddJointType.Slider: case AddJointType.Corkscrew: case AddJointType.UniversalJoint: bodies = new Body[2]; GetJointBodyPair(out bodies[0], out bodies[1], e.Body1Type, e.Body2Type, centerPoint, finalRotation, e.SeparationDistance, color); break; case AddJointType.UpVector: case AddJointType.Multi_BallAndChain: case AddJointType.Multi_Tetrahedron: MessageBox.Show("finish this"); return; default: throw new ApplicationException("Unknown AddJointType: " + e.JointType.ToString()); } #endregion _bodySets.Add(bodies); #region Setup Joint Vector3D directionAlong = finalRotation.GetRotatedVector(new Vector3D(1, 0, 0)); Vector3D directionOrth1 = finalRotation.GetRotatedVector(new Vector3D(0, 1, 0)); Vector3D directionOrth2 = finalRotation.GetRotatedVector(new Vector3D(0, 0, 1)); switch (e.JointType) { case AddJointType.BallAndSocket: #region BallAndSocket JointBallAndSocket ballAndSocket = JointBallAndSocket.CreateBallAndSocket(_world, centerPoint, bodies[0], bodies[1]); ballAndSocket.ShouldLinkedBodiesCollideEachOther = true; //TODO: Let the user define these limits //ballAndSocket.SetConeLimits(); #endregion break; case AddJointType.Hinge: #region Hinge JointHinge hinge = JointHinge.CreateHinge(_world, centerPoint, directionOrth1, bodies[0], bodies[1]); hinge.ShouldLinkedBodiesCollideEachOther = true; #endregion break; case AddJointType.Slider: #region Slider JointSlider slider = JointSlider.CreateSlider(_world, centerPoint, directionAlong, bodies[0], bodies[1]); slider.ShouldLinkedBodiesCollideEachOther = true; #endregion break; case AddJointType.Corkscrew: #region Corkscrew JointCorkscrew corkscrew = JointCorkscrew.CreateCorkscrew(_world, centerPoint, directionAlong, bodies[0], bodies[1]); corkscrew.ShouldLinkedBodiesCollideEachOther = true; #endregion break; case AddJointType.UniversalJoint: #region UniversalJoint JointUniversal uJoint = JointUniversal.CreateUniversal(_world, centerPoint, directionOrth1, directionOrth2, bodies[0], bodies[1]); uJoint.ShouldLinkedBodiesCollideEachOther = true; #endregion break; default: throw new ApplicationException("Unexpected AddJointType: " + e.JointType.ToString()); } #endregion BodiesAdded(bodies); } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }