using UnityEngine; namespace Telemetry { [System.Serializable] public class TelemetryData { /// /// Forward speed in m/s /// public float speed; /// /// Local space acceleration in m/s/s /// public float accelerationX, accelerationY, accelerationZ; public float accZ; /// /// Local space angular speed in degrees/s /// public float angularSpeedX, angularSpeedY, angularSpeedZ; /// /// Local space rotation in degrees /// public float rotationX, rotationY, rotationZ; #region States /// /// TRUE when game is paused /// public bool paused; /// /// when FALSE, bike is out of track and shakes /// public bool onTrack; public int gear; public int rpm; #endregion #region events /// /// event, TRUE when collecting a pickup /// public bool collectPickup; /// /// event, TRUE when starting turbo /// public bool turbo; /// /// event, TRUE when starting engine /// public bool startEngine; /// /// event, TRUE when stoping engine /// public bool stopEngine; /// /// event, TRUE when a collision happens /// public bool collision; public float collisionAngle; #endregion float STEP = 0.01f; public void UpdateRotation(Vector3 a, float dt) { //ensure our angle is between -180 and 180 Vector3 angles = a; if (angles.x > 180) angles.x -= 360; if (angles.y > 180) angles.y -= 360; if (angles.z > 180) angles.z -= 360; angularSpeedX = STEP * Mathf.RoundToInt((angles.x - rotationX) / dt / STEP); angularSpeedY = STEP * Mathf.RoundToInt((angles.y - rotationY) / dt / STEP); angularSpeedZ = STEP * Mathf.RoundToInt((angles.z - rotationZ) / dt / STEP); rotationX = STEP * Mathf.RoundToInt(angles.x / STEP); rotationY = STEP * Mathf.RoundToInt(angles.y / STEP); rotationZ = STEP * Mathf.RoundToInt(angles.z / STEP); } public void UpdateSpeed(float s, Vector3 acceleration, float dt) { accelerationX = STEP * Mathf.RoundToInt(acceleration.x / STEP); accelerationY = STEP * Mathf.RoundToInt(acceleration.y / STEP); accelerationZ = STEP * Mathf.RoundToInt(acceleration.z / STEP); speed = s; } public override string ToString() { string tmp = "speed=" + speed; tmp += "\n\naccelerationX=" + accelerationX; tmp += "\naccelerationY=" + accelerationY; tmp += "\naccelerationZ=" + accelerationZ; tmp += "\n\nrotationX=" + rotationX; tmp += "\nrotationY=" + rotationY; tmp += "\nrotationZ=" + rotationZ; tmp += "\nangularSpeedX=" + angularSpeedX; tmp += "\nangularSpeedY=" + angularSpeedY; tmp += "\nangularSpeedZ=" + angularSpeedZ; return tmp; } public void ClearEvents() { startEngine = false; stopEngine = false; collision = false; collisionAngle = 0; collectPickup = false; turbo = false; } } }