Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Fixed a NRE when using hand oriented movement
Browse files Browse the repository at this point in the history
  • Loading branch information
LivingFray committed Jan 24, 2023
1 parent 95f347f commit a9a1675
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 27 deletions.
53 changes: 29 additions & 24 deletions HellsingerVR/Components/VRInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void LateUpdate()
}
catch (Exception e)
{
HellsingerVR._instance.Log.LogError(e.Message);
HellsingerVR._instance.Log.LogError(e.ToString());
}
InputSystem.QueueEvent(ptr);

Expand Down Expand Up @@ -221,34 +221,34 @@ private void UpdateGameInputs(InputEventPtr ptr)
#region Input Converter functions
private Vector2 GetMenuVector()
{
SteamVR_Action_Vector2 input = SteamVR_Input.GetVector2Action("menu", "Navigate", true);
SteamVR_Action_Vector2 input = SteamVR_Input.GetVector2Action("menu", "Navigate");

return input.GetAxis(SteamVR_Input_Sources.Any);
}

private float GetMenuSelect()
{
return SteamVR_Input.GetBooleanAction("menu", "Select", true).state ? 1.0f : 0.0f;
return SteamVR_Input.GetBooleanAction("menu", "Select").state ? 1.0f : 0.0f;
}

private float GetMenuBack()
{
return SteamVR_Input.GetBooleanAction("menu", "Back", true).state ? 1.0f : 0.0f;
return SteamVR_Input.GetBooleanAction("menu", "Back").state ? 1.0f : 0.0f;
}

private float GetMenuPrevTab()
{
return SteamVR_Input.GetBooleanAction("menu", "PrevTab", true).state ? 1.0f : 0.0f;
return SteamVR_Input.GetBooleanAction("menu", "PrevTab").state ? 1.0f : 0.0f;
}

private float GetMenuNextTab()
{
return SteamVR_Input.GetBooleanAction("menu", "NextTab", true).state ? 1.0f : 0.0f;
return SteamVR_Input.GetBooleanAction("menu", "NextTab").state ? 1.0f : 0.0f;
}

private float GetMenuClose()
{
return SteamVR_Input.GetBooleanAction("menu", "CloseMenu", true).state ? 1.0f : 0.0f;
return SteamVR_Input.GetBooleanAction("menu", "CloseMenu").state ? 1.0f : 0.0f;
}


Expand All @@ -257,12 +257,17 @@ private Vector2 GetMovementVector()
{
SteamVR_Action_Vector2 input = SteamVR_Input.GetVector2Action("game", "Movement", true);

float rotation = (AlignToHead ?
HellsingerVR.rig.head.rotation :
UseLeftHand ?
HellsingerVR.rig.leftHand.rotation :
HellsingerVR.rig.rightHand.rotation
).eulerAngles.y;
Quaternion rotationQuat;

if (AlignToHead)
{
rotationQuat = HellsingerVR.rig.head.rotation;
}
else
{
rotationQuat = GetHandTransform(UseLeftHand).Item2;
}
float rotation = rotationQuat.eulerAngles.y;

if (HellsingerVR.rig.PlayerTransform)
{
Expand All @@ -277,7 +282,7 @@ private float GetLookValue()
if (UseSnapTurn)
{
const float Deadzone = 0.25f;
float Val = SteamVR_Input.GetVector2Action("game", "Look", true).axis.x;
float Val = SteamVR_Input.GetVector2Action("game", "Look").axis.x;

HasPendingSnapMove = false;

Expand All @@ -292,23 +297,23 @@ private float GetLookValue()
}
return 0.0f;
}
return SteamVR_Input.GetVector2Action("game", "Look", true).axis.x;
return SteamVR_Input.GetVector2Action("game", "Look").axis.x;
}

private float GetDashing()
{
return SteamVR_Input.GetBooleanAction("game", "Dash", true).state ? 1.0f : 0.0f;
return SteamVR_Input.GetBooleanAction("game", "Dash").state ? 1.0f : 0.0f;
}

private float GetJumping()
{
return SteamVR_Input.GetBooleanAction("game", "Jump", true).state ? 1.0f : 0.0f;
return SteamVR_Input.GetBooleanAction("game", "Jump").state ? 1.0f : 0.0f;
}

private float GetShooting()
{
SteamVR_Action_Boolean fireAction = SteamVR_Input.GetBooleanAction("game", "Shoot", true);
SteamVR_Action_Boolean altFireAction = SteamVR_Input.GetBooleanAction("game", "ShootAlt", true);
SteamVR_Action_Boolean fireAction = SteamVR_Input.GetBooleanAction("game", "Shoot");
SteamVR_Action_Boolean altFireAction = SteamVR_Input.GetBooleanAction("game", "ShootAlt");


bool Shooting = fireAction.state;
Expand Down Expand Up @@ -341,25 +346,25 @@ private float GetShooting()

private float GetUltimate()
{
bool Shooting = SteamVR_Input.GetBooleanAction("game", "Shoot", true).state;
bool AltShooting = SteamVR_Input.GetBooleanAction("game", "ShootAlt", true).state;
bool Shooting = SteamVR_Input.GetBooleanAction("game", "Shoot").state;
bool AltShooting = SteamVR_Input.GetBooleanAction("game", "ShootAlt").state;

return Shooting && AltShooting ? 1.0f : 0.0f;
}

private float GetSlaughtering()
{
return SteamVR_Input.GetBooleanAction("game", "Slaughter", true).state ? 1.0f : 0.0f;
return SteamVR_Input.GetBooleanAction("game", "Slaughter").state ? 1.0f : 0.0f;
}

private float GetReloading()
{
return SteamVR_Input.GetBooleanAction("game", "Reload", true).state ? 1.0f : 0.0f;
return SteamVR_Input.GetBooleanAction("game", "Reload").state ? 1.0f : 0.0f;
}

private float GetPausing()
{
return SteamVR_Input.GetBooleanAction("game", "OpenMenu", true).state ? 1.0f : 0.0f;
return SteamVR_Input.GetBooleanAction("game", "OpenMenu").state ? 1.0f : 0.0f;
}
#endregion
}
Expand Down
2 changes: 0 additions & 2 deletions HellsingerVR/Components/VRRig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ namespace HellsingerVR.Components
public class VRRig : MonoBehaviour
{
public Transform head;
public Transform leftHand;
public Transform rightHand;
public SteamVR_Camera vrCamera;
public Camera camera;

Expand Down
38 changes: 37 additions & 1 deletion SteamVR_IL2CPP/Scripts/SteamVR_CameraMask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,43 @@ public static Mesh CreateHiddenAreaMesh(HiddenAreaMesh_t src, VRTextureBounds_t
{
if (src.unTriangleCount == 0u)
{
return null;
float uMin = (2f * bounds.uMin) - 1f;
float uMax = (2f * bounds.uMax) - 1f;
float vMin = (2f * bounds.vMin) - 1f;
float vMax = (2f * bounds.vMax) - 1f;

Vector3[] verts = new Vector3[] {
// Left
new Vector3(-1, vMin, 0),
new Vector3(uMin, vMin, 0),
new Vector3(-1, vMax, 0),
new Vector3(uMin, vMax, 0),
// Right
new Vector3(uMax, vMin, 0),
new Vector3(1, vMin, 0),
new Vector3(uMax, vMax, 0),
new Vector3(1, vMax, 0)
};

int[] tris = new int[12]
{
// lower left triangle
0, 2, 1,
// upper right triangle
2, 3, 1,

// lower left triangle
4, 6, 5,
// upper right triangle
6, 7, 5,
};

// Force the sides to not render
Mesh m2 = new Mesh();
m2.vertices = verts;
m2.triangles = tris;
m2.bounds = new Bounds(Vector3.zero, new Vector3(float.MaxValue, float.MaxValue, float.MaxValue));
return m2;
}
float[] array = new float[src.unTriangleCount * 3u * 2u];
Marshal.Copy(src.pVertexData, array, 0, array.Length);
Expand Down

0 comments on commit a9a1675

Please sign in to comment.