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