Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class CameraSimulationSettingsDrawer : PropertyDrawer

private readonly GUIContent moveSpeedContent = new GUIContent("Speed");
private readonly GUIContent moveSmoothingContent = new GUIContent("Smoothed");
private readonly GUIContent frameRateIndependentContent = new GUIContent("Frame Rate Independent");
private readonly GUIContent moveDepthContent = new GUIContent("Depth");
private readonly GUIContent moveHorizontalContent = new GUIContent("Horizontal");
private readonly GUIContent moveVerticalContent = new GUIContent("Vertical");
Expand Down Expand Up @@ -78,6 +79,7 @@ public override void OnGUI(

SerializedProperty moveSpeed = property.FindPropertyRelative("moveSpeed");
SerializedProperty moveSmoothing = property.FindPropertyRelative("isMovementSmoothed");
SerializedProperty frameRateIndependent = property.FindPropertyRelative("isFrameRateIndependent");
SerializedProperty moveDepth = property.FindPropertyRelative("moveDepth");
SerializedProperty moveHorizontal = property.FindPropertyRelative("moveHorizontal");
SerializedProperty moveVertical = property.FindPropertyRelative("moveVertical");
Expand All @@ -97,6 +99,13 @@ public override void OnGUI(
++rowMultiplier,
PropertyDrawerUtilities.Height),
moveSpeed, moveSpeedContent);
EditorGUI.PropertyField(
PropertyDrawerUtilities.GetPosition(
position,
PropertyDrawerUtilities.VerticalSpacing,
++rowMultiplier,
PropertyDrawerUtilities.Height),
frameRateIndependent, frameRateIndependentContent);
EditorGUI.PropertyField(
PropertyDrawerUtilities.GetPosition(
position,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ public bool IsMovementSmoothed
set => isMovementSmoothed = value;
}

[SerializeField]
[Tooltip("Multiply resulting speed with deltaTime?")]
private bool isFrameRateIndependent = true;

/// <summary>
/// Multiply resulting speed with deltaTime?
/// </summary>
public bool IsFrameRateIndependent
{
get => isFrameRateIndependent;
set => isFrameRateIndependent = value;
}

[SerializeField]
[Tooltip("The input action used to move the camera along the depth axis.")]
private InputActionReference moveDepth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,31 +116,50 @@ public void ResetToOrigin()
/// <param name="isSmoothed">Should smoothing be applied to camera movement?</param>
/// <param name="moveSpeed">Multiplier used to adjust how fast the camera moves.</param>
/// <param name="rotationSensitivity">Multiplier used to adjust the sensitivity of the camera rotation.</param>
/// <param name="frameRateIndependent">Multiply resulting speed with deltaTime?</param>
public void Update(
Vector3 moveDelta,
Vector3 rotationDelta,
bool isSmoothed = true,
float moveSpeed = 1f,
float rotationSensitivity = 1f)
float rotationSensitivity = 1f,
bool frameRateIndependent = true)
{
using (UpdatePerfMarker.Auto())
{
if (simulatedHmd == null) { return; }

// Perform smoothing on move delta.
if (frameRateIndependent)
{
smoothedMoveDelta = isSmoothed ?
Smoothing.SmoothTo(smoothedMoveDelta, moveDelta, moveSmoothingTime, Time.deltaTime) :
100f * Time.deltaTime * moveDelta;
}
// Yes; this isn't framerate independent. However; there's currently a Unity editor bug
// wherein the *polling rate* of your mouse can cause severe lagspikes in the
// editor; this causes deltaTimes to go all over the place while moving your mouse.
// Using fixedDeltaTime is a good workaround until this bug is resolved.
smoothedMoveDelta = isSmoothed ?
Smoothing.SmoothTo(smoothedMoveDelta, moveDelta, moveSmoothingTime, Time.fixedDeltaTime) :
moveDelta;

else
{
smoothedMoveDelta = isSmoothed ?
Smoothing.SmoothTo(smoothedMoveDelta, moveDelta, moveSmoothingTime, Time.fixedDeltaTime) :
moveDelta;
}

simulatedHmdState.trackingState = (int)(InputTrackingState.Position | InputTrackingState.Rotation);

// HMD poses are relative to the camera floor offset.
Transform origin = PlayspaceUtilities.XROrigin.CameraFloorOffsetObject.transform;
Vector3 cameraPosition = simulatedHmdState.centerEyePosition + Quaternion.Inverse(origin.rotation) * Camera.main.transform.rotation * (smoothedMoveDelta * moveSpeed);
Vector3 cameraPosition = simulatedHmdState.centerEyePosition;
if (frameRateIndependent)
{
cameraPosition += Quaternion.Inverse(origin.rotation) * Camera.main.transform.rotation * (1000f * moveSpeed * Time.deltaTime * smoothedMoveDelta);
}
else
{
cameraPosition += Quaternion.Inverse(origin.rotation) * Camera.main.transform.rotation * (smoothedMoveDelta * moveSpeed);
}

// Update camera rotation
cameraRotation += rotationDelta * rotationSensitivity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ private void UpdateSimulatedHMD()
rotationDelta,
CameraSettings.IsMovementSmoothed,
CameraSettings.MoveSpeed,
CameraSettings.RotationSensitivity);
CameraSettings.RotationSensitivity,
CameraSettings.IsFrameRateIndependent);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ MonoBehaviour:
simulationEnabled: 1
originOffset: {x: 0, y: 0, z: 0}
isMovementSmoothed: 1
isFrameRateIndependent: 1
moveDepth: {fileID: 7299012687604269993, guid: 70b361cf3c037d54896482d1ffd9f999, type: 3}
moveHorizontal: {fileID: 8718149717473967433, guid: 70b361cf3c037d54896482d1ffd9f999, type: 3}
moveVertical: {fileID: 8557015737124631664, guid: 70b361cf3c037d54896482d1ffd9f999, type: 3}
Expand All @@ -61,6 +62,7 @@ MonoBehaviour:
invertPitch: 0
eyeGazeSettings:
simulationEnabled: 1
isTracked: 1
eyeOriginOffset: {x: 0, y: 0, z: 0}
lookHorizontal: {fileID: -7345170528461143681, guid: 70b361cf3c037d54896482d1ffd9f999, type: 3}
lookVertical: {fileID: -4223466768389085971, guid: 70b361cf3c037d54896482d1ffd9f999, type: 3}
Expand Down