/// <summary> /// Builds and spawns the body into the world. /// </summary> public virtual void SpawnBody() { if (Body != null) { DestroyBody(); } Body = new BEPUphysics.Entities.Entity(Shape, Mass); Body.CollisionInformation.CollisionRules.Group = CGroup; InternalOffset = new Location(Body.Position); Body.AngularVelocity = new Vector3((double)AVel.X, (double)AVel.Y, (double)AVel.Z); Body.LinearVelocity = new Vector3((double)LVel.X, (double)LVel.Y, (double)LVel.Z); Body.WorldTransform = WorldTransform; // TODO: Position, Orientation Body.Tag = this; Body.PositionUpdateMode = BEPUphysics.PositionUpdating.PositionUpdateMode.Passive; if (!CanRotate) { Body.AngularDamping = 1; } // TODO: Other settings // TODO: Gravity SetFriction(Friction); SetBounciness(Bounciness); TheRegion.PhysicsWorld.Add(Body); for (int i = 0; i < Joints.Count; i++) { if (Joints[i] is BaseJoint) { BaseJoint joint = (BaseJoint)Joints[i]; joint.CurrentJoint = joint.GetBaseJoint(); TheRegion.PhysicsWorld.Add(joint.CurrentJoint); } } }
public void AddJoint(InternalBaseJoint joint) { Joints.Add(joint); joint.One.Joints.Add(joint); joint.Two.Joints.Add(joint); joint.Enable(); if (joint is BaseJoint) { BaseJoint pjoint = (BaseJoint)joint; pjoint.CurrentJoint = pjoint.GetBaseJoint(); PhysicsWorld.Add(pjoint.CurrentJoint); } }
public void AddJoint(InternalBaseJoint joint) { Joints.Add(joint); joint.One.Joints.Add(joint); joint.Two.Joints.Add(joint); joint.JID = jID++; joint.Enable(); if (joint is BaseJoint) { BaseJoint pjoint = (BaseJoint)joint; pjoint.CurrentJoint = pjoint.GetBaseJoint(); PhysicsWorld.Add(pjoint.CurrentJoint); } SendToAll(new AddJointPacketOut(joint)); }
public void DestroyJoint(InternalBaseJoint joint) { if (!Joints.Remove(joint)) { SysConsole.Output(OutputType.WARNING, "Destroyed non-existent joint?!"); } joint.One.Joints.Remove(joint); joint.Two.Joints.Remove(joint); joint.Disable(); if (joint is BaseJoint) { BaseJoint pjoint = (BaseJoint)joint; PhysicsWorld.Remove(pjoint.CurrentJoint); } }
/// <summary> /// Destroys the body, removing it from the physics world. /// </summary> public virtual void DestroyBody() { LVel = new Location(Body.LinearVelocity); AVel = new Location(Body.AngularVelocity); Friction = GetFriction(); // TODO: Gravity = new Location(Body.Gravity.X, Body.Gravity.Y, Body.Gravity.Z); WorldTransform = Body.WorldTransform; for (int i = 0; i < Joints.Count; i++) { if (Joints[i] is BaseJoint) { BaseJoint joint = (BaseJoint)Joints[i]; TheRegion.PhysicsWorld.Remove(joint.CurrentJoint); } } TheRegion.PhysicsWorld.Remove(Body); Body = null; }
/// <summary> /// Destroys the body, removing it from the physics world. /// </summary> public virtual void DestroyBody() { if (Seats != null) { foreach (Seat seat in Seats) { if (seat.Sitter != null) { seat.Kick(); } } } LVel = new Location(Body.LinearVelocity.X, Body.LinearVelocity.Y, Body.LinearVelocity.Z); AVel = new Location(Body.AngularVelocity.X, Body.AngularVelocity.Y, Body.AngularVelocity.Z); Friction = GetFriction(); // TODO: Gravity = new Location(Body.Gravity.X, Body.Gravity.Y, Body.Gravity.Z); WorldTransform = Body.WorldTransform; for (int i = 0; i < Joints.Count; i++) { if (Joints[i] is BaseJoint) { BaseJoint joint = (BaseJoint)Joints[i]; try { TheRegion.PhysicsWorld.Remove(joint.CurrentJoint); } catch (Exception ex) { // We don't actually care if this errors. Utilities.CheckException(ex); } } } TheRegion.PhysicsWorld.Remove(Body); Body = null; }
public void DestroyJoint(InternalBaseJoint joint) { Joints.Remove(joint); joint.One.Joints.Remove(joint); joint.Two.Joints.Remove(joint); joint.Disable(); if (joint is BaseJoint) { BaseJoint pjoint = (BaseJoint)joint; if (pjoint.CurrentJoint != null) { try { PhysicsWorld.Remove(pjoint.CurrentJoint); } catch (Exception ex) { // We don't really care... Utilities.CheckException(ex); } } } SendToAll(new DestroyJointPacketOut(joint)); }