viewangles refactor, fix view angles wraparound
This commit is contained in:
@@ -85,7 +85,7 @@
|
|||||||
"PositiveButton": 0,
|
"PositiveButton": 0,
|
||||||
"NegativeButton": 0,
|
"NegativeButton": 0,
|
||||||
"DeadZone": 0.0,
|
"DeadZone": 0.0,
|
||||||
"Sensitivity": 0.02,
|
"Sensitivity": 0.022,
|
||||||
"Gravity": 1.0,
|
"Gravity": 1.0,
|
||||||
"Scale": 1.0,
|
"Scale": 1.0,
|
||||||
"Snap": false
|
"Snap": false
|
||||||
@@ -97,7 +97,7 @@
|
|||||||
"PositiveButton": 0,
|
"PositiveButton": 0,
|
||||||
"NegativeButton": 0,
|
"NegativeButton": 0,
|
||||||
"DeadZone": 0.0,
|
"DeadZone": 0.0,
|
||||||
"Sensitivity": 0.02,
|
"Sensitivity": 0.022,
|
||||||
"Gravity": 1.0,
|
"Gravity": 1.0,
|
||||||
"Scale": 1.0,
|
"Scale": 1.0,
|
||||||
"Snap": false
|
"Snap": false
|
||||||
|
|||||||
@@ -33,8 +33,15 @@ namespace Game
|
|||||||
{
|
{
|
||||||
// Collect all input here
|
// Collect all input here
|
||||||
// All axis values here should be accumulated
|
// All axis values here should be accumulated
|
||||||
currentState.input.viewDeltaX += InputManager.GetAxisRaw("Mouse X");
|
float sensitivity = 1.0f / 8.0f;
|
||||||
currentState.input.viewDeltaY += InputManager.GetAxisRaw("Mouse Y");
|
sensitivity = 1.0f;
|
||||||
|
|
||||||
|
//var asf = InputManager.GetAxisRaw("Mouse X");
|
||||||
|
//if (asf != 0.0f)
|
||||||
|
// Console.Print(InputManager.GetAxisRaw("Mouse X").ToString("G9", System.Globalization.CultureInfo.InvariantCulture));
|
||||||
|
|
||||||
|
currentState.input.viewDeltaX += InputManager.GetAxisRaw("Mouse X") * sensitivity;
|
||||||
|
currentState.input.viewDeltaY += InputManager.GetAxisRaw("Mouse Y") * sensitivity;
|
||||||
currentState.input.viewDeltaX += InputManager.GetAxisRaw("LookRight") * Time.DeltaTime * 100;
|
currentState.input.viewDeltaX += InputManager.GetAxisRaw("LookRight") * Time.DeltaTime * 100;
|
||||||
currentState.input.viewDeltaY += -InputManager.GetAxisRaw("LookUp") * Time.DeltaTime * 100;
|
currentState.input.viewDeltaY += -InputManager.GetAxisRaw("LookUp") * Time.DeltaTime * 100;
|
||||||
|
|
||||||
|
|||||||
@@ -102,13 +102,8 @@ namespace Game
|
|||||||
private Actor rootActor;
|
private Actor rootActor;
|
||||||
private float startupTime;
|
private float startupTime;
|
||||||
|
|
||||||
private float viewPitch;
|
private Float3 viewAngles;
|
||||||
|
private Float3 viewAnglesLastFrame;
|
||||||
private float viewPitchLastFrame;
|
|
||||||
private float viewRoll;
|
|
||||||
private float viewRollLastFrame;
|
|
||||||
private float viewYaw;
|
|
||||||
private float viewYawLastFrame;
|
|
||||||
|
|
||||||
[Limit(0, 9000)]
|
[Limit(0, 9000)]
|
||||||
[Tooltip("Base Movement speed")]
|
[Tooltip("Base Movement speed")]
|
||||||
@@ -186,6 +181,14 @@ namespace Game
|
|||||||
public void SetInput(string demoFile)
|
public void SetInput(string demoFile)
|
||||||
{
|
{
|
||||||
input = new PlayerInputDemo(demoFile);
|
input = new PlayerInputDemo(demoFile);
|
||||||
|
|
||||||
|
/*Actor.Position = input.GetCurrentActorState().position;
|
||||||
|
currentVelocity = input.GetCurrentActorState().velocity;
|
||||||
|
SetCameraEulerAngles(input.GetCurrentActorState().viewAngles);*/
|
||||||
|
Actor.Position = input.GetCurrentInputState().verificationPosition;
|
||||||
|
//rootActor.Orientation = input.GetCurrentInputState().verificationOrientation;
|
||||||
|
currentVelocity = input.GetCurrentInputState().verificationVelocity;
|
||||||
|
SetCameraEulerAngles(input.GetCurrentInputState().verificationViewAngles);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnDisable()
|
public override void OnDisable()
|
||||||
@@ -232,14 +235,10 @@ namespace Game
|
|||||||
|
|
||||||
public void ResetRotation(Float3 eulerAngles)
|
public void ResetRotation(Float3 eulerAngles)
|
||||||
{
|
{
|
||||||
viewPitch = eulerAngles.X;
|
viewAngles = eulerAngles;
|
||||||
viewYaw = eulerAngles.Y;
|
viewAnglesLastFrame = eulerAngles;
|
||||||
viewRoll = eulerAngles.Z;
|
|
||||||
viewPitchLastFrame = viewPitch;
|
|
||||||
viewYawLastFrame = viewYaw;
|
|
||||||
viewRollLastFrame = viewRoll;
|
|
||||||
|
|
||||||
SetCameraEulerAngles(new Float3(viewYaw, viewPitch, viewRoll));
|
SetCameraEulerAngles(new Float3(eulerAngles.Y, eulerAngles.X, eulerAngles.Z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnUpdate()
|
public override void OnUpdate()
|
||||||
@@ -263,9 +262,7 @@ namespace Game
|
|||||||
|
|
||||||
PlayerInputState inputState = input.GetCurrentInputState();
|
PlayerInputState inputState = input.GetCurrentInputState();
|
||||||
|
|
||||||
viewYaw = viewYawLastFrame;
|
viewAngles = viewAnglesLastFrame;
|
||||||
viewPitch = viewPitchLastFrame;
|
|
||||||
viewRoll = viewRollLastFrame;
|
|
||||||
ApplyInputToCamera(inputState);
|
ApplyInputToCamera(inputState);
|
||||||
|
|
||||||
/*input.RecordCurrentActorState(new PlayerActorState()
|
/*input.RecordCurrentActorState(new PlayerActorState()
|
||||||
@@ -294,18 +291,18 @@ namespace Game
|
|||||||
|
|
||||||
if (input is PlayerInputDemo)
|
if (input is PlayerInputDemo)
|
||||||
{
|
{
|
||||||
ApplyInputToCamera(inputState);
|
ApplyInputToCamera(inputState, false);
|
||||||
|
|
||||||
// Verify view angles first
|
// Verify view angles first
|
||||||
if (demoDeltasVerify)
|
if (demoDeltasVerify)
|
||||||
{
|
{
|
||||||
Float3 viewAngles = new Float3(viewYaw, viewPitch, viewRoll);
|
Float3 verifAngles = new Float3(inputState.verificationViewAngles.Y, inputState.verificationViewAngles.X, inputState.verificationViewAngles.Z);
|
||||||
float viewAnglesDelta = (viewAngles - inputState.verificationViewAngles).Length;
|
float viewAnglesDelta = (viewAngles - verifAngles).Length;
|
||||||
if (viewAnglesDelta > 0.00001)
|
if (viewAnglesDelta > 0.00001)
|
||||||
{
|
{
|
||||||
Console.PrintError("Demo verification failed, view angles delta: " + viewAnglesDelta);
|
Console.PrintError($"Demo verification failed, view angles delta: {viewAnglesDelta}, viewAngles:{viewAngles}, verif:{verifAngles}");
|
||||||
if (demoDeltasCorrect)
|
if (demoDeltasCorrect)
|
||||||
SetCameraEulerAngles(inputState.verificationViewAngles);
|
SetCameraEulerAngles(verifAngles, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -317,11 +314,11 @@ namespace Game
|
|||||||
// verify
|
// verify
|
||||||
float positionDelta = (Actor.Position - inputState.verificationPosition).Length;
|
float positionDelta = (Actor.Position - inputState.verificationPosition).Length;
|
||||||
if (positionDelta > 0.00001)
|
if (positionDelta > 0.00001)
|
||||||
Console.Print("Demo verification failed, position delta: " + positionDelta);
|
Console.PrintError("Demo verification failed, position delta: " + positionDelta);
|
||||||
|
|
||||||
float velocityDelta = (currentVelocity - inputState.verificationVelocity).Length;
|
float velocityDelta = (currentVelocity - inputState.verificationVelocity).Length;
|
||||||
if (velocityDelta > 0.00001)
|
if (velocityDelta > 0.00001)
|
||||||
Console.Print("Demo verification failed, velocity delta: " + velocityDelta);
|
Console.PrintError("Demo verification failed, velocity delta: " + velocityDelta);
|
||||||
|
|
||||||
float orientationDelta = (rootActor.Orientation - inputState.verificationOrientation).Length;
|
float orientationDelta = (rootActor.Orientation - inputState.verificationOrientation).Length;
|
||||||
if (orientationDelta > 0.00001)
|
if (orientationDelta > 0.00001)
|
||||||
@@ -347,7 +344,7 @@ namespace Game
|
|||||||
position = Actor.Position,
|
position = Actor.Position,
|
||||||
velocity = currentVelocity,
|
velocity = currentVelocity,
|
||||||
orientation = rootActor.Orientation,
|
orientation = rootActor.Orientation,
|
||||||
viewAngles = new Float3(viewYaw, viewPitch, viewRoll)
|
viewAngles = new Float3(viewAngles.Y, viewAngles.X, viewAngles.Z)
|
||||||
});
|
});
|
||||||
input.OnEndFrame();
|
input.OnEndFrame();
|
||||||
|
|
||||||
@@ -355,12 +352,10 @@ namespace Game
|
|||||||
lastInputFrame = currentInputFrame;
|
lastInputFrame = currentInputFrame;
|
||||||
currentInputFrame++;
|
currentInputFrame++;
|
||||||
|
|
||||||
viewPitchLastFrame = viewPitch;
|
viewAnglesLastFrame = viewAngles;
|
||||||
viewYawLastFrame = viewYaw;
|
|
||||||
viewRollLastFrame = viewRoll;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyInputToCamera(PlayerInputState inputState)
|
private void ApplyInputToCamera(PlayerInputState inputState, bool wrapAround = true)
|
||||||
{
|
{
|
||||||
// Update camera viewf
|
// Update camera viewf
|
||||||
float xAxis = inputState.viewDeltaX;
|
float xAxis = inputState.viewDeltaX;
|
||||||
@@ -368,17 +363,33 @@ namespace Game
|
|||||||
if (xAxis == 0.0f && yAxis == 0.0f)
|
if (xAxis == 0.0f && yAxis == 0.0f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
float viewPitch = viewAngles.X;
|
||||||
|
float viewYaw = viewAngles.Y;
|
||||||
viewPitch = Mathf.Clamp(viewPitch + yAxis, -90.0f, 90.0f);
|
viewPitch = Mathf.Clamp(viewPitch + yAxis, -90.0f, 90.0f);
|
||||||
viewYaw += xAxis;
|
viewYaw += xAxis;
|
||||||
|
|
||||||
SetCameraEulerAngles(new Float3(viewYaw, viewPitch, viewRoll));
|
SetCameraEulerAngles(new Float3(viewYaw, viewPitch, viewAngles.Z), wrapAround);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetCameraEulerAngles(Float3 viewAngles)
|
private void SetCameraEulerAngles(Float3 angles, bool wrapAround = true)
|
||||||
{
|
{
|
||||||
|
// Very slight drift
|
||||||
|
if (wrapAround)
|
||||||
|
{
|
||||||
|
angles.X = Mathf.Mod(angles.X, 360.0f);
|
||||||
|
angles.Y = Mathf.Mod(angles.Y, 360.0f);
|
||||||
|
angles.Z = Mathf.Mod(angles.Z, 360.0f);
|
||||||
|
}
|
||||||
|
|
||||||
// Root orientation must be set first
|
// Root orientation must be set first
|
||||||
rootActor.Orientation = Quaternion.Euler(0, viewAngles.X, 0);
|
var or1 = Quaternion.Euler(0, angles.X, 0);
|
||||||
cameraHolder.Orientation = Quaternion.Euler(viewAngles.Y, viewAngles.X, viewAngles.Z);
|
var or2 = Quaternion.Euler(angles.Y, angles.X, angles.Z);
|
||||||
|
rootActor.Orientation = or1;
|
||||||
|
cameraHolder.Orientation = or2;
|
||||||
|
|
||||||
|
Console.Print(angles.X.ToString());
|
||||||
|
|
||||||
|
viewAngles = new Float3(angles.Y, angles.X, angles.Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool SweepPlayerCollider(Actor actor, Float3 start, Vector3 end, out RayCastHit[] hits)
|
private static bool SweepPlayerCollider(Actor actor, Float3 start, Vector3 end, out RayCastHit[] hits)
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ namespace Game
|
|||||||
public static string ContentPath { get; private set; } =
|
public static string ContentPath { get; private set; } =
|
||||||
Path.Combine(Directory.GetCurrentDirectory(), "Content");
|
Path.Combine(Directory.GetCurrentDirectory(), "Content");
|
||||||
|
|
||||||
|
public static string DemoPath { get; private set; } =
|
||||||
|
Path.Combine(Directory.GetCurrentDirectory(), "Demos");
|
||||||
|
|
||||||
public static GameplayGlobals Globals { get; private set; }
|
public static GameplayGlobals Globals { get; private set; }
|
||||||
public static Config Config { get; private set; }
|
public static Config Config { get; private set; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user