refactor: float[2] -> RcVec2f

This commit is contained in:
ikpil 2023-10-12 23:31:25 +09:00
parent 61a21327e9
commit adfded5a94
3 changed files with 27 additions and 26 deletions

View File

@ -10,6 +10,12 @@ namespace DotRecast.Core
public static RcVec2f Zero { get; } = new RcVec2f { X = 0, Y = 0 }; public static RcVec2f Zero { get; } = new RcVec2f { X = 0, Y = 0 };
public RcVec2f(float x, float y)
{
X = x;
Y = y;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public float Get(int idx) public float Get(int idx)
{ {

View File

@ -636,10 +636,10 @@ public class DebugDraw
return _projectionMatrix; return _projectionMatrix;
} }
public RcMatrix4x4f ViewMatrix(RcVec3f cameraPos, float[] cameraEulers) public RcMatrix4x4f ViewMatrix(RcVec3f cameraPos, RcVec2f cameraEulers)
{ {
var rx = RcMatrix4x4f.CreateFromRotate(cameraEulers[0], 1, 0, 0); var rx = RcMatrix4x4f.CreateFromRotate(cameraEulers.X, 1, 0, 0);
var ry = RcMatrix4x4f.CreateFromRotate(cameraEulers[1], 0, 1, 0); var ry = RcMatrix4x4f.CreateFromRotate(cameraEulers.Y, 0, 1, 0);
var r = RcMatrix4x4f.Mul(ref rx, ref ry); var r = RcMatrix4x4f.Mul(ref rx, ref ry);
var t = new RcMatrix4x4f(); var t = new RcMatrix4x4f();

View File

@ -78,7 +78,7 @@ public class RecastDemo : IRecastDemoChannel
private bool processHitTestShift; private bool processHitTestShift;
private int _modState; private int _modState;
private readonly float[] mousePos = new float[2]; private RcVec2f mousePos = new RcVec2f();
private bool _mouseOverMenu; private bool _mouseOverMenu;
private bool pan; private bool pan;
@ -86,11 +86,11 @@ public class RecastDemo : IRecastDemoChannel
private bool rotate; private bool rotate;
private bool movedDuringRotate; private bool movedDuringRotate;
private float scrollZoom; private float scrollZoom;
private readonly float[] origMousePos = new float[2]; private RcVec2f origMousePos = new RcVec2f();
private readonly float[] origCameraEulers = new float[2]; private RcVec2f origCameraEulers = new RcVec2f();
private RcVec3f origCameraPos = new RcVec3f(); private RcVec3f origCameraPos = new RcVec3f();
private readonly float[] cameraEulers = { 45, -45 }; private RcVec2f cameraEulers = new RcVec2f(45, -45);
private RcVec3f cameraPos = RcVec3f.Of(0, 0, 0); private RcVec3f cameraPos = RcVec3f.Of(0, 0, 0);
@ -155,14 +155,14 @@ public class RecastDemo : IRecastDemoChannel
public void OnMouseMoved(IMouse mouse, Vector2 position) public void OnMouseMoved(IMouse mouse, Vector2 position)
{ {
mousePos[0] = (float)position.X; mousePos.X = position.X;
mousePos[1] = (float)position.Y; mousePos.Y = position.Y;
int dx = (int)(mousePos[0] - origMousePos[0]); int dx = (int)(mousePos.X - origMousePos.X);
int dy = (int)(mousePos[1] - origMousePos[1]); int dy = (int)(mousePos.Y - origMousePos.Y);
if (rotate) if (rotate)
{ {
cameraEulers[0] = origCameraEulers[0] + dy * 0.25f; cameraEulers.X = origCameraEulers.X + dy * 0.25f;
cameraEulers[1] = origCameraEulers[1] + dx * 0.25f; cameraEulers.Y = origCameraEulers.Y + dx * 0.25f;
if (dx * dx + dy * dy > 3 * 3) if (dx * dx + dy * dy > 3 * 3)
{ {
movedDuringRotate = true; movedDuringRotate = true;
@ -199,10 +199,8 @@ public class RecastDemo : IRecastDemoChannel
// Rotate view // Rotate view
rotate = true; rotate = true;
movedDuringRotate = false; movedDuringRotate = false;
origMousePos[0] = mousePos[0]; origMousePos = mousePos;
origMousePos[1] = mousePos[1]; origCameraEulers = cameraEulers;
origCameraEulers[0] = cameraEulers[0];
origCameraEulers[1] = cameraEulers[1];
} }
} }
else if (button == MouseButton.Middle) else if (button == MouseButton.Middle)
@ -212,11 +210,8 @@ public class RecastDemo : IRecastDemoChannel
// Pan view // Pan view
pan = true; pan = true;
movedDuringPan = false; movedDuringPan = false;
origMousePos[0] = mousePos[0]; origMousePos = mousePos;
origMousePos[1] = mousePos[1]; origCameraPos = cameraPos;
origCameraPos.X = cameraPos.X;
origCameraPos.Y = cameraPos.Y;
origCameraPos.Z = cameraPos.Z;
} }
} }
} }
@ -513,8 +508,8 @@ public class RecastDemo : IRecastDemoChannel
RcVec3f rayStart = new RcVec3f(); RcVec3f rayStart = new RcVec3f();
RcVec3f rayEnd = new RcVec3f(); RcVec3f rayEnd = new RcVec3f();
GLU.GlhUnProjectf(mousePos[0], viewport[3] - 1 - mousePos[1], 0.0f, modelviewMatrix, projectionMatrix, viewport, ref rayStart); GLU.GlhUnProjectf(mousePos.X, viewport[3] - 1 - mousePos.Y, 0.0f, modelviewMatrix, projectionMatrix, viewport, ref rayStart);
GLU.GlhUnProjectf(mousePos[0], viewport[3] - 1 - mousePos[1], 1.0f, modelviewMatrix, projectionMatrix, viewport, ref rayEnd); GLU.GlhUnProjectf(mousePos.X, viewport[3] - 1 - mousePos.Y, 1.0f, modelviewMatrix, projectionMatrix, viewport, ref rayEnd);
SendMessage(new RaycastEvent() SendMessage(new RaycastEvent()
{ {
@ -578,8 +573,8 @@ public class RecastDemo : IRecastDemoChannel
cameraPos.Y = (bmax.Y + bmin.Y) / 2 + camr; cameraPos.Y = (bmax.Y + bmin.Y) / 2 + camr;
cameraPos.Z = (bmax.Z + bmin.Z) / 2 + camr; cameraPos.Z = (bmax.Z + bmin.Z) / 2 + camr;
camr *= 5; camr *= 5;
cameraEulers[0] = 45; cameraEulers.X = 45;
cameraEulers[1] = -45; cameraEulers.Y = -45;
} }
_sample.SetChanged(false); _sample.SetChanged(false);