Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix glitches where galaxy/distant planets jiggle during head movement. #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions KerbalVR/KerbalVR_Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,18 +346,21 @@ private void RenderHmdCameras(
*/

// position of the eye in the VR reference frame
Vector3 positionToEye = hmdTransform.pos + hmdTransform.rot * hmdEyeTransform.pos;

// update position of the cameras
Scene.Instance.UpdateScene(eye, hmdTransform, hmdEyeTransform);

// render the set of cameras
for (int i = 0; i < Scene.Instance.NumVRCameras; i++) {

Types.CameraData camData = Scene.Instance.VRCameras[i];
Vector3 positionToEye = hmdTransform.pos + hmdTransform.rot * hmdEyeTransform.pos;
if(camData.IsSkyBox)
positionToEye = hmdTransform.pos;

// set projection matrix
camData.camera.projectionMatrix = (eye == EVREye.Eye_Left) ?
camData.hmdProjectionMatrixL : camData.hmdProjectionMatrixR;
camData.hmdProjectionMatrixL : camData.hmdProjectionMatrixR;

// set texture to render to, then render
camData.camera.targetTexture = hmdEyeRenderTexture;
Expand Down
3 changes: 2 additions & 1 deletion KerbalVR/KerbalVR_DeviceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace KerbalVR
/// </summary>
public class DeviceManager : MonoBehaviour
{
public float ManipulatorSize = 1.0f;

#region Properties
// Manipulator objects
public Manipulator ManipulatorLeft { get; private set; }
Expand All @@ -30,7 +32,6 @@ public class DeviceManager : MonoBehaviour
private GameObject manipulatorRight;
#endregion


#region Singleton
// this is a singleton class, and there must be one DeviceManager in the scene
private static DeviceManager _instance;
Expand Down
45 changes: 41 additions & 4 deletions KerbalVR/KerbalVR_Scene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,52 @@ private void UpdateFlightIvaScene(
Vector3 updatedPosition = DevicePoseToWorld(positionToEye);
Quaternion updatedRotation = DevicePoseToWorld(hmdTransform.rot);

var worldPos = InternalSpace.InternalToWorld(updatedPosition);
var worldRot = InternalSpace.InternalToWorld(updatedRotation);

// in flight, update the internal and flight cameras
InternalCamera.Instance.transform.position = updatedPosition;
InternalCamera.Instance.transform.rotation = updatedRotation;
var ic = InternalCamera.Instance;
if(ic != null)
{
ic.transform.position = updatedPosition;
ic.transform.rotation = updatedRotation;
}

var fc = FlightCamera.fetch;
if(fc != null)
{
fc.transform.position = worldPos;
fc.transform.rotation = worldRot;
}


FlightCamera.fetch.transform.position = InternalSpace.InternalToWorld(InternalCamera.Instance.transform.position);
FlightCamera.fetch.transform.rotation = InternalSpace.InternalToWorld(InternalCamera.Instance.transform.rotation);
var fx = FXCamera.Instance;
if(fx != null)
{
fx.transform.position = worldPos;
fx.transform.rotation = worldRot;
}

var gc = GalaxyCameraControl.Instance;
if(gc != null)
gc.transform.rotation = worldRot;

var sc = ScaledCamera.Instance;
if(sc != null)
sc.transform.rotation = worldRot;

if(galaxyCam == null)
galaxyCam = GameObject.Find("GalaxyCamera");
if(galaxyCam != null)
galaxyCam.transform.rotation = worldRot;

// store the eyeball position
HmdEyePosition[(int)eye] = updatedPosition;
HmdEyeRotation[(int)eye] = updatedRotation;
}

static GameObject galaxyCam = null;

private void UpdateFlightEvaScene(
EVREye eye,
SteamVR_Utils.RigidTransform hmdTransform,
Expand Down Expand Up @@ -392,6 +426,9 @@ private void PopulateCameraList(string[] cameraNames) {
VRCameras[i].hmdProjectionMatrixL = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projectionMatrixL);
VRCameras[i].hmdProjectionMatrixR = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projectionMatrixR);

if(foundCamera.name.Equals("GalaxyCamera") || foundCamera.name.Equals("Camera ScaledSpace"))
VRCameras[i].IsSkyBox = true;

// disable the camera so we can call Render directly
foundCamera.enabled = false;
}
Expand Down
1 change: 1 addition & 0 deletions KerbalVR/KerbalVR_Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Types
// struct to keep track of Camera properties
public struct CameraData
{
public bool IsSkyBox;
public Camera camera;
public Matrix4x4 originalProjectionMatrix;
public Matrix4x4 hmdProjectionMatrixL;
Expand Down