Beispiel #1
0
        public override void trigger(Object lastStateObj, Object currentStateObj, GameStateData currentGameState)
        {
            F12018StructWrapper currentWrapper = (F12018StructWrapper)currentStateObj;

            if (currentWrapper.packetLapData.m_lapData == null || currentWrapper.packetMotionData.m_carMotionData == null || currentWrapper.packetCarTelemetryData.m_carTelemetryData == null)
            {
                return;
            }
            Boolean inPits       = currentWrapper.packetLapData.m_lapData[currentWrapper.packetLapData.m_header.m_playerCarIndex].m_pitStatus != 0;
            Boolean isSpectating = currentWrapper.packetSessionData.m_isSpectating != 0;

            if (inPits || isSpectating)
            {
                return;
            }

            DateTime now = new DateTime(currentWrapper.ticksWhenRead);

            if (enabled && currentWrapper.packetMotionData.m_carMotionData.Length > 1)
            {
                int playerIndex = currentWrapper.packetMotionData.m_header.m_playerCarIndex;

                CarMotionData playerData = currentWrapper.packetMotionData.m_carMotionData[playerIndex];

                float[] currentPlayerPosition = new float[] { playerData.m_worldPositionX, playerData.m_worldPositionZ };

                List <float[]> currentOpponentPositions    = new List <float[]>();
                List <float[]> currentOpponentVelocityData = new List <float[]>();
                float[]        playerVelocityData          = new float[3];
                playerVelocityData[0] = (float)currentWrapper.packetCarTelemetryData.m_carTelemetryData[currentWrapper.packetCarTelemetryData.m_header.m_playerCarIndex].m_speed * 0.277778f;
                playerVelocityData[1] = playerData.m_worldVelocityX;
                playerVelocityData[2] = playerData.m_worldVelocityZ;

                for (int i = 0; i < currentWrapper.packetMotionData.m_carMotionData.Length; i++)
                {
                    if (i == playerIndex)
                    {
                        continue;
                    }
                    CarMotionData opponentData     = currentWrapper.packetMotionData.m_carMotionData[i];
                    float[]       currentPositions = new float[] { opponentData.m_worldPositionX, opponentData.m_worldPositionZ };
                    currentOpponentPositions.Add(currentPositions);
                    currentOpponentVelocityData.Add(new float[] { opponentData.m_worldVelocityX, opponentData.m_worldVelocityZ });
                }
                if (currentOpponentPositions.Count() > 0)
                {
                    float playerRotation = playerData.m_yaw;
                    if (playerRotation < 0)
                    {
                        playerRotation = playerRotation * -1;
                    }
                    else
                    {
                        playerRotation = twoPi - playerRotation;
                    }
                    internalSpotter.triggerInternal(playerRotation, currentPlayerPosition, playerVelocityData, currentOpponentPositions, currentOpponentVelocityData);
                }
            }
        }
Beispiel #2
0
        public F1PacketEventEventArgs(PacketHeader packetHeader           = null,
                                      CarMotionData carMotionData         = null,
                                      PacketSessionData packetSessionData = null,
                                      PacketMotionData packetMotionData   = null)
        {
            this.packetHeader     = packetHeader;
            this.carMotionData    = carMotionData;
            this.packetMotionData = packetMotionData;

            this.packetSessionData = packetSessionData;
        }
Beispiel #3
0
        protected void Awake()
        {
            m_CarController = GetComponent <UnityStandardAssets.Vehicles.Car.CarController>();
            m_CarMotionData = new CarMotionData();
            //m_Explosion = transform.Find("CartoonBoom_V2").gameObject;

            m_CarVisibility = transform.Find("Car_Body").gameObject;

            beUnity = BridgeEngineUnity.main;
            if (beUnity)
            {
                beUnity.onControllerMotionEvent.AddListener(OnMotionEvent);
                beUnity.onControllerButtonEvent.AddListener(OnButtonEvent);
                beUnity.onControllerTouchEvent.AddListener(OnTouchEvent);
            }
            else
            {
                Debug.LogWarning("Cannot connect to BridgeEngineUnity controller.");
            }
        }
Beispiel #4
0
            public PacketMotionData(int a)
            {
                m_header        = new PacketHeader();       // Header
                m_carMotionData = new CarMotionData[20];    // Data for all cars on track

                // Extra player car ONLY data
                m_suspensionPosition     = new float[4]; // Note: All wheel arrays have the following order:
                m_suspensionVelocity     = new float[4]; // RL, RR, FL, FR
                m_suspensionAcceleration = new float[4]; // RL, RR, FL, FR
                m_wheelSpeed             = new float[4]; // Speed of each wheel
                m_wheelSlip            = new float[4];   // Slip ratio for each wheel
                m_localVelocityX       = 0;              // Velocity in local space
                m_localVelocityY       = 0;              // Velocity in local space
                m_localVelocityZ       = 0;              // Velocity in local space
                m_angularVelocityX     = 0;              // Angular velocity x-component
                m_angularVelocityY     = 0;              // Angular velocity y-component
                m_angularVelocityZ     = 0;              // Angular velocity z-component
                m_angularAccelerationX = 0;              // Angular velocity x-component
                m_angularAccelerationY = 0;              // Angular velocity y-component
                m_angularAccelerationZ = 0;              // Angular velocity z-component
                m_frontWheelsAngle     = 0;              // Current front wheels angle in radians
            }
            /// <summary>
            /// Takes 60 bytes to make.
            /// </summary>
            /// <param name="bytes"></param>
            /// <returns></returns>
            public static CarMotionData Create(byte[] bytes)
            {
                CarMotionData    ReturnInstance = new CarMotionData();
                ByteArrayManager BAM            = new ByteArrayManager(bytes);
                List <byte>      ToConvert      = new List <byte>();

                //Get position X,Y,Z
                ReturnInstance.PositionX = BitConverter.ToSingle(BAM.NextBytes(4), 0);
                ReturnInstance.PositionY = BitConverter.ToSingle(BAM.NextBytes(4), 0);
                ReturnInstance.PositionZ = BitConverter.ToSingle(BAM.NextBytes(4), 0);

                //Get Velocity X,Y,Z
                ReturnInstance.VelocityX = BitConverter.ToSingle(BAM.NextBytes(4), 0);
                ReturnInstance.VelocityY = BitConverter.ToSingle(BAM.NextBytes(4), 0);
                ReturnInstance.VelocityZ = BitConverter.ToSingle(BAM.NextBytes(4), 0);

                //Get forward direction X,Y,Z
                ReturnInstance.ForwardDirectionX = BitConverter.ToInt16(BAM.NextBytes(2), 0);
                ReturnInstance.ForwardDirectionY = BitConverter.ToInt16(BAM.NextBytes(2), 0);
                ReturnInstance.ForwardDirectionZ = BitConverter.ToInt16(BAM.NextBytes(2), 0);

                //Get right direction X,Y,Z
                ReturnInstance.RightDirectionX = BitConverter.ToInt16(BAM.NextBytes(2), 0);
                ReturnInstance.RightDirectionY = BitConverter.ToInt16(BAM.NextBytes(2), 0);
                ReturnInstance.RightDirectionZ = BitConverter.ToInt16(BAM.NextBytes(2), 0);

                //Get G Forces
                ReturnInstance.gForceLateral      = BitConverter.ToSingle(BAM.NextBytes(4), 0);
                ReturnInstance.gForceLongitudinal = BitConverter.ToSingle(BAM.NextBytes(4), 0);
                ReturnInstance.gForceVertical     = BitConverter.ToSingle(BAM.NextBytes(4), 0);

                //Get Yaw, Pitch, Role
                ReturnInstance.Yaw   = BitConverter.ToSingle(BAM.NextBytes(4), 0);
                ReturnInstance.Pitch = BitConverter.ToSingle(BAM.NextBytes(4), 0);
                ReturnInstance.Roll  = BitConverter.ToSingle(BAM.NextBytes(4), 0);

                return(ReturnInstance);
            }
 private static void AddAcceleration(ref CarMotionData data, SimulatorDataSet simData)
 {
     simData.PlayerInfo.CarInfo.Acceleration.XinG = data.MGForceLateral;
     simData.PlayerInfo.CarInfo.Acceleration.YinG = data.MGForceVertical;
     simData.PlayerInfo.CarInfo.Acceleration.ZinG = data.MGForceLongitudinal;
 }
        public override void LoadBytes(byte[] bytes)
        {
            ByteArrayManager BAM = new ByteArrayManager(bytes);

            //Update the header.
            base.LoadBytes(BAM.NextBytes(24));



            //Create car motion data
            int t = 1;
            List <CarMotionData> AllCarData = new List <CarMotionData>();

            for (t = 1; t <= 22; t++)
            {
                CarMotionData thiscardata = CarMotionData.Create(BAM.NextBytes(60));
                AllCarData.Add(thiscardata);
            }
            FieldMotionData = AllCarData.ToArray();


            //Get suspension position
            SuspensionPosition            = new WheelDataArray();
            SuspensionPosition.RearLeft   = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            SuspensionPosition.RearRight  = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            SuspensionPosition.FrontLeft  = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            SuspensionPosition.FrontRight = BitConverter.ToSingle(BAM.NextBytes(4), 0);

            //Get suspension velocity
            SuspensionVelocity            = new WheelDataArray();
            SuspensionVelocity.RearLeft   = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            SuspensionVelocity.RearRight  = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            SuspensionVelocity.FrontLeft  = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            SuspensionVelocity.FrontRight = BitConverter.ToSingle(BAM.NextBytes(4), 0);

            //Get suspension acceleration
            SuspensionAcceleration            = new WheelDataArray();
            SuspensionAcceleration.RearLeft   = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            SuspensionAcceleration.RearRight  = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            SuspensionAcceleration.FrontLeft  = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            SuspensionAcceleration.FrontRight = BitConverter.ToSingle(BAM.NextBytes(4), 0);

            //Get wheel speed
            WheelSpeed            = new WheelDataArray();
            WheelSpeed.RearLeft   = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            WheelSpeed.RearRight  = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            WheelSpeed.FrontLeft  = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            WheelSpeed.FrontRight = BitConverter.ToSingle(BAM.NextBytes(4), 0);

            //Get WheelSlip
            WheelSlip            = new WheelDataArray();
            WheelSlip.RearLeft   = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            WheelSlip.RearRight  = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            WheelSlip.FrontLeft  = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            WheelSlip.FrontRight = BitConverter.ToSingle(BAM.NextBytes(4), 0);

            //Get velocity X,Y,Z
            VelocityX = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            VelocityY = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            VelocityZ = BitConverter.ToSingle(BAM.NextBytes(4), 0);

            //Get angular velocity X,Y,Z
            AngularVelocityX = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            AngularVelocityY = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            AngularVelocityZ = BitConverter.ToSingle(BAM.NextBytes(4), 0);

            //Get angular acceleration X,Y,Z
            AngularAccelerationX = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            AngularAccelerationY = BitConverter.ToSingle(BAM.NextBytes(4), 0);
            AngularAccelerationZ = BitConverter.ToSingle(BAM.NextBytes(4), 0);

            //Get front wheel angle
            FrontWheelAngle = BitConverter.ToSingle(BAM.NextBytes(4), 0);
        }
Beispiel #8
0
        private static IPacket Motion(PacketHeader packetHeader, BinaryReader reader)
        {
            var packetCarMotionData = new PacketMotionData(packetHeader);

            for (int i = 0; i < MaxNumberOfCarsOnTrack; i++)
            {
                var carMotionData = new CarMotionData();

                carMotionData.WorldPositionX = reader.ReadSingle();
                carMotionData.WorldPositionY = reader.ReadSingle();
                carMotionData.WorldPositionZ = reader.ReadSingle();

                carMotionData.WorldVelocityX = reader.ReadSingle();
                carMotionData.WorldVelocityY = reader.ReadSingle();
                carMotionData.WorldVelocityZ = reader.ReadSingle();

                carMotionData.WorldForwardDirX = reader.ReadInt16();
                carMotionData.WorldForwardDirY = reader.ReadInt16();
                carMotionData.WorldForwardDirZ = reader.ReadInt16();

                carMotionData.WorldRightDirX = reader.ReadInt16();
                carMotionData.WorldRightDirY = reader.ReadInt16();
                carMotionData.WorldRightDirZ = reader.ReadInt16();

                carMotionData.GForceLateral      = reader.ReadSingle();
                carMotionData.GForceLongitudinal = reader.ReadSingle();
                carMotionData.GForceVertical     = reader.ReadSingle();

                carMotionData.Yaw   = reader.ReadSingle();
                carMotionData.Pitch = reader.ReadSingle();
                carMotionData.Roll  = reader.ReadSingle();

                packetCarMotionData.CarMotionData[i] = carMotionData;
            }

            // Extra player data
            for (int j = 0; j < NumberOfTyres; j++)
            {
                packetCarMotionData.SuspensionPosition[j] = reader.ReadSingle();
            }

            for (int j = 0; j < NumberOfTyres; j++)
            {
                packetCarMotionData.SuspensionVelocity[j] = reader.ReadSingle();
            }

            for (int j = 0; j < NumberOfTyres; j++)
            {
                packetCarMotionData.SuspensionAcceleration[j] = reader.ReadSingle();
            }

            for (int j = 0; j < NumberOfTyres; j++)
            {
                packetCarMotionData.WheelSpeed[j] = reader.ReadSingle();
            }

            for (int j = 0; j < NumberOfTyres; j++)
            {
                packetCarMotionData.WheelSlip[j] = reader.ReadSingle();
            }

            packetCarMotionData.LocalVelocityX = reader.ReadSingle();
            packetCarMotionData.LocalVelocityY = reader.ReadSingle();
            packetCarMotionData.LocalVelocityZ = reader.ReadSingle();

            packetCarMotionData.AngularVelocityX = reader.ReadSingle();
            packetCarMotionData.AngularVelocityY = reader.ReadSingle();
            packetCarMotionData.AngularVelocityZ = reader.ReadSingle();

            packetCarMotionData.AngularAccelerationX = reader.ReadSingle();
            packetCarMotionData.AngularAccelerationY = reader.ReadSingle();
            packetCarMotionData.AngularAccelerationZ = reader.ReadSingle();

            packetCarMotionData.FrontWheelsAngle = reader.ReadSingle();

            return(packetCarMotionData);
        }