forked from bit/DotRecastNetSim
added mouse event
This commit is contained in:
parent
90ec8a1836
commit
ad5a1b7419
|
@ -50,7 +50,7 @@ using Window = Silk.NET.Windowing.Window;
|
|||
|
||||
namespace DotRecast.Recast.Demo;
|
||||
|
||||
public class RecastDemo : MouseListener
|
||||
public class RecastDemo
|
||||
{
|
||||
private static readonly ILogger Logger = Log.ForContext<RecastDemo>();
|
||||
|
||||
|
@ -115,42 +115,35 @@ public class RecastDemo : MouseListener
|
|||
window.Run();
|
||||
}
|
||||
|
||||
private Mouse createMouse(IInputContext input)
|
||||
public void OnMouseScrolled(IMouse mice, ScrollWheel scrollWheel)
|
||||
{
|
||||
Mouse mouse = new Mouse(input);
|
||||
mouse.addListener(this);
|
||||
return mouse;
|
||||
}
|
||||
|
||||
public void scroll(double xoffset, double yoffset)
|
||||
{
|
||||
if (yoffset < 0)
|
||||
if (scrollWheel.Y < 0)
|
||||
{
|
||||
// wheel down
|
||||
if (!mouseOverMenu)
|
||||
{
|
||||
// if (!mouseOverMenu)
|
||||
// {
|
||||
scrollZoom += 1.0f;
|
||||
}
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!mouseOverMenu)
|
||||
{
|
||||
// if (!mouseOverMenu)
|
||||
// {
|
||||
scrollZoom -= 1.0f;
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
// float[] modelviewMatrix = dd.viewMatrix(cameraPos, cameraEulers);
|
||||
// cameraPos[0] += scrollZoom * 2.0f * modelviewMatrix[2];
|
||||
// cameraPos[1] += scrollZoom * 2.0f * modelviewMatrix[6];
|
||||
// cameraPos[2] += scrollZoom * 2.0f * modelviewMatrix[10];
|
||||
float[] modelviewMatrix = dd.viewMatrix(cameraPos, cameraEulers);
|
||||
cameraPos[0] += scrollZoom * 2.0f * modelviewMatrix[2];
|
||||
cameraPos[1] += scrollZoom * 2.0f * modelviewMatrix[6];
|
||||
cameraPos[2] += scrollZoom * 2.0f * modelviewMatrix[10];
|
||||
scrollZoom = 0;
|
||||
}
|
||||
|
||||
public void position(double x, double y)
|
||||
public void OnMouseMoved(IMouse mouse, Vector2 position)
|
||||
{
|
||||
mousePos[0] = (float)x;
|
||||
mousePos[1] = (float)y;
|
||||
mousePos[0] = (float)position.X;
|
||||
mousePos[1] = (float)position.Y;
|
||||
int dx = (int)(mousePos[0] - origMousePos[0]);
|
||||
int dy = (int)(mousePos[1] - origMousePos[1]);
|
||||
if (rotate)
|
||||
|
@ -163,36 +156,36 @@ public class RecastDemo : MouseListener
|
|||
}
|
||||
}
|
||||
|
||||
// if (pan)
|
||||
// {
|
||||
// float[] modelviewMatrix = dd.viewMatrix(cameraPos, cameraEulers);
|
||||
// cameraPos[0] = origCameraPos[0];
|
||||
// cameraPos[1] = origCameraPos[1];
|
||||
// cameraPos[2] = origCameraPos[2];
|
||||
//
|
||||
// cameraPos[0] -= 0.1f * dx * modelviewMatrix[0];
|
||||
// cameraPos[1] -= 0.1f * dx * modelviewMatrix[4];
|
||||
// cameraPos[2] -= 0.1f * dx * modelviewMatrix[8];
|
||||
//
|
||||
// cameraPos[0] += 0.1f * dy * modelviewMatrix[1];
|
||||
// cameraPos[1] += 0.1f * dy * modelviewMatrix[5];
|
||||
// cameraPos[2] += 0.1f * dy * modelviewMatrix[9];
|
||||
// if (dx * dx + dy * dy > 3 * 3)
|
||||
// {
|
||||
// movedDuringPan = true;
|
||||
// }
|
||||
// }
|
||||
if (pan)
|
||||
{
|
||||
float[] modelviewMatrix = dd.viewMatrix(cameraPos, cameraEulers);
|
||||
cameraPos[0] = origCameraPos[0];
|
||||
cameraPos[1] = origCameraPos[1];
|
||||
cameraPos[2] = origCameraPos[2];
|
||||
|
||||
cameraPos[0] -= 0.1f * dx * modelviewMatrix[0];
|
||||
cameraPos[1] -= 0.1f * dx * modelviewMatrix[4];
|
||||
cameraPos[2] -= 0.1f * dx * modelviewMatrix[8];
|
||||
|
||||
cameraPos[0] += 0.1f * dy * modelviewMatrix[1];
|
||||
cameraPos[1] += 0.1f * dy * modelviewMatrix[5];
|
||||
cameraPos[2] += 0.1f * dy * modelviewMatrix[9];
|
||||
if (dx * dx + dy * dy > 3 * 3)
|
||||
{
|
||||
movedDuringPan = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void button(int button, int mods, bool down)
|
||||
public void OnMouseUpAndDown(IMouse mouse, MouseButton button, bool down)
|
||||
{
|
||||
modState = mods;
|
||||
modState = 0;
|
||||
if (down)
|
||||
{
|
||||
if (button == 1)
|
||||
{
|
||||
if (!mouseOverMenu)
|
||||
if (button == MouseButton.Right)
|
||||
{
|
||||
// if (!mouseOverMenu)
|
||||
// {
|
||||
// Rotate view
|
||||
rotate = true;
|
||||
movedDuringRotate = false;
|
||||
|
@ -200,12 +193,12 @@ public class RecastDemo : MouseListener
|
|||
origMousePos[1] = mousePos[1];
|
||||
origCameraEulers[0] = cameraEulers[0];
|
||||
origCameraEulers[1] = cameraEulers[1];
|
||||
//}
|
||||
}
|
||||
}
|
||||
else if (button == 2)
|
||||
{
|
||||
if (!mouseOverMenu)
|
||||
else if (button == MouseButton.Middle)
|
||||
{
|
||||
// if (!mouseOverMenu)
|
||||
// {
|
||||
// Pan view
|
||||
pan = true;
|
||||
movedDuringPan = false;
|
||||
|
@ -214,34 +207,34 @@ public class RecastDemo : MouseListener
|
|||
origCameraPos[0] = cameraPos[0];
|
||||
origCameraPos[1] = cameraPos[1];
|
||||
origCameraPos[2] = cameraPos[2];
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle mouse clicks here.
|
||||
if (button == 1)
|
||||
if (button == MouseButton.Right)
|
||||
{
|
||||
rotate = false;
|
||||
if (!mouseOverMenu)
|
||||
{
|
||||
// if (!mouseOverMenu)
|
||||
// {
|
||||
if (!movedDuringRotate)
|
||||
{
|
||||
processHitTest = true;
|
||||
processHitTestShift = true;
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
else if (button == 0)
|
||||
{
|
||||
if (!mouseOverMenu)
|
||||
else if (button == MouseButton.Left)
|
||||
{
|
||||
// if (!mouseOverMenu)
|
||||
// {
|
||||
processHitTest = true;
|
||||
//processHitTestShift = (mods & Keys.GLFW_MOD_SHIFT) != 0 ? true : false;
|
||||
//processHitTestShift = (mods & Keys.) != 0 ? true : false;
|
||||
//}
|
||||
}
|
||||
}
|
||||
else if (button == 2)
|
||||
else if (button == MouseButton.Middle)
|
||||
{
|
||||
pan = false;
|
||||
}
|
||||
|
@ -381,6 +374,14 @@ public class RecastDemo : MouseListener
|
|||
_sdl = SdlWindowing.GetExistingApi(window);
|
||||
|
||||
_input = window.CreateInput();
|
||||
foreach (var mice in _input.Mice)
|
||||
{
|
||||
mice.Scroll += OnMouseScrolled;
|
||||
mice.MouseDown += (m, b) => OnMouseUpAndDown(m, b, true);
|
||||
mice.MouseUp += (m, b) => OnMouseUpAndDown(m, b, false);
|
||||
mice.MouseMove += OnMouseMoved;
|
||||
}
|
||||
|
||||
_gl = window.CreateOpenGL();
|
||||
|
||||
dd = new RecastDebugDraw(_gl);
|
||||
|
@ -672,7 +673,6 @@ public class RecastDemo : MouseListener
|
|||
}
|
||||
|
||||
|
||||
|
||||
var io = ImGui.GetIO();
|
||||
|
||||
io.DisplaySize = new Vector2(width, height);
|
||||
|
|
Loading…
Reference in New Issue