Esempio n. 1
0
 public             UInt32[] spare;     //(4*3=12-byte) reserved for future use                                       @unit _                                      @version 0x0100 */
 public RDB_OBJECT_STATE_EXT_t(RDB_COORD_t speed, RDB_COORD_t accel, float traveledDist, UInt32[] spare)
 {
     this.speed        = speed;
     this.accel        = accel;
     this.traveledDist = traveledDist;
     this.spare        = spare;
 }
Esempio n. 2
0
        public void UpdateState(int i, int n)
        {
            RDB_COORD_t pos = data_deserialized[n].object_state.Base.pos;
            RDB_COORD_t v   = data_deserialized[n].object_state.ext.speed;

            CurrentPos[i] = new Vector3(Convert.ToSingle(-pos.y), Convert.ToSingle(pos.z), Convert.ToSingle(pos.x));
            NewVel[i]     = new Vector3(Convert.ToSingle(-v.y), Convert.ToSingle(v.z), Convert.ToSingle(v.x));
            float factor = 180 / Mathf.PI;

            if (CurrentPos[i] != Vector3.zero)
            {
                diff = CurrentPos[i] - LatestPos[i];
                players[i].transform.rotation = Quaternion.Euler(new Vector3(pos.p * factor, -pos.h * factor, -pos.r * factor));
                players[i].transform.position = CurrentPos[i];
                //Debug.Log("Elapsed:" + (stopWatch1.Elapsed.Milliseconds)/1000f);
                //targetPos = CurrentPos[i] + NewVel[i] * (Time.fixedDeltaTime-(stopWatch1.Elapsed.Milliseconds)/1000);
                //players[i].transform.position = Vector3.Lerp(CurrentPos[i], targetPos, Time.fixedDeltaTime * 5f);
                //Debug.Log("True position:" + CurrentPos[i] + "frameNo:" + data_deserialized[n].msg_hdr.frameNo);
                LastFrame[i] = data_deserialized[n].msg_hdr.frameNo;
            }

            // Update wheel steering angle
            GameObject Wheel_Hub, Wheel;

            for (int k = 0; k < 4; k++)
            {
                float y = data_deserialized[n].wheel[k].Base.steeringAngle * factor;
                float x = data_deserialized[n].wheel[k].Base.rotAngle * factor;
                Wheel_Hub = players[i].transform.GetChild(1).GetChild(k).gameObject;
                Wheel     = players[i].gameObject.transform.GetChild(5).GetChild(k).gameObject;
                Wheel.transform.localRotation = Quaternion.Euler(new Vector3(x, -y, 0));
                WheelCollider Wheel_collider = Wheel_Hub.GetComponent <WheelCollider>();
                Wheel_collider.steerAngle = -y;
            }
        }
Esempio n. 3
0
        public byte[] PacketizeMessage()
        {
            m_serialization.msg_hdr                    = new RDB_MSG_HDR_t(35712, 0x011e, 24, 448, ++counter, SimTime);
            m_serialization.start_of_frame             = new RDB_MSG_ENTRY_HDR_t(16, 0, 0, 1, 0);
            m_serialization.msg_entry_hdr_object_state = new RDB_MSG_ENTRY_HDR_t(16, 208, 208, 9, 0x01);
            m_serialization.msg_entry_hdr_wheel        = new RDB_MSG_ENTRY_HDR_t(16, 176, 44, 14, 0);
            m_serialization.end_of_frame               = new RDB_MSG_ENTRY_HDR_t(16, 0, 0, 2, 0);

            RDB_GEOMETRY_t geo   = new RDB_GEOMETRY_t(4.6f, 1.86f, 1.6f, 0.8f, 0.0f, 0.3f);
            RDB_COORD_t    pos   = new RDB_COORD_t(Pos.z, -Pos.x, Pos.y, -transform.eulerAngles.y / 180f * Mathf.PI, transform.eulerAngles.x / 180f * Mathf.PI, -transform.eulerAngles.z / 180f * Mathf.PI, 0x01 | 0x02, 0, 0);
            RDB_COORD_t    speed = new RDB_COORD_t(Vel.z, -Vel.x, Vel.y, -localangularvelocity.y, localangularvelocity.x, -localangularvelocity.z, 0x01 | 0x02, 0, 0);

            RDB_OBJECT_STATE_BASE_t object_base = new RDB_OBJECT_STATE_BASE_t(id, 1, 1, 0x06, ClientName, geo, pos, 0, 0, 0);
            RDB_COORD_t             accel       = new RDB_COORD_t(0.0D, 0.0D, 0.0D, 0.0f, 0.0f, 0.0f, 0x01, 0, 0);
            RDB_OBJECT_STATE_EXT_t  object_ext  = new RDB_OBJECT_STATE_EXT_t(speed, accel, 1.0f, spare);

            m_serialization.object_state = new RDB_OBJECT_STATE_t(object_base, object_ext);

            Vector4 steeringAngle = new Vector4(-m_Car.CurrentSteerAngle / 180 * Mathf.PI, -m_Car.CurrentSteerAngle / 180 * Mathf.PI, 0, 0);

            for (int k = 0; k < 4; k++)
            {
                RDB_WHEEL_BASE_t wheel_base = new RDB_WHEEL_BASE_t(id, (byte)k, 0, spare0, 1.0f, -0.025f, rotAngle, 0.0f, steeringAngle[k], spare1);
                m_serialization.wheel[k] = new RDB_WHEEL_t(wheel_base);
            }

            data_serialized = m_serialization.Serialize();
            return(data_serialized);
        }
Esempio n. 4
0
        public void Spawning()
        {
            for (int n = 0; n < data_deserialized.GetLength(0); n++)
            {
                UInt32 id = data_deserialized[n].object_state.Base.id;
                if (m_serialization.flag_vires == true)
                {
                    if (id == ID_UnityPlayer1 || id == ID_UnityPlayer2) // ID for unity vechiles
                    {
                        continue;
                    }
                }
                if (id == 0)
                {
                    break;
                }

                if (!guests.Contains(id))
                {
                    guests.Add(id); // add new player
                    Debug.Log("Add new player with Id:" + id);
                    RDB_COORD_t p = data_deserialized[n].object_state.Base.pos;
                    m_guest.SpawnLocation = new Vector3(Convert.ToSingle(-p.y), Convert.ToSingle(p.z), Convert.ToSingle(p.x));
                    Debug.Log("position:" + m_guest.SpawnLocation);
                    players[j] = m_guest.SpawnVechile(type);
                    DontDestroyOnLoad(players[j]);
                    float factor = 180 / Mathf.PI;
                    players[j].transform.rotation = Quaternion.Euler(new Vector3(p.p * factor, -p.h * factor, p.r * factor));;
                    j += 1;
                }
                else
                {
                    for (int i = 0; i < guests.Count; i++)
                    {
                        if (guests[i].Equals(id))
                        {
                            LatestPos[i] = players[i].transform.position;
                            if (LastFrame[i] < data_deserialized[n].msg_hdr.frameNo)
                            {
                                Debug.Log("The frame number is right in order");
                                UpdateState(i, n);
                            }
                            else if (LastFrame[i] == data_deserialized[n].msg_hdr.frameNo)
                            {
                                Debug.Log("There is no message recieved in this frame");
                                PredictPosition(i);
                            }
                            else if (LastFrame[i] > data_deserialized[n].msg_hdr.frameNo)
                            {
                                Debug.Log("The frame number is out of order");
                            }
                        }
                        break;
                    }
                }
            }
        }
Esempio n. 5
0
        public UInt16         cfgModelId; //(2-byte) visual model ID

        public RDB_OBJECT_STATE_BASE_t(UInt32 id, Byte category, Byte type, UInt16 visMask, char[] name, RDB_GEOMETRY_t geo, RDB_COORD_t pos, UInt32 parent, UInt16 cfgFlags, UInt16 cfgModelId)
        {
            this.id         = id;
            this.category   = category;
            this.type       = type;
            this.visMask    = visMask;
            this.name       = name;
            this.geo        = geo;
            this.pos        = pos;
            this.parent     = parent;
            this.cfgFlags   = cfgFlags;
            this.cfgModelId = cfgModelId;
        }