Skip to content

Commit 06f28ff

Browse files
committed
Add a fix for the direct cursor of the InteractionLasers not being scaled independently
This caused it to become really big and in your face when the laser is sticking to something far away and the direct cursor snaps to something much closer.
1 parent bd21b0b commit 06f28ff

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Elements.Core;
2+
using FrooxEngine;
3+
using HarmonyLib;
4+
using MonkeyLoader.Resonite;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Text;
8+
9+
namespace CommunityBugFixCollection
10+
{
11+
[HarmonyPatchCategory(nameof(IndependentlyScaleDirectCursor))]
12+
[HarmonyPatch(typeof(InteractionLaser), nameof(InteractionLaser.UpdateLaserVisual))]
13+
internal sealed class IndependentlyScaleDirectCursor : ResoniteMonkey<IndependentlyScaleDirectCursor>
14+
{
15+
public override IEnumerable<string> Authors => Contributors.Banane9;
16+
17+
public override bool CanBeDisabled => true;
18+
19+
private static void Postfix(InteractionLaser __instance)
20+
{
21+
if (!Enabled || !__instance._directCursorActive.Target.Value)
22+
return;
23+
24+
// This is the same calculation as is done for the actual point, but for the direct one
25+
var localPoint = __instance._directCursorOffset.Target.Value;
26+
var localPointInUserRootPos = __instance.Slot.LocalPointToSpace(in localPoint, __instance.LocalUserRoot.Slot);
27+
var userViewInUserRootPos = __instance.LocalUserRoot.Slot.GlobalPointToLocal(__instance.World.LocalUserViewPosition);
28+
29+
var distanceInUserRoot = MathX.Distance(in localPointInUserRootPos, in userViewInUserRootPos);
30+
var localDistance = __instance.Slot.SpaceScaleToLocal(distanceInUserRoot, __instance.LocalUserRoot.Slot);
31+
32+
var localScaleFactor = !__instance.InputInterface.VR_Active
33+
? localDistance * (__instance.World.LocalUserDesktopFOV / 60f)
34+
: 1f + (0.5f * MathX.Max(0f, localDistance - 1f));
35+
36+
__instance._directCursorRoot.Target.LocalScale = localScaleFactor * float3.One;
37+
38+
// Have to adjust the direct line to the new scale as well
39+
var directLineTargetPos = __instance._directLineMesh.Target.Slot.SpacePointToLocal(__instance._pointSlotPos.Target.Value, __instance.Slot);
40+
__instance._directLineTarget.Target.Value = directLineTargetPos;
41+
__instance._directCursorVisualsVisible.Value = directLineTargetPos.Magnitude > 0.01f;
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)