Browse Source

Reworked coordinate and rotation conversion from Quake to Unity. It still feels weird, but entity models are now seemingly oriented correctly, and some strange edge cases with entities rotating in the wrong direction have been cleared up.

console
Nico de Poel 5 years ago
parent
commit
a479d7246b
  1. 8
      Assets/Scripts/Data/QExtensions.cs
  2. 8
      Assets/Scripts/Modules/RenderModule.cs

8
Assets/Scripts/Data/QExtensions.cs

@ -48,16 +48,18 @@ public static class QExtensions
public static Vector3 ToUnity(this Vector3 vec) public static Vector3 ToUnity(this Vector3 vec)
{ {
return new Vector3(vec.x, vec.z, vec.y);
return new Vector3(vec.y, vec.z, -vec.x);
} }
public static Vector3 ToUnityPosition(this QVec3 origin) public static Vector3 ToUnityPosition(this QVec3 origin)
{ {
return new Vector3(origin.x, origin.z, origin.y);
return new Vector3(origin.y, origin.z, -origin.x);
} }
public static Quaternion ToUnityRotation(this QVec3 angles) public static Quaternion ToUnityRotation(this QVec3 angles)
{ {
return Quaternion.Euler(angles.x, -angles.y, -angles.z);
return Quaternion.AngleAxis(-angles.y, Vector3.up)
* Quaternion.AngleAxis(angles.x, Vector3.right)
* Quaternion.AngleAxis(angles.z, Vector3.forward);
} }
} }

8
Assets/Scripts/Modules/RenderModule.cs

@ -74,8 +74,12 @@ public partial class RenderModule
if (cam == null) if (cam == null)
return; return;
angles.y -= 90; // Don't know why this correction is necessary
// Don't know exactly why this correction is necessary.
// Mixing Quake and Unity's coordinate systems creates a bit of a mess. With the current set of conversions
// we at least get everything to look right in every case I've tested, but it still seems a bit off somehow.
angles.y += 180;
angles.z = -angles.z;
cam.transform.position = origin.ToUnityPosition(); cam.transform.position = origin.ToUnityPosition();
cam.transform.rotation = angles.ToUnityRotation(); cam.transform.rotation = angles.ToUnityRotation();
} }

Loading…
Cancel
Save