public BEPUphysics.ISpaceObject CreateCollision(JMapObjectData block) { BEPUphysics.ISpaceObject collision = null; if (block.colliderTypes == 0) { BEPUphysics.EntityStateManagement.MotionState ms = new BEPUphysics.EntityStateManagement.MotionState(); ms.Position = new BEPUutilities.Vector3(block.mapPos.x, block.mapPos.y, block.mapPos.z); ms.Orientation = new BEPUutilities.Quaternion(block.mapRot.x, block.mapRot.y, block.mapRot.z, block.mapRot.w); collision = new Box(ms, block.mapScale.x, 1f, block.mapScale.y); } else { var vertices = new BEPUutilities.Vector3[block.meshColliderVertices.Length]; int[] indices = new int[block.meshColliderIndices.Length]; for (int i = 0; i < vertices.Length; ++i) { vertices[i] = new BEPUutilities.Vector3(block.meshColliderVertices[i].x, block.meshColliderVertices[i].y, block.meshColliderVertices[i].z); } for (int i = 0; i < indices.Length; ++i) { indices[i] = block.meshColliderIndices[i]; } var Position = new BEPUutilities.Vector3(block.mapPos.x, block.mapPos.y, block.mapPos.z); var Orientation = new BEPUutilities.Quaternion(block.mapRot.x, block.mapRot.y, block.mapRot.z, block.mapRot.w); var staticMesh = new BEPUphysics.BroadPhaseEntries.StaticMesh(vertices, indices, new BEPUutilities.AffineTransform(new BEPUutilities.Vector3(0.1f, 0.1f, 0.1f), Orientation, Position)); //staticMesh.Sidedness = BEPUutilities.TriangleSidedness.DoubleSided; collision = staticMesh; } space.Add(collision); return(collision); }
public override bool ParseBytesAndExecute(byte[] data) { if (data.Length != 24 + 24 + 16 + 24 + 8) { return(false); } Location pos = Location.FromDoubleBytes(data, 0); Location vel = Location.FromDoubleBytes(data, 24); BEPUutilities.Quaternion ang = Utilities.BytesToQuaternion(data, 24 + 24); Location grav = Location.FromDoubleBytes(data, 24 + 24 + 16); long eID = Utilities.BytesToLong(Utilities.BytesPartial(data, 24 + 24 + 16 + 24, 8)); for (int i = 0; i < TheClient.TheRegion.Entities.Count; i++) { if (TheClient.TheRegion.Entities[i] is PrimitiveEntity e) { if (e.EID == eID) { e.SetPosition(pos); e.SetVelocity(vel); e.Angles = ang; e.Gravity = grav; return(true); } } } TheClient.Network.SendPacket(new PleaseRedefinePacketOut(eID)); return(true); }
public static void Convert(ref BEPUutilities.Quaternion bepuQuaternion, out Quaternion quaternion) { quaternion.X = bepuQuaternion.X; quaternion.Y = bepuQuaternion.Y; quaternion.Z = bepuQuaternion.Z; quaternion.W = bepuQuaternion.W; }
public override void Update() { //Update propertis if (entity.Mass != Mass) { entity.Mass = Mass; } if (entity.LinearDamping != Drag) { entity.LinearDamping = Drag; } if (Mass > 0) { //Dynamic Parent.Transform.localPosition = Physics.VectorB2T(entity.Position); Parent.Transform.localRotation = Physics.QuaternionB2T(entity.Orientation); entity.Gravity = Physics.VectorT2B(Physics.Gravity); } else { //Kinematic BEPUutilities.Vector3 transformPosition = Physics.VectorT2B(Parent.Transform.Position); BEPUutilities.Quaternion transformOrientation = Physics.QuaternionT2B(Parent.Transform.Rotation); if (transformPosition != entity.Position) { entity.Position = transformPosition; } if (transformOrientation != entity.Orientation) { entity.Orientation = transformOrientation; } } base.Update(); }
public static void Convert(ref Quaternion quaternion, out BEPUutilities.Quaternion bepuQuaternion) { bepuQuaternion.X = quaternion.X; bepuQuaternion.Y = quaternion.Y; bepuQuaternion.Z = quaternion.Z; bepuQuaternion.W = quaternion.W; }
public void UpdateTransforms(ModelNode pNode, Matrix4 transf) { string nodename = pNode.Name; Matrix4 nodeTransf = Matrix4.Identity; double time; SingleAnimationNode pNodeAnim = FindNodeAnim(nodename, pNode.Mode, out time); if (pNodeAnim != null) { BEPUutilities.Vector3 vec = pNodeAnim.lerpPos(time); BEPUutilities.Quaternion quat = pNodeAnim.lerpRotate(time); OpenTK.Quaternion oquat = new OpenTK.Quaternion(quat.X, quat.Y, quat.Z, quat.W); Matrix4 trans; Matrix4.CreateTranslation(vec.X, vec.Y, vec.Z, out trans); trans.Transpose(); Matrix4 rot; Matrix4.CreateFromQuaternion(ref oquat, out rot); rot.Transpose(); Matrix4.Mult(ref trans, ref rot, out nodeTransf); } Matrix4 global; Matrix4.Mult(ref transf, ref nodeTransf, out global); for (int i = 0; i < pNode.Bones.Count; i++) { //Matrix4 modded; //Matrix4.Mult(ref globalInverse, ref global, out modded); Matrix4.Mult(ref global, ref pNode.Bones[i].Offset, out pNode.Bones[i].Transform); } for (int i = 0; i < pNode.Children.Count; i++) { UpdateTransforms(pNode.Children[i], global); } }
/// <summary> /// Gets the forward vector of this controller. /// </summary> /// <returns></returns> public Location ForwardVector() { OpenTK.Quaternion loquat = Position.ExtractRotation(true); BEPUutilities.Quaternion lquat = new BEPUutilities.Quaternion(loquat.X, loquat.Y, loquat.Z, loquat.W); BEPUutilities.Vector3 lforw = -BEPUutilities.Quaternion.Transform(BEPUutilities.Vector3.UnitZ, lquat); return(new Location(lforw)); }
public static Quaternion Convert(BEPUutilities.Quaternion quaternion) { Quaternion toReturn; toReturn.X = quaternion.X; toReturn.Y = quaternion.Y; toReturn.Z = quaternion.Z; toReturn.W = quaternion.W; return(toReturn); }
public override bool ParseBytesAndExecute(byte[] data) { if (data.Length != 24 + 24 + 16 + 24 + 1 + 8) { SysConsole.Output(OutputType.WARNING, "Invalid physentupdtpacket: invalid length!"); return(false); } Location pos = Location.FromDoubleBytes(data, 0); Location vel = Location.FromDoubleBytes(data, 24); BEPUutilities.Quaternion ang = Utilities.BytesToQuaternion(data, 24 + 24); Location angvel = Location.FromDoubleBytes(data, 24 + 24 + 16); bool active = (data[24 + 24 + 16 + 24] & 1) == 1; long eID = Utilities.BytesToLong(Utilities.BytesPartial(data, 24 + 24 + 16 + 24 + 1, 8)); for (int i = 0; i < TheClient.TheRegion.Entities.Count; i++) { if (TheClient.TheRegion.Entities[i] is PhysicsEntity) { PhysicsEntity e = (PhysicsEntity)TheClient.TheRegion.Entities[i]; if (e.EID == eID) { if (e is ModelEntity && ((ModelEntity)e).PlanePilot == TheClient.Player) { float lerp = TheClient.CVars.n_ourvehiclelerp.ValueF; e.SetPosition(e.GetPosition() + (pos - e.GetPosition()) * lerp); e.SetVelocity(e.GetVelocity() + (vel - e.GetVelocity()) * lerp); e.SetAngularVelocity(e.GetAngularVelocity() + (angvel - e.GetAngularVelocity()) * lerp); e.SetOrientation(BEPUutilities.Quaternion.Slerp(e.GetOrientation(), ang, lerp)); } else { e.SetPosition(pos); e.SetVelocity(vel); e.SetOrientation(ang); e.SetAngularVelocity(angvel); } if (e.Body != null && e.Body.ActivityInformation != null && e.Body.ActivityInformation.IsActive && !active) // TODO: Why are the first two checks needed? { if (e.Body.ActivityInformation.SimulationIsland != null) // TODO: Why is this needed? { e.Body.ActivityInformation.SimulationIsland.IsActive = false; } } else if (e.Body != null && e.Body.ActivityInformation != null && !e.Body.ActivityInformation.IsActive && active) // TODO: Why are the first two checks needed? { e.Body.ActivityInformation.Activate(); } return(true); } } } TheClient.Network.SendPacket(new PleaseRedefinePacketOut(eID)); return(true); }
public void UpdateTransforms(ModelNode pNode, Matrix4 transf) { string nodename = pNode.Name; Matrix4 nodeTransf = Matrix4.Identity; double time; SingleAnimationNode pNodeAnim = FindNodeAnim(nodename, pNode.Mode, out time); if (pNodeAnim != null) { BEPUutilities.Vector3 vec = pNodeAnim.lerpPos(time); BEPUutilities.Quaternion quat = pNodeAnim.lerpRotate(time); Quaternion oquat = new Quaternion((float)quat.X, (float)quat.Y, (float)quat.Z, (float)quat.W); Matrix4 trans; Matrix4.CreateTranslation((float)vec.X, (float)vec.Y, (float)vec.Z, out trans); trans.Transpose(); Matrix4 rot; Matrix4.CreateFromQuaternion(ref oquat, out rot); Matrix4 r2; if (CustomAnimationAdjustments.TryGetValue(nodename, out r2)) { rot *= r2; } rot.Transpose(); Matrix4.Mult(ref trans, ref rot, out nodeTransf); } else { Matrix4 temp; if (CustomAnimationAdjustments.TryGetValue(nodename, out temp)) { temp.Transpose(); nodeTransf = temp; } } Matrix4 global; Matrix4.Mult(ref transf, ref nodeTransf, out global); for (int i = 0; i < pNode.Bones.Count; i++) { if (ForceBoneNoOffset) { pNode.Bones[i].Transform = global; } else { Matrix4.Mult(ref global, ref pNode.Bones[i].Offset, out pNode.Bones[i].Transform); } } for (int i = 0; i < pNode.Children.Count; i++) { UpdateTransforms(pNode.Children[i], global); } }
public override void Fire() { const float ATTACK_RADIUS = 3.0f; const float ATTACK_LENGTH = 4.0f; // Play 'thwack' sound Actor owner = GameResources.ActorManager.GetActorById(OwnerActorId); BipedControllerComponent bipedControl = owner.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control); RigidTransform alignCapsule = new RigidTransform(BepuVec3.Forward * ATTACK_LENGTH * 0.5f + BepuConverter.Convert(MuzzleOffset), BepuQuaternion.CreateFromAxisAngle(BepuVec3.Right, MathHelper.PiOver2)); Vector3 aim = (bipedControl.WorldAim.HasValue ? bipedControl.WorldAim.Value : BepuConverter.Convert(bipedControl.Controller.ViewDirection)); RigidTransform positionAndAim = new RigidTransform(bipedControl.Controller.Body.Position, BepuConverter.Convert( SpaceUtils.GetOrientation(aim, Vector3.Up))); RigidTransform attackTransform; RigidTransform.Transform(ref alignCapsule, ref positionAndAim, out attackTransform); ConvexShape bashShape = new CapsuleShape(ATTACK_LENGTH, ATTACK_RADIUS); BepuVec3 noSweep = BepuVec3.Zero; List <RayCastResult> dudesBashed = new List <RayCastResult>(); AttackFilter filter = new AttackFilter(GameResources.ActorManager.IsMob(OwnerActorId)); GameResources.ActorManager.SimSpace.ConvexCast(bashShape, ref attackTransform, ref noSweep, filter.Test, dudesBashed); foreach (RayCastResult dude in dudesBashed) { EntityCollidable otherEntityCollidable = dude.HitObject as EntityCollidable; Terrain otherTerrain = dude.HitObject as Terrain; if (otherEntityCollidable != null && otherEntityCollidable.Entity != null && otherEntityCollidable.Entity.Tag != null) { Actor actorHit = GameResources.ActorManager.GetActorById((int)(otherEntityCollidable.Entity.Tag)); IDamagable damage = actorHit.GetBehaviorThatImplementsType <IDamagable>(); if (damage != null) { damage.TakeDamage(Damage); // TODO: P2: Query hit actor for appropiate damage effect e.g. blood and create it; } BashDust(dude.HitData.Location); } else if (otherTerrain != null) { BashDust(dude.HitData.Location); } } }
private void TurnToDesiredHeading() { //get current heading var heading = player.GetHeading(); Vector2 desiredForward = MonoMathHelper.GetVectorFromHeading(MathHelper.ToRadians(player.DesiredHeading - 360)); var lookMatrix = Matrix.CreateWorld(ParentObject.Transform.AbsoluteTransform.Translation, new Vector3(desiredForward.X, 0, desiredForward.Y), Vector3.Up); var bepuMatrix = MonoMathHelper.GenerateBepuMatrixFromMono(lookMatrix); BEPUutilities.Quaternion desiredRot = BEPUutilities.Quaternion.CreateFromRotationMatrix(bepuMatrix); rotator.TargetOrientation = desiredRot; }
public virtual bool ApplyVar(string var, string value) { switch (var) { case "position": Position = Location.FromString(value); return(true); case "angle": Angle = Utilities.StringToQuat(value); return(true); case "velocity": Velocity = Location.FromString(value); return(true); case "angular_velocity": Angular_Velocity = Location.FromString(value); return(true); case "mass": Mass = Utilities.StringToFloat(value); return(true); case "friction": Friction = Utilities.StringToFloat(value); return(true); case "bounciness": Bounciness = Utilities.StringToFloat(value); return(true); case "solid": Solid = value.ToLower() == "true"; return(true); case "visible": Visible = value.ToLower() == "true"; return(true); case "jointtargetid": JointTargetID = value; return(true); default: return(false); } }
public void Update(GameTime gameTime) { if (e.DesiredPosiiton != e.Transform.AbsoluteTransform.Translation) { mover.TargetPosition = e.DesiredPosiiton.ToBepuVector(); Vector3 newForward = e.DesiredPosiiton - e.Transform.AbsoluteTransform.Translation; newForward.Normalize(); Vector3 newRight = Vector3.Cross(newForward, Vector3.Up); Vector3 newUp = Vector3.Cross(newRight, newForward); var lookMatrix = Matrix.CreateWorld(ParentObject.Transform.AbsoluteTransform.Translation, newForward, newUp); var bepuMatrix = MonoMathHelper.GenerateBepuMatrixFromMono(lookMatrix); BEPUutilities.Quaternion desiredRot = BEPUutilities.Quaternion.CreateFromRotationMatrix(bepuMatrix); rotator.TargetOrientation = desiredRot; } }
public override BsonDocument GetSaveData() { BsonDocument doc = new BsonDocument(); byte[] pos = Position.ToDoubleBytes(); doc["prim_pos"] = pos; doc["prim_vel"] = Velocity.ToDoubleBytes(); doc["prim_scale"] = Scale.ToDoubleBytes(); doc["prim_grav"] = Gravity.ToDoubleBytes(); BEPUutilities.Quaternion quat = GetOrientation(); doc["prim_ang_x"] = (double)quat.X; doc["prim_ang_y"] = (double)quat.Y; doc["prim_ang_z"] = (double)quat.Z; doc["prim_ang_w"] = (double)quat.W; BsonArray b = new BsonArray(); foreach (long l in NoCollide) { b.Add(l); } doc["prim_noco"] = b; return(doc); }
public static Quaternion ToSharp(this BEPUutilities.Quaternion q) { return(new Quaternion(q.X, q.Y, q.Z, q.W)); }
public override void SetOrientation(BEPUutilities.Quaternion quat) { Angles = quat; }
/// <summary> /// Converts a BEPU quaternion to an OpenTK quaternion. /// </summary> /// <param name="q">The BEPU quaternion.</param> /// <returns>The OpenTK quaternion.</returns> public static OpenTK.Quaternion ToOpenTK(this BEPUutilities.Quaternion q) { return(new OpenTK.Quaternion((float)q.X, (float)q.Y, (float)q.Z, (float)q.W)); }
public static string QuatToString(BEPUutilities.Quaternion quat) { return("(" + quat.X + ", " + quat.Y + ", " + quat.Z + ", " + quat.W + ")"); }
private void SetupVehicle() { float width = 2.5f; float height = 0.75f; float length = 4.5f; float scale = 1f; var vehicleShape = new ProceduralCuboid(width / 2 * scale, length / 2 * scale, height / 2 * scale); vehicleShape.Translate(new Vector3(0, 0.5f, 0)); vehicleShape.SetColor(Color.Red); vehicleObject = GameObjectFactory.CreateRenderableGameObjectFromShape(vehicleShape, EffectLoader.LoadSM5Effect("flatshaded")); vehicleObject.AddComponent(new ShadowCasterComponent()); SystemCore.GameObjectManager.AddAndInitialiseGameObject(vehicleObject); ProceduralSphere cyl = new ProceduralSphere(10, 10); cyl.Scale(0.375f * scale); //cyl.Transform(Matrix.CreateRotationZ(MathHelper.PiOver2)); wheel1 = GameObjectFactory.CreateRenderableGameObjectFromShape(cyl, EffectLoader.LoadSM5Effect("flatshaded")); SystemCore.GameObjectManager.AddAndInitialiseGameObject(wheel1); var bodies = new List <CompoundShapeEntry> { new CompoundShapeEntry(new BoxShape(width * scale, height * scale, length * scale), new BEPUutilities.Vector3(0, 0, 0), 60), //new CompoundShapeEntry(new BoxShape(2.5f, .3f, 2f), new BEPUutilities.Vector3(0, .75f / 2 + .3f / 2, .5f), 1) }; var body = new CompoundBody(bodies, 61); body.CollisionInformation.LocalPosition = new BEPUutilities.Vector3(0, .5f, 0); body.Position = new BEPUutilities.Vector3(10, 20, 10); testVehicle = new Vehicle(body); BEPUutilities.Quaternion localWheelRotation = BEPUutilities.Quaternion.Identity; BEPUutilities.Matrix wheelGraphicRotation = BEPUutilities.Matrix.Identity; testVehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f * scale, 0.2f * scale, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, BEPUutilities.Vector3.Down, 0.325f, new BEPUutilities.Vector3(-1.1f, -0.1f, 1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); testVehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f * scale, 0.2f * scale, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, BEPUutilities.Vector3.Down, 0.325f, new BEPUutilities.Vector3(-1.1f, -0.1f, -1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); testVehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f * scale, 0.2f * scale, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, BEPUutilities.Vector3.Down, 0.325f, new BEPUutilities.Vector3(1.1f, -0.1f, 1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); testVehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f * scale, 0.2f * scale, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, BEPUutilities.Vector3.Down, 0.325f, new BEPUutilities.Vector3(1.1f, -0.1f, -1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); foreach (Wheel wheel in testVehicle.Wheels) { //This is a cosmetic setting that makes it looks like the car doesn't have antilock brakes. wheel.Shape.FreezeWheelsWhileBraking = true; //By default, wheels use as many iterations as the space. By lowering it, //performance can be improved at the cost of a little accuracy. //However, because the suspension and friction are not really rigid, //the lowered accuracy is not so much of a problem. wheel.Suspension.SolverSettings.MaximumIterationCount = 1; wheel.Brake.SolverSettings.MaximumIterationCount = 1; wheel.SlidingFriction.SolverSettings.MaximumIterationCount = 1; wheel.DrivingMotor.SolverSettings.MaximumIterationCount = 1; } SystemCore.PhysicsSimulation.Add(testVehicle); }
public static Location ForwardVector(BEPUutilities.Quaternion quat) { return(Location.FromBVector(BEPUutilities.Quaternion.Transform(BEPUutilities.Vector3.UnitX, quat))); }
private void ProcessAIStepHandler(object sender, UpdateStepEventArgs e) { // Check FOV, add any new foes to memory. And update existing ones. We may also have gained new memories by other means. // Get players and mobs in field of vision: List <RayCastResult> actorsInView = new List <RayCastResult>(); ConeShape visionCone = new ConeShape(VisionDistance, VisionDistance); BipedControllerComponent bcc = Owner.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control); RigidTransform tipOverCone = new RigidTransform(BepuVec3.Forward * VisionDistance * 0.75f, BepuQuaternion.CreateFromAxisAngle(BepuVec3.Right, MathHelper.PiOver2)); RigidTransform eyeLevelAndFacing = new RigidTransform(bcc.Controller.Body.Position - bcc.Controller.Down * bcc.Controller.Body.Height * 0.45f, BepuConverter.Convert(SpaceUtils.GetOrientation(BepuConverter.Convert(bcc.Controller.ViewDirection), Vector3.Up))); RigidTransform visionConeTransform; RigidTransform.Transform(ref tipOverCone, ref eyeLevelAndFacing, out visionConeTransform); BepuVec3 noSweep = BepuVec3.Zero; ViewInterestFilter filter = new ViewInterestFilter(bcc.Controller.Body.CollisionInformation); GameResources.ActorManager.SimSpace.ConvexCast(visionCone, ref visionConeTransform, ref noSweep, filter.Test, actorsInView); for (int a = 0; a < actorsInView.Count; ++a) { // Does this actor warrant an addition to be made to our memory? // If so, check for LOS and recheck range. If those tests pass, modify the memory. EntityCollidable otherEntityCollidable = actorsInView[a].HitObject as EntityCollidable; // We can jump to the Id in the Tag property because we know the filter has validated this. int actorId = (int)(otherEntityCollidable.Entity.Tag); Actor viewedActor = GameResources.ActorManager.GetActorById(actorId); BipedControllerComponent viewedActorBcc = viewedActor.GetComponent <BipedControllerComponent>(ActorComponent.ComponentType.Control); BepuVec3 toSubject = viewedActorBcc.Controller.Body.Position - eyeLevelAndFacing.Position; // Check range: if (toSubject.LengthSquared() <= VisionDistance * VisionDistance) { BepuRay losRay = new BepuRay(eyeLevelAndFacing.Position, toSubject); RayCastResult losResult; LOSFilter losFilter = new LOSFilter(bcc.Controller.Body.CollisionInformation, otherEntityCollidable); GameResources.ActorManager.SimSpace.RayCast(losRay, VisionDistance, losFilter.Test, out losResult); EntityCollidable losEC = losResult.HitObject as EntityCollidable; // Test for LOS: if (losEC != null && losEC.Entity != null && losEC.Entity.Tag != null && (int)(losEC.Entity.Tag) == actorId) { // The viewed actor is either a player(foe) or a mob(ally). if (GameResources.ActorManager.IsPlayer(actorId)) { mMemory.SpotFoe(actorId); } else { IAgentStateManager agent = viewedActor.GetBehaviorThatImplementsType <IAgentStateManager>(); if (agent != null && agent.HasProperty(AgentPropertyName.ActiveOpponent)) { int mobFoe = agent.GetProperty <int>(AgentPropertyName.ActiveOpponent); mMemory.SenseFoe(mobFoe); } } } } } // Evaluate current threats and select one to engage: int enemyId = mMemory.GetLargestThreat(); if (enemyId != Actor.INVALID_ACTOR_ID) { if (mAgentProperties.ContainsKey(AgentPropertyName.ActiveOpponent)) { if ((int)(mAgentProperties[AgentPropertyName.ActiveOpponent]) != enemyId) { mAgentProperties[AgentPropertyName.ActiveOpponent] = enemyId; } } else { mAgentProperties.Add(AgentPropertyName.ActiveOpponent, enemyId); } } else { if (mAgentProperties.ContainsKey(AgentPropertyName.ActiveOpponent)) { mAgentProperties.Remove(AgentPropertyName.ActiveOpponent); } } TimeInState += e.GameTime.ElapsedGameTime; CurrentState.Update(mSteering, Owner, this); Vector2 locomotion = mSteering.ComputeForce(Owner); if (locomotion.LengthSquared() == 0.0f) { bcc.OrientationChange = Quaternion.Identity; bcc.HorizontalMovement = Vector2.Zero; } else { bcc.OrientationChange = Quaternion.CreateFromAxisAngle(Vector3.Up, (float)(Math.Atan2(-locomotion.X, locomotion.Y))); bcc.HorizontalMovement = locomotion.Length() * Vector2.UnitY; } mMemory.Fade(e.GameTime); }
public static Quaternion toEngineQuat(this BEPUutilities.Quaternion conv) { return(new Quaternion(conv.X, conv.Y, conv.Z, conv.W)); }
internal static Quaternion QuaternionB2T(BEPUutilities.Quaternion quaternion) { return(new Quaternion(quaternion.X, quaternion.Y, quaternion.Z, quaternion.W)); }
public AddJointPacketOut(InternalBaseJoint joint) { UsageType = NetUsageType.ENTITIES; ID = ServerToClientPacket.ADD_JOINT; int len = 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4 + 24 + 4 + 4 + 4 + 4; // TODO: joint registry! if (joint is JointBallSocket) { Data = new byte[len + 24]; Data[0] = 0; ((JointBallSocket)joint).Position.ToDoubleBytes().CopyTo(Data, len); } else if (joint is JointSlider) { Data = new byte[len + 24]; Data[0] = 1; ((JointSlider)joint).Direction.ToDoubleBytes().CopyTo(Data, len); } else if (joint is JointDistance) { Data = new byte[len + 4 + 4 + 24 + 24]; Data[0] = 2; Utilities.FloatToBytes((float)((JointDistance)joint).Min).CopyTo(Data, len); Utilities.FloatToBytes((float)((JointDistance)joint).Max).CopyTo(Data, len + 4); ((JointDistance)joint).Ent1Pos.ToDoubleBytes().CopyTo(Data, len + 4 + 4); ((JointDistance)joint).Ent2Pos.ToDoubleBytes().CopyTo(Data, len + 4 + 4 + 24); } else if (joint is JointPullPush) { Data = new byte[len + 24 + 1]; Data[0] = 3; ((JointPullPush)joint).Axis.ToDoubleBytes().CopyTo(Data, len); Data[len + 24] = (byte)(((JointPullPush)joint).Mode ? 1 : 0); } else if (joint is JointForceWeld) { Data = new byte[len]; Data[0] = 4; } else if (joint is JointSpinner) { Data = new byte[len + 24]; Data[0] = 5; ((JointSpinner)joint).Direction.ToDoubleBytes().CopyTo(Data, len); } else if (joint is JointTwist) { Data = new byte[len + 24 + 24]; Data[0] = 6; ((JointTwist)joint).AxisOne.ToDoubleBytes().CopyTo(Data, len); ((JointTwist)joint).AxisTwo.ToDoubleBytes().CopyTo(Data, len + 24); } else if (joint is JointWeld) { Data = new byte[len]; Data[0] = 7; } else if (joint is JointVehicleMotor) { Data = new byte[len + 24 + 1]; Data[0] = 8; ((JointVehicleMotor)joint).Direction.ToDoubleBytes().CopyTo(Data, len); Data[len + 24] = (byte)(((JointVehicleMotor)joint).IsSteering ? 1 : 0); } else if (joint is JointLAxisLimit) { Data = new byte[len + 24 + 24 + 24 + 4 + 4]; Data[0] = 9; ((JointLAxisLimit)joint).CPos1.ToDoubleBytes().CopyTo(Data, len); ((JointLAxisLimit)joint).CPos2.ToDoubleBytes().CopyTo(Data, len + 24); ((JointLAxisLimit)joint).Axis.ToDoubleBytes().CopyTo(Data, len + 24 + 24); Utilities.FloatToBytes((float)((JointLAxisLimit)joint).Min).CopyTo(Data, len + 24 + 24 + 24); Utilities.FloatToBytes((float)((JointLAxisLimit)joint).Max).CopyTo(Data, len + 24 + 24 + 24 + 4); } else if (joint is JointSwivelHinge) { Data = new byte[len + 24 + 24]; Data[0] = 10; ((JointSwivelHinge)joint).WorldHinge.ToDoubleBytes().CopyTo(Data, len); ((JointSwivelHinge)joint).WorldTwist.ToDoubleBytes().CopyTo(Data, len + 24); } else if (joint is ConstWheelStepUp) { Data = new byte[len + 4]; Data[0] = 11; Utilities.FloatToBytes((float)((ConstWheelStepUp)joint).Height).CopyTo(Data, len); } else if (joint is ConnectorBeam) { Data = new byte[len + 4 * 4 + 1]; Data[0] = 12; Utilities.FloatToBytes(((ConnectorBeam)joint).color.R).CopyTo(Data, len); Utilities.FloatToBytes(((ConnectorBeam)joint).color.G).CopyTo(Data, len + 4); Utilities.FloatToBytes(((ConnectorBeam)joint).color.B).CopyTo(Data, len + 4 * 2); Utilities.FloatToBytes(((ConnectorBeam)joint).color.A).CopyTo(Data, len + 4 * 3); Data[len + 4 * 4] = (byte)((ConnectorBeam)joint).type; } else if (joint is JointFlyingDisc) { Data = new byte[len]; Data[0] = 13; } else if (joint is JointNoCollide) { Data = new byte[len]; Data[0] = 14; } else if (joint is JointHinge) { Data = new byte[len + 24]; Data[0] = 15; ((JointHinge)joint).WorldHinge.ToDoubleBytes().CopyTo(Data, len); } Utilities.LongToBytes(joint.One.EID).CopyTo(Data, 1); Utilities.LongToBytes(joint.Two.EID).CopyTo(Data, 1 + 8); Utilities.LongToBytes(joint.JID).CopyTo(Data, 1 + 8 + 8); joint.One.GetPosition().ToDoubleBytes().CopyTo(Data, 1 + 8 + 8 + 8); BEPUutilities.Quaternion quat = joint.One.GetOrientation(); Utilities.FloatToBytes((float)quat.X).CopyTo(Data, 1 + 8 + 8 + 8 + 24); Utilities.FloatToBytes((float)quat.Y).CopyTo(Data, 1 + 8 + 8 + 8 + 24 + 4); Utilities.FloatToBytes((float)quat.Z).CopyTo(Data, 1 + 8 + 8 + 8 + 24 + 4 + 4); Utilities.FloatToBytes((float)quat.W).CopyTo(Data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4); joint.Two.GetPosition().ToDoubleBytes().CopyTo(Data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4); BEPUutilities.Quaternion quat2 = joint.Two.GetOrientation(); Utilities.FloatToBytes((float)quat2.X).CopyTo(Data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4 + 24); Utilities.FloatToBytes((float)quat2.Y).CopyTo(Data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4 + 24 + 4); Utilities.FloatToBytes((float)quat2.Z).CopyTo(Data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4 + 24 + 4 + 4); Utilities.FloatToBytes((float)quat2.W).CopyTo(Data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4 + 24 + 4 + 4 + 4); }
public override bool ParseBytesAndExecute(byte[] data) { int len = 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4 + 24 + 4 + 4 + 4 + 4; if (data.Length < len) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad initial length!"); return false; } byte type = data[0]; long EID1 = Utilities.BytesToLong(Utilities.BytesPartial(data, 1, 8)); long EID2 = Utilities.BytesToLong(Utilities.BytesPartial(data, 1 + 8, 8)); long JID = Utilities.BytesToLong(Utilities.BytesPartial(data, 1 + 8 + 8, 8)); if (TheClient.TheRegion.GetJoint(JID) != null) { // If we already know this joint, just keep on going. return true; } Entity pe1 = TheClient.TheRegion.GetEntity(EID1); Entity pe2 = TheClient.TheRegion.GetEntity(EID2); if (pe1 == null) { SysConsole.Output(OutputType.WARNING, "Joint Packet: Invalid EID-1 " + EID1); return false; } if (pe2 == null) { SysConsole.Output(OutputType.WARNING, "Joint Packet: Invalid EID-2 " + EID2); return false; } Location pos1 = Location.FromDoubleBytes(data, 1 + 8 + 8 + 8); float qx1 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24, 4)); float qy1 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4, 4)); float qz1 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 4, 4)); float qw1 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4, 4)); BEPUutilities.Quaternion quat1 = new BEPUutilities.Quaternion(qx1, qy1, qz1, qw1); pe1.SetPosition(pos1); pe1.SetOrientation(quat1); Location pos2 = Location.FromDoubleBytes(data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4); float qx2 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 24 + 4 + 4 + 4 + 4, 4)); float qy2 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 24 + 4 + 4 + 4 + 4, 4)); float qz2 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 24 + 4 + 4 + 4 + 4, 4)); float qw2 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 24 + 4 + 4 + 4 + 4, 4)); BEPUutilities.Quaternion quat2 = new BEPUutilities.Quaternion(qx2, qy2, qz2, qw2); pe1.SetPosition(pos1); pe1.SetOrientation(quat1); pe2.SetPosition(pos2); pe2.SetOrientation(quat2); if (type == 0) { if (data.Length != len + 24) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return false; } Location pos = Location.FromDoubleBytes(data, len); JointBallSocket jbs = new JointBallSocket((PhysicsEntity)pe1, (PhysicsEntity)pe2, pos); jbs.JID = JID; TheClient.TheRegion.AddJoint(jbs); return true; } else if (type == 1) { if (data.Length != len + 24) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return false; } Location dir = Location.FromDoubleBytes(data, len); JointSlider js = new JointSlider((PhysicsEntity)pe1, (PhysicsEntity)pe2, dir); js.JID = JID; TheClient.TheRegion.AddJoint(js); return true; } else if (type == 2) { if (data.Length != len + 4 + 4 + 24 + 24) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return false; } float min = Utilities.BytesToFloat(Utilities.BytesPartial(data, len, 4)); float max = Utilities.BytesToFloat(Utilities.BytesPartial(data, len + 4, 4)); Location ent1pos = Location.FromDoubleBytes(data, len + 4 + 4); Location ent2pos = Location.FromDoubleBytes(data, len + 4 + 4 + 24); JointDistance jd = new JointDistance((PhysicsEntity)pe1, (PhysicsEntity)pe2, min, max, ent1pos, ent2pos); jd.JID = JID; TheClient.TheRegion.AddJoint(jd); return true; } else if (type == 3) { if (data.Length != len + 24 + 1) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return false; } Location axis = Location.FromDoubleBytes(data, len); bool mode = data[len + 24] == 1; JointPullPush jpp = new JointPullPush((PhysicsEntity)pe1, (PhysicsEntity)pe2, axis, mode); jpp.JID = JID; TheClient.TheRegion.AddJoint(jpp); return true; } else if (type == 4) { if (data.Length != len) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return false; } JointForceWeld jfw = new JointForceWeld(pe1, pe2); jfw.JID = JID; TheClient.TheRegion.AddJoint(jfw); return true; } else if (type == 5) { if (data.Length != len + 24) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return false; } Location dir = Location.FromDoubleBytes(data, len); JointSpinner js = new JointSpinner((PhysicsEntity)pe1, (PhysicsEntity)pe2, dir); js.JID = JID; TheClient.TheRegion.AddJoint(js); return true; } else if (type == 6) { if (data.Length != len + 24 + 24) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return false; } Location a1 = Location.FromDoubleBytes(data, len); Location a2 = Location.FromDoubleBytes(data, len + 24); JointTwist jt = new JointTwist((PhysicsEntity)pe1, (PhysicsEntity)pe2, a1, a2); jt.JID = JID; TheClient.TheRegion.AddJoint(jt); return true; } else if (type == 7) { if (data.Length != len) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return false; } JointWeld jw = new JointWeld((PhysicsEntity)pe1, (PhysicsEntity)pe2); jw.JID = JID; TheClient.TheRegion.AddJoint(jw); return true; } else if (type == 8) { if (data.Length != len + 24 + 1) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return false; } Location dir = Location.FromDoubleBytes(data, len); bool issteering = data[len + 24] == 1; JointVehicleMotor jm = new JointVehicleMotor((PhysicsEntity)pe1, (PhysicsEntity)pe2, dir, issteering); jm.JID = JID; TheClient.TheRegion.AddJoint(jm); return true; } else if (type == 9) { if (data.Length != len + 24 + 24 + 24 + 4 + 4) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return false; } Location cpos1 = Location.FromDoubleBytes(data, len); Location cpos2 = Location.FromDoubleBytes(data, len + 24); Location axis = Location.FromDoubleBytes(data, len + 24 + 24); float min = Utilities.BytesToFloat(Utilities.BytesPartial(data, len + 24 + 24 + 24, 4)); float max = Utilities.BytesToFloat(Utilities.BytesPartial(data, len + 24 + 24 + 24 + 4, 4)); JointLAxisLimit jlal = new JointLAxisLimit((PhysicsEntity)pe1, (PhysicsEntity)pe2, min, max, cpos1, cpos2, axis); jlal.JID = JID; TheClient.TheRegion.AddJoint(jlal); return true; } else if (type == 10) { if (data.Length != len + 24 + 24) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return false; } Location hinge = Location.FromDoubleBytes(data, len); Location twist = Location.FromDoubleBytes(data, len + 24); JointSwivelHinge jlal = new JointSwivelHinge((PhysicsEntity)pe1, (PhysicsEntity)pe2, hinge, twist); jlal.JID = JID; TheClient.TheRegion.AddJoint(jlal); return true; } else if (type == 11) { if (data.Length != len + 4) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return false; } float height = Utilities.BytesToFloat(Utilities.BytesPartial(data, len, 4)); ConstWheelStepUp cwsu = new ConstWheelStepUp((PhysicsEntity)pe1, height); cwsu.JID = JID; TheClient.TheRegion.AddJoint(cwsu); return true; } else if (type == 12) { if (data.Length != len + 4 + 1) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return false; } ConnectorBeam cb = new ConnectorBeam(); cb.One = pe1; cb.Two = pe2; cb.color = System.Drawing.Color.FromArgb(Utilities.BytesToInt(Utilities.BytesPartial(data, len, 4))); cb.JID = JID; cb.type = (BeamType)data[len + 4]; TheClient.TheRegion.AddJoint(cb); return true; } else if (type == 13) { if (data.Length != len) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return false; } JointFlyingDisc jfd = new JointFlyingDisc((PhysicsEntity)pe1); jfd.JID = JID; TheClient.TheRegion.AddJoint(jfd); return true; } else if (type == 14) { if (data.Length != len) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return false; } JointNoCollide jnc = new JointNoCollide((PhysicsEntity)pe1, (PhysicsEntity)pe2); jnc.JID = JID; TheClient.TheRegion.AddJoint(jnc); return true; } else { SysConsole.Output(OutputType.WARNING, "Unknown joint type " + type); return false; } }
/// <summary> /// Fired when entity is spawned. /// </summary> public override void OnSpawn() { Game game = Engine3D.Source as Game; // Generate the layer seeds, height map and materials int s2 = Size * 2; Seeds = new Vector2[Layers]; for (int i = 0; i < Layers; i++) { Seeds[i] = new Vector2((float)game.Random.NextDouble(), (float)game.Random.NextDouble()); } GenerateHeightMap(2.0f); ApplyClampedHeightMap(8.0f, 0.025f, 0.0f, 0.75f, Seeds[0]); ApplyHeightMap(0.5f, 0.25f, 0.5f, Seeds[1]); ApplyHighHeightMap(2.0f, 0.15f, 0.5f, 7.0f, Seeds[2]); GenerateMaterialLayer(GridMaterial.Grass); ApplyHighMaterialLayer(GridMaterial.Dirt, 0.05f, Seeds[3], 7.0f, 3.0f); ApplyHighMaterialLayer(GridMaterial.Rock, 0.025f, Seeds[4], 9.0f, 1.0f); ApplyLowMaterialLayer(GridMaterial.Water, 0.1f, Seeds[5], 3.0f, 0.5f); // Generate the terrain grid mesh: Vertices, Normals and Indices Builder = new Renderable.ListBuilder(); int n = s2 * Size * 3; Builder.Prepare(n); for (int i = 1; i < s2; i++) { for (int j = 0; j < Size; j++) { GridFace face = new GridFace(i, j); List <Vector3> vertices = new List <Vector3>(); foreach (GridVertex vert in face.Corners()) { vertices.Add(vert.ToCartesianCoords3D(HeightMap)); Builder.AddEmptyBoneInfo(); } Builder.Vertices.AddRange(vertices); Vector3[] vArray = vertices.ToArray(); Vector3 normal = Vector3.Cross(vArray[2] - vArray[0], vArray[1] - vArray[0]); normal.Normalize(); Builder.Normals.Add(normal); Builder.Normals.Add(normal); Builder.Normals.Add(normal); Vector4 c = Materials[i, j].Color.ToOpenTK(); Builder.Colors.Add(c); Builder.Colors.Add(c); Builder.Colors.Add(c); if (face.PointsUp()) { Builder.TexCoords.Add(new Vector3(0, 0, 0)); Builder.TexCoords.Add(new Vector3(0.5f, 1, 0)); Builder.TexCoords.Add(new Vector3(1, 0, 0)); } else { Builder.TexCoords.Add(new Vector3(1, 1, 0)); Builder.TexCoords.Add(new Vector3(0.5f, 0, 0)); Builder.TexCoords.Add(new Vector3(0, 1, 0)); } } } int count = Builder.Vertices.Count; for (uint k = 0; k < count; k++) { Builder.Indices.Add(k); } Rend = Builder.Generate(); BEPUutilities.Vector3 scaling = new BEPUutilities.Vector3(0.5, 1, -0.866); BEPUutilities.Quaternion rotation = BEPUutilities.Quaternion.CreateFromAxisAngle(BEPUutilities.Vector3.UnitX, MathHelper.PiOver2); BEPUutilities.Vector3 translation = BEPUutilities.Vector3.Zero; Body = new Terrain(new TerrainShape(HeightMap), new BEPUutilities.AffineTransform(ref scaling, ref rotation, ref translation)) { ImproveBoundaryBehavior = true }; }
public override bool ParseBytesAndExecute(byte[] data) { int len = 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4 + 24 + 4 + 4 + 4 + 4; if (data.Length < len) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad initial length!"); return(false); } byte type = data[0]; long EID1 = Utilities.BytesToLong(Utilities.BytesPartial(data, 1, 8)); long EID2 = Utilities.BytesToLong(Utilities.BytesPartial(data, 1 + 8, 8)); long JID = Utilities.BytesToLong(Utilities.BytesPartial(data, 1 + 8 + 8, 8)); if (TheClient.TheRegion.GetJoint(JID) != null) { // If we already know this joint, just keep on going. return(true); } Entity pe1 = TheClient.TheRegion.GetEntity(EID1); Entity pe2 = TheClient.TheRegion.GetEntity(EID2); if (pe1 == null) { SysConsole.Output(OutputType.WARNING, "Joint Packet: Invalid EID-1 " + EID1); return(false); } if (pe2 == null) { SysConsole.Output(OutputType.WARNING, "Joint Packet: Invalid EID-2 " + EID2); return(false); } Location pos1 = Location.FromDoubleBytes(data, 1 + 8 + 8 + 8); float qx1 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24, 4)); float qy1 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4, 4)); float qz1 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 4, 4)); float qw1 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4, 4)); BEPUutilities.Quaternion quat1 = new BEPUutilities.Quaternion(qx1, qy1, qz1, qw1); pe1.SetPosition(pos1); pe1.SetOrientation(quat1); Location pos2 = Location.FromDoubleBytes(data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 4); float qx2 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 24 + 4 + 4 + 4 + 4, 4)); float qy2 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 24 + 4 + 4 + 4 + 4, 4)); float qz2 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 24 + 4 + 4 + 4 + 4, 4)); float qw2 = Utilities.BytesToFloat(Utilities.BytesPartial(data, 1 + 8 + 8 + 8 + 24 + 4 + 4 + 4 + 24 + 4 + 4 + 4 + 4, 4)); BEPUutilities.Quaternion quat2 = new BEPUutilities.Quaternion(qx2, qy2, qz2, qw2); pe1.SetPosition(pos1); pe1.SetOrientation(quat1); pe2.SetPosition(pos2); pe2.SetOrientation(quat2); if (type == 0) { if (data.Length != len + 24) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return(false); } Location pos = Location.FromDoubleBytes(data, len); JointBallSocket jbs = new JointBallSocket((PhysicsEntity)pe1, (PhysicsEntity)pe2, pos) { JID = JID }; TheClient.TheRegion.AddJoint(jbs); return(true); } else if (type == 1) { if (data.Length != len + 24) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return(false); } Location dir = Location.FromDoubleBytes(data, len); JointSlider js = new JointSlider((PhysicsEntity)pe1, (PhysicsEntity)pe2, dir) { JID = JID }; TheClient.TheRegion.AddJoint(js); return(true); } else if (type == 2) { if (data.Length != len + 4 + 4 + 24 + 24) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return(false); } float min = Utilities.BytesToFloat(Utilities.BytesPartial(data, len, 4)); float max = Utilities.BytesToFloat(Utilities.BytesPartial(data, len + 4, 4)); Location ent1pos = Location.FromDoubleBytes(data, len + 4 + 4); Location ent2pos = Location.FromDoubleBytes(data, len + 4 + 4 + 24); JointDistance jd = new JointDistance((PhysicsEntity)pe1, (PhysicsEntity)pe2, min, max, ent1pos, ent2pos) { JID = JID }; TheClient.TheRegion.AddJoint(jd); return(true); } else if (type == 3) { if (data.Length != len + 24 + 1) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return(false); } Location axis = Location.FromDoubleBytes(data, len); bool mode = data[len + 24] == 1; JointPullPush jpp = new JointPullPush((PhysicsEntity)pe1, (PhysicsEntity)pe2, axis, mode) { JID = JID }; TheClient.TheRegion.AddJoint(jpp); return(true); } else if (type == 4) { if (data.Length != len) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return(false); } JointForceWeld jfw = new JointForceWeld(pe1, pe2) { JID = JID }; TheClient.TheRegion.AddJoint(jfw); return(true); } else if (type == 5) { if (data.Length != len + 24) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return(false); } Location dir = Location.FromDoubleBytes(data, len); JointSpinner js = new JointSpinner((PhysicsEntity)pe1, (PhysicsEntity)pe2, dir) { JID = JID }; TheClient.TheRegion.AddJoint(js); return(true); } else if (type == 6) { if (data.Length != len + 24 + 24) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return(false); } Location a1 = Location.FromDoubleBytes(data, len); Location a2 = Location.FromDoubleBytes(data, len + 24); JointTwist jt = new JointTwist((PhysicsEntity)pe1, (PhysicsEntity)pe2, a1, a2) { JID = JID }; TheClient.TheRegion.AddJoint(jt); return(true); } else if (type == 7) { if (data.Length != len) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return(false); } JointWeld jw = new JointWeld((PhysicsEntity)pe1, (PhysicsEntity)pe2) { JID = JID }; TheClient.TheRegion.AddJoint(jw); return(true); } else if (type == 8) { if (data.Length != len + 24 + 1) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return(false); } Location dir = Location.FromDoubleBytes(data, len); bool issteering = data[len + 24] == 1; JointVehicleMotor jm = new JointVehicleMotor((PhysicsEntity)pe1, (PhysicsEntity)pe2, dir, issteering) { JID = JID }; TheClient.TheRegion.AddJoint(jm); return(true); } else if (type == 9) { if (data.Length != len + 24 + 24 + 24 + 4 + 4) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return(false); } Location cpos1 = Location.FromDoubleBytes(data, len); Location cpos2 = Location.FromDoubleBytes(data, len + 24); Location axis = Location.FromDoubleBytes(data, len + 24 + 24); float min = Utilities.BytesToFloat(Utilities.BytesPartial(data, len + 24 + 24 + 24, 4)); float max = Utilities.BytesToFloat(Utilities.BytesPartial(data, len + 24 + 24 + 24 + 4, 4)); JointLAxisLimit jlal = new JointLAxisLimit((PhysicsEntity)pe1, (PhysicsEntity)pe2, min, max, cpos1, cpos2, axis) { JID = JID }; TheClient.TheRegion.AddJoint(jlal); return(true); } else if (type == 10) { if (data.Length != len + 24 + 24) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return(false); } Location hinge = Location.FromDoubleBytes(data, len); Location twist = Location.FromDoubleBytes(data, len + 24); JointSwivelHinge jlal = new JointSwivelHinge((PhysicsEntity)pe1, (PhysicsEntity)pe2, hinge, twist) { JID = JID }; TheClient.TheRegion.AddJoint(jlal); return(true); } else if (type == 11) { if (data.Length != len + 4) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return(false); } float height = Utilities.BytesToFloat(Utilities.BytesPartial(data, len, 4)); ConstWheelStepUp cwsu = new ConstWheelStepUp((PhysicsEntity)pe1, height) { JID = JID }; TheClient.TheRegion.AddJoint(cwsu); return(true); } else if (type == 12) { if (data.Length != len + 4 + 1) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return(false); } ConnectorBeam cb = new ConnectorBeam() { One = pe1, Two = pe2, color = System.Drawing.Color.FromArgb(Utilities.BytesToInt(Utilities.BytesPartial(data, len, 4))), JID = JID, type = (BeamType)data[len + 4] }; TheClient.TheRegion.AddJoint(cb); return(true); } else if (type == 13) { if (data.Length != len) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return(false); } JointFlyingDisc jfd = new JointFlyingDisc((PhysicsEntity)pe1) { JID = JID }; TheClient.TheRegion.AddJoint(jfd); return(true); } else if (type == 14) { if (data.Length != len) { SysConsole.Output(OutputType.WARNING, "Joint packet: Bad length!"); return(false); } JointNoCollide jnc = new JointNoCollide((PhysicsEntity)pe1, (PhysicsEntity)pe2) { JID = JID }; TheClient.TheRegion.AddJoint(jnc); return(true); } else { SysConsole.Output(OutputType.WARNING, "Unknown joint type " + type); return(false); } }
public abstract void SetOrientation(BEPUutilities.Quaternion quat);
public static Quaternion Convert(BEPUutilities.Quaternion q) { return(new Quaternion(q.X, q.Y, q.Z, q.W)); }