Reformat codef

This commit is contained in:
GoaLitiuM
2021-06-28 16:22:20 +03:00
parent c7369d94b5
commit 6c5965e959
19 changed files with 2964 additions and 2926 deletions

View File

@@ -4,118 +4,118 @@ using System.Diagnostics;
namespace Game
{
public class CameraMovement : Script
{
[Limit(0, 9000), Tooltip("Camera speed")]
public float MoveSpeed { get; set; } = 400;
public class CameraMovement : Script
{
[Limit(0, 9000), Tooltip("Camera speed")]
public float MoveSpeed { get; set; } = 400;
private float _pitch;
private float _yaw;
private float _pitch;
private float _yaw;
private float xAxis;
private float yAxis;
private float inputH;
private float inputV;
private float xAxis;
private float yAxis;
private float inputH;
private float inputV;
private InputEvent onExit = new InputEvent("Exit");
private InputEvent onExit = new InputEvent("Exit");
public override void OnAwake()
{
base.OnAwake();
onExit.Triggered += () =>
{
if (Console.IsSafeToQuit)
Engine.RequestExit();
};
}
onExit.Triggered += () =>
{
if (Console.IsSafeToQuit)
Engine.RequestExit();
};
}
public override void OnDestroy()
{
base.OnDestroy();
onExit.Dispose();
onExit.Dispose();
}
public override void OnStart()
{
var initialEulerAngles = Actor.Orientation.EulerAngles;
_pitch = initialEulerAngles.X;
_yaw = initialEulerAngles.Y;
}
public override void OnStart()
{
var initialEulerAngles = Actor.Orientation.EulerAngles;
_pitch = initialEulerAngles.X;
_yaw = initialEulerAngles.Y;
}
public override void OnUpdate()
{
var camTrans = Actor.Transform;
public override void OnUpdate()
{
var camTrans = Actor.Transform;
xAxis = InputManager.GetAxis("Mouse X");
yAxis = InputManager.GetAxis("Mouse Y");
xAxis = InputManager.GetAxis("Mouse X");
yAxis = InputManager.GetAxis("Mouse Y");
if (xAxis != 0.0f || yAxis != 0.0f)
{
_pitch += yAxis;
_yaw += xAxis;
if (xAxis != 0.0f || yAxis != 0.0f)
{
_pitch += yAxis;
_yaw += xAxis;
camTrans.Orientation = Quaternion.Euler(_pitch, _yaw, 0);
}
camTrans.Orientation = Quaternion.Euler(_pitch, _yaw, 0);
}
inputH = InputManager.GetAxis("Horizontal");
inputV = InputManager.GetAxis("Vertical");
var move = new Vector3(inputH, 0.0f, inputV);
inputH = InputManager.GetAxis("Horizontal");
inputV = InputManager.GetAxis("Vertical");
var move = new Vector3(inputH, 0.0f, inputV);
if (!move.IsZero)
{
move.Normalize();
move = camTrans.TransformDirection(move) * MoveSpeed;
{
Vector3 delta = move * Time.UnscaledDeltaTime;
float movementLeft = delta.Length;
if (!move.IsZero)
{
move.Normalize();
move = camTrans.TransformDirection(move) * MoveSpeed;
// TODO: check multiple times in case we get stuck in walls
{
Vector3 delta = move * Time.UnscaledDeltaTime;
float movementLeft = delta.Length;
float sphereRadius = 10.0f; // TODO: use collider radius
RayCastHit[] hitInfos;
float moveDist = delta.Length;
Physics.SphereCastAll(Actor.Transform.Translation, sphereRadius, move.Normalized, out hitInfos, moveDist);
// TODO: check multiple times in case we get stuck in walls
//bool nohit = true;
float hitDistance = moveDist;
Vector3 hitNormal = move.Normalized;
foreach (RayCastHit hitInfo in hitInfos)
{
if (hitInfo.Collider.Parent == Parent)
continue;
float sphereRadius = 10.0f; // TODO: use collider radius
RayCastHit[] hitInfos;
float moveDist = delta.Length;
Physics.SphereCastAll(Actor.Transform.Translation, sphereRadius, move.Normalized, out hitInfos,
moveDist);
if (hitInfo.Distance < hitDistance)
{
hitDistance = hitInfo.Distance;
hitNormal = hitInfo.Normal;
}
//nohit = false;
//break;
}
//bool nohit = true;
float hitDistance = moveDist;
Vector3 hitNormal = move.Normalized;
foreach (RayCastHit hitInfo in hitInfos)
{
if (hitInfo.Collider.Parent == Parent)
continue;
if (hitDistance != moveDist)
{
//camTrans.Translation = Vector3.Lerp(Actor.Transform.Translation, camTrans.Translation, hitDistance);
if (hitInfo.Distance < hitDistance)
{
hitDistance = hitInfo.Distance;
hitNormal = hitInfo.Normal;
}
//nohit = false;
//break;
}
//projected = normal * dot(direction, normal);
//direction = direction - projected
if (hitDistance != moveDist)
{
//camTrans.Translation = Vector3.Lerp(Actor.Transform.Translation, camTrans.Translation, hitDistance);
//projected = normal * dot(direction, normal);
//direction = direction - projected
//camTrans.Translation += hitNormal * (moveDist - hitDistance); // correct?
//camTrans.Translation = hitNormal * (move * hitNormal); // correct?
//camTrans.Translation = Actor.Transform.Translation;
delta += -Vector3.Dot(delta, hitNormal) * hitNormal; // correct?
}
//camTrans.Translation += hitNormal * (moveDist - hitDistance); // correct?
//camTrans.Translation = hitNormal * (move * hitNormal); // correct?
//camTrans.Translation = Actor.Transform.Translation;
delta += -Vector3.Dot(delta, hitNormal) * hitNormal; // correct?
}
camTrans.Translation += delta;
}
}
camTrans.Translation += delta;
}
}
Actor.Transform = camTrans;
}
}
}
Actor.Transform = camTrans;
}
}
}