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

Commit

Permalink
Added reticle scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
LivingFray committed Jan 15, 2023
1 parent 7e2ec7e commit 3634955
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
4 changes: 4 additions & 0 deletions HellsingerVR/HellsingerVR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class HellsingerVR : BasePlugin
public ConfigEntry<float> SnapTurningAngle;
public ConfigEntry<string> MovementType;
// UI
public ConfigEntry<bool> ReticleFacesCamera;
public ConfigEntry<string> ReticleScaling;
public ConfigEntry<float> MenuUIDistance;
public ConfigEntry<float> GameUIDistance;
public ConfigEntry<string> ReticleLocation;
Expand Down Expand Up @@ -162,6 +164,8 @@ private void SetupConfig()
MenuUIDistance = Config.Bind("UI", "MenuUIDistance", 2.5f, "Distance between the HMD and the menu UIs in meters");
GameUIDistance = Config.Bind("UI", "GameUIDistance", 2.5f, "Distance between the HMD and the game UIs in meters");
ReticleLocation = Config.Bind("UI", "ReticleLocation", "target", "Location of the reticle/beat indicator in the world, valid options are \"target\" (location in world the dominant hand is pointing to), \"head\" (floats a fixed distance in front of the camera), \"sights\" (placed above the weapon in the dominant hand akin to ironsights");
ReticleFacesCamera = Config.Bind("UI", "ReticleFacesCamera", false, "When reticle location is set to target should the reticle always face the camera, or be flat against the surface it hits");
ReticleScaling = Config.Bind("UI", "ReticleScaling", "partial", "How should the reticle's scale change with distance. Options are \"none\" (reticle will always be the same scale) \"partial\" (reticle will grow with distance but still appear smaller at a distance) or \"full\" (reticle will grow with distance such that it always occupies the same percentage of the screen)");
ShowHealthOnHand = Config.Bind("UI", "ShowHealthOnHand", true, "Set to false to show the health bar floating in front of the camera instead of attached to the non dominant hand");
ShowUltimateOnHand = Config.Bind("UI", "ShowUltimateOnHand", true, "Set to false to show the ultimate bar floating in front of the camera instead of attached to the non dominant hand");
ShowFuryOnHand = Config.Bind("UI", "ShowFuryOnHand", true, "Set to false to show the fury meter floating in front of the camera instead of attached to the non dominant hand");
Expand Down
49 changes: 47 additions & 2 deletions HellsingerVR/UI/RhythmIndicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ public class RhythmIndicator

public enum Position { Head, Sights, Target };

public enum Scaling { None, Partial, Full };

public Position position = Position.Target;

public Scaling scaling = Scaling.Partial;

public bool FaceCamera = false;

public float head_distance = 2.5f;

public float target_distance = 10.0f;
public float target_distance = 25.0f;
public float target_offset = 0.25f;

public float head_scale = 1.0f;
Expand Down Expand Up @@ -55,6 +61,23 @@ public void Init()
position = Position.Target;
break;
}

string scalingCfg = HellsingerVR._instance.ReticleScaling.Value.ToLower();

switch (scalingCfg)
{
case "none":
scaling = Scaling.None;
break;
case "full":
scaling = Scaling.Full;
break;
default:
scaling = Scaling.Partial;
break;
}

FaceCamera = HellsingerVR._instance.ReticleFacesCamera.Value;
}

public void Update()
Expand Down Expand Up @@ -142,13 +165,35 @@ private void Update_Target()
OutNormal = rotation * Vector3.back;
}

if (FaceCamera)
{
OutNormal = rotation * Vector3.back;
}

Vector3 direction = (OutPoint - location).normalized;

RhythmIndicatorTrans.position = OutPoint - (direction * target_offset);

RhythmIndicatorTrans.LookAt(OutPoint - OutNormal);

FixOtherUIElements(target_scale);
float Distance = (OutPoint - location).magnitude / head_distance;

float scaleModifier = 1.0f;

switch (scaling)
{
case Scaling.None:
scaleModifier = 1.0f;
break;
case Scaling.Partial:
scaleModifier = Mathf.Sqrt(Distance);
break;
case Scaling.Full:
scaleModifier = Distance;
break;
}

FixOtherUIElements(target_scale * scaleModifier);
}

private void FixOtherUIElements(float scale)
Expand Down

0 comments on commit 3634955

Please sign in to comment.