mirror of
https://github.com/thegeneralist01/Scene-Manager-DevRepo
synced 2026-01-11 23:50:29 +01:00
Refactored class into Utils folder
This commit is contained in:
parent
fccb41fd65
commit
794e97554a
1 changed files with 42 additions and 0 deletions
42
SceneManager/Utils/MousePositionInWorld.cs
Normal file
42
SceneManager/Utils/MousePositionInWorld.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
using Rage;
|
||||||
|
|
||||||
|
namespace SceneManager.Utils
|
||||||
|
{
|
||||||
|
internal static class MousePositionInWorld
|
||||||
|
{
|
||||||
|
internal static Vector3 GetPosition { get { return GetMousePositionInWorld(); } }
|
||||||
|
|
||||||
|
internal static Vector3 GetPositionForBarrier { get { return GetMousePositionInWorld(Settings.BarrierPlacementDistance); } }
|
||||||
|
|
||||||
|
private static Vector3 GetMousePositionInWorld(float maxDistance = 100f)
|
||||||
|
{
|
||||||
|
HitResult TracePlayerView(float maxTraceDistance = 100f, TraceFlags flags = TraceFlags.IntersectWorld) => TracePlayerView2(out Vector3 v1, out Vector3 v2, maxTraceDistance, flags);
|
||||||
|
|
||||||
|
HitResult TracePlayerView2(out Vector3 start, out Vector3 end, float maxTraceDistance, TraceFlags flags)
|
||||||
|
{
|
||||||
|
Vector3 direction = GetPlayerLookingDirection(out start);
|
||||||
|
end = start + (maxTraceDistance * direction);
|
||||||
|
return World.TraceLine(start, end, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 GetPlayerLookingDirection(out Vector3 camPosition)
|
||||||
|
{
|
||||||
|
if (Camera.RenderingCamera)
|
||||||
|
{
|
||||||
|
camPosition = Camera.RenderingCamera.Position;
|
||||||
|
return Camera.RenderingCamera.Direction;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float pitch = Rage.Native.NativeFunction.Natives.GET_GAMEPLAY_CAM_RELATIVE_PITCH<float>();
|
||||||
|
float heading = Rage.Native.NativeFunction.Natives.GET_GAMEPLAY_CAM_RELATIVE_HEADING<float>();
|
||||||
|
|
||||||
|
camPosition = Rage.Native.NativeFunction.Natives.GET_GAMEPLAY_CAM_COORD<Vector3>();
|
||||||
|
return (Game.LocalPlayer.Character.Rotation + new Rotator(pitch, 0, heading)).ToVector().ToNormalized();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TracePlayerView(maxDistance, TraceFlags.IntersectWorld).HitPosition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue