コード例 #1
0
        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
        /// <summary>
        /// Reset the values, the position, rotation etc.
        /// </summary>
        public void Reset()
        {
            // Reset the raw values
            raw_thrust = 0.0f;
            raw_yaw    = 0.0f;
            raw_pitch  = 0.0f;
            raw_roll   = 0.0f;

            //keepHeight = false;
            //autoHover = false;
            attitude_dx = 0.0f;
            attitude_dz = 0.0f;
            pidControllerAltitude.Reset();
            pidControllerAttitudeX.Reset();
            pidControllerAttitudeZ.Reset();

            // Reset rotation and position
            Rotation = new xna.Vector3();
            Position = TypeConversion.ToXNA(initialPos);

            // Reset the linear and the angular velocity
            PhysicsEntity.SetAngularVelocity(new Vector3());
            PhysicsEntity.SetLinearVelocity(new Vector3());

            // Reset the camera to the initial view
            cameraView.EyePosition = MulticopterSimulationService.INITIAL_CAMERA_EYEPOS;
            cameraView.LookAtPoint = MulticopterSimulationService.INITIAL_CAMERA_LOOKAT;
            SimulationEngine.GlobalInstancePort.Update(cameraView);
        }