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);
        }
예제 #2
0
        public override void Click(Entity entity, ItemStack item)
        {
            if (!(entity is PlayerEntity))
            {
                return; // TODO: non-player support?
            }
            PlayerEntity player = (PlayerEntity)entity;

            if (player.Manipulator_Grabbed != null)
            {
                return;
            }
            Location        eye = player.ItemSource();
            CollisionResult cr  = player.TheRegion.Collision.RayTrace(eye, eye + player.ItemDir * 50, player.IgnoreThis);

            if (!cr.Hit || cr.HitEnt == null || cr.HitEnt.Mass <= 0)
            {
                return;
            }
            PhysicsEntity target = (PhysicsEntity)cr.HitEnt.Tag;

            player.Manipulator_Grabbed  = target;
            player.Manipulator_Distance = (double)(eye - target.GetPosition()).Length();
            player.Manipulator_Beam     = new ConnectorBeam()
            {
                type = BeamType.MULTICURVE
            };
            player.Manipulator_Beam.One   = player;
            player.Manipulator_Beam.Two   = target;
            player.Manipulator_Beam.color = Colors.BLUE;
            player.TheRegion.AddJoint(player.Manipulator_Beam);
        }
예제 #3
0
 public JointDistance(PhysicsEntity e1, PhysicsEntity e2, double min, double max, Location e1pos, Location e2pos)
 {
     Ent1    = e1;
     Ent2    = e2;
     Min     = min;
     Max     = max;
     Ent1Pos = e1pos - e1.GetPosition();
     Ent2Pos = e2pos - e2.GetPosition();
 }
예제 #4
0
 public PhysicsEntityUpdatePacketOut(PhysicsEntity e)
 {
     UsageType = NetUsageType.ENTITIES;
     ID        = ServerToClientPacket.PHYSICS_ENTITY_UPDATE;
     Data      = new byte[24 + 24 + 16 + 24 + 1 + 8];
     e.GetPosition().ToDoubleBytes().CopyTo(Data, 0);
     e.GetVelocity().ToDoubleBytes().CopyTo(Data, 24);
     Utilities.QuaternionToBytes(e.GetOrientation()).CopyTo(Data, 24 + 24);
     e.GetAngularVelocity().ToDoubleBytes().CopyTo(Data, 24 + 24 + 16);
     Data[24 + 24 + 16 + 24] = (byte)((e.Body != null && e.Body.ActivityInformation.IsActive) ? 1 : 0);
     Utilities.LongToBytes(e.EID).CopyTo(Data, 24 + 24 + 16 + 24 + 1);
 }
예제 #5
0
 public static Vector2 CalculateGravitationalForce(PhysicsEntity a, PhysicsEntity b)
 {
     return(CalculateGravitationalForce(a.GetPosition(), a.GetMass(), b.GetPosition(), b.GetMass()));
 }
예제 #6
0
        public void ApplyHook(PlayerEntity player, ItemStack item, Location Position, BEPUphysics.Entities.Entity HitEnt)
        {
            RemoveHook(player);
            PhysicsEntity pe;
            double        len  = (double)(Position - player.GetCenter()).Length();
            Location      step = (player.GetCenter() - Position) / len;
            Location      forw = Utilities.VectorToAngles(step);

            forw.Yaw += 180;
            BEPUutilities.Quaternion quat = BEPUutilities.Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), (double)(forw.Pitch * Utilities.PI180)) *
                                            BEPUutilities.Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), (double)(forw.Yaw * Utilities.PI180));
            if (HitEnt == null)
            {
                ModelEntity mod = new ModelEntity("cube", player.TheRegion)
                {
                    Mass    = 0,
                    CanSave = false,
                    scale   = new Location(0.023, 0.05, 0.05),
                    mode    = ModelCollisionMode.AABB
                };
                mod.SetPosition(Position);
                mod.SetOrientation(quat);
                player.TheRegion.SpawnEntity(mod);
                pe = mod;
                player.Hooks.Add(new HookInfo()
                {
                    Joint = null, Hit = pe, IsBar = true
                });
            }
            else
            {
                pe = (PhysicsEntity)HitEnt.Tag;
            }
            JointDistance jd;
            //jd = new JointDistance(player, pe, 0.01f, len + 0.01f, player.GetCenter(), Position);
            //player.TheRegion.AddJoint(jd);
            //player.Hooks.Add(new HookInfo() { Joint = jd, Hit = pe, IsBar = false });
            PhysicsEntity cent = pe;

            for (double f = 0; f < len - 1f; f += 0.5f)
            {
                Location    cpos = Position + step * f;
                ModelEntity ce   = new ModelEntity("cube", player.TheRegion)
                {
                    Mass    = 15,
                    CanSave = false,
                    scale   = new Location(0.023, 0.05, 0.05),
                    mode    = ModelCollisionMode.AABB
                };
                ce.SetPosition(cpos + step * 0.5);
                ce.SetOrientation(quat);
                player.TheRegion.SpawnEntity(ce);
                jd = new JointDistance(ce, cent, 0.01f, 0.5f, ce.GetPosition(), (ReferenceEquals(cent, pe) ? Position: cent.GetPosition()));
                CollisionRules.AddRule(player.Body, ce.Body, CollisionRule.NoBroadPhase);
                player.TheRegion.AddJoint(jd);
                player.Hooks.Add(new HookInfo()
                {
                    Joint = jd, Hit = ce, IsBar = true
                });
                cent = ce;
            }
            jd = new JointDistance(cent, player, 0.01f, 0.5f, cent.GetPosition(), player.GetCenter());
            player.TheRegion.AddJoint(jd);
            player.Hooks.Add(new HookInfo()
            {
                Joint = jd, Hit = player, IsBar = false
            });
        }