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;
|
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,85 +156,85 @@ 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;
|
||||||
origMousePos[0] = mousePos[0];
|
origMousePos[0] = mousePos[0];
|
||||||
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 == 2)
|
else if (button == MouseButton.Middle)
|
||||||
{
|
{
|
||||||
if (!mouseOverMenu)
|
// if (!mouseOverMenu)
|
||||||
{
|
// {
|
||||||
// Pan view
|
// Pan view
|
||||||
pan = true;
|
pan = true;
|
||||||
movedDuringPan = false;
|
movedDuringPan = false;
|
||||||
origMousePos[0] = mousePos[0];
|
origMousePos[0] = mousePos[0];
|
||||||
origMousePos[1] = mousePos[1];
|
origMousePos[1] = mousePos[1];
|
||||||
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;
|
|
||||||
processHitTestShift = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (button == 0)
|
|
||||||
{
|
|
||||||
if (!mouseOverMenu)
|
|
||||||
{
|
{
|
||||||
processHitTest = true;
|
processHitTest = true;
|
||||||
//processHitTestShift = (mods & Keys.GLFW_MOD_SHIFT) != 0 ? true : false;
|
processHitTestShift = true;
|
||||||
//processHitTestShift = (mods & Keys.) != 0 ? true : false;
|
|
||||||
}
|
}
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
else if (button == 2)
|
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 == MouseButton.Middle)
|
||||||
{
|
{
|
||||||
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);
|
||||||
|
@ -470,41 +471,41 @@ public class RecastDemo : MouseListener
|
||||||
|
|
||||||
// if (settingsUI.isMeshInputTrigerred())
|
// if (settingsUI.isMeshInputTrigerred())
|
||||||
// {
|
// {
|
||||||
// aFilterPatterns.put(stack.UTF8("*.obj"));
|
// aFilterPatterns.put(stack.UTF8("*.obj"));
|
||||||
// aFilterPatterns.flip();
|
// aFilterPatterns.flip();
|
||||||
// string filename = TinyFileDialogs.tinyfd_openFileDialog("Open Mesh File", "", aFilterPatterns,
|
// string filename = TinyFileDialogs.tinyfd_openFileDialog("Open Mesh File", "", aFilterPatterns,
|
||||||
// "Mesh File (*.obj)", false);
|
// "Mesh File (*.obj)", false);
|
||||||
// if (filename != null) {
|
// if (filename != null) {
|
||||||
// try (InputStream stream = new FileInputStream(filename)) {
|
// try (InputStream stream = new FileInputStream(filename)) {
|
||||||
// sample.update(loadInputMesh(stream), null, null);
|
// sample.update(loadInputMesh(stream), null, null);
|
||||||
// } catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
// Console.WriteLine(e).printStackTrace();
|
// Console.WriteLine(e).printStackTrace();
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// else if (settingsUI.isNavMeshInputTrigerred())
|
// else if (settingsUI.isNavMeshInputTrigerred())
|
||||||
// {
|
// {
|
||||||
// try (MemoryStack stack = stackPush()) {
|
// try (MemoryStack stack = stackPush()) {
|
||||||
// PointerBuffer aFilterPatterns = stack.mallocPointer(4);
|
// PointerBuffer aFilterPatterns = stack.mallocPointer(4);
|
||||||
// aFilterPatterns.put(stack.UTF8("*.bin"));
|
// aFilterPatterns.put(stack.UTF8("*.bin"));
|
||||||
// aFilterPatterns.put(stack.UTF8("*.zip"));
|
// aFilterPatterns.put(stack.UTF8("*.zip"));
|
||||||
// aFilterPatterns.put(stack.UTF8("*.bytes"));
|
// aFilterPatterns.put(stack.UTF8("*.bytes"));
|
||||||
// aFilterPatterns.put(stack.UTF8("*.navmesh"));
|
// aFilterPatterns.put(stack.UTF8("*.navmesh"));
|
||||||
// aFilterPatterns.flip();
|
// aFilterPatterns.flip();
|
||||||
// string filename = TinyFileDialogs.tinyfd_openFileDialog("Open Nav Mesh File", "", aFilterPatterns,
|
// string filename = TinyFileDialogs.tinyfd_openFileDialog("Open Nav Mesh File", "", aFilterPatterns,
|
||||||
// "Nav Mesh File", false);
|
// "Nav Mesh File", false);
|
||||||
// if (filename != null) {
|
// if (filename != null) {
|
||||||
// File file = new File(filename);
|
// File file = new File(filename);
|
||||||
// if (file.exists()) {
|
// if (file.exists()) {
|
||||||
// try {
|
// try {
|
||||||
// loadNavMesh(file, filename);
|
// loadNavMesh(file, filename);
|
||||||
// geom = null;
|
// geom = null;
|
||||||
// } catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
// Console.WriteLine(e);
|
// Console.WriteLine(e);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// else if (settingsUI.isBuildTriggered() && sample.getInputGeom() != null)
|
// else if (settingsUI.isBuildTriggered() && sample.getInputGeom() != null)
|
||||||
// {
|
// {
|
||||||
|
@ -557,63 +558,63 @@ public class RecastDemo : MouseListener
|
||||||
|
|
||||||
// if (!mouseOverMenu)
|
// if (!mouseOverMenu)
|
||||||
// {
|
// {
|
||||||
// GLU.glhUnProjectf(mousePos[0], viewport[3] - 1 - mousePos[1], 0.0f, modelviewMatrix, projectionMatrix, viewport,
|
// GLU.glhUnProjectf(mousePos[0], viewport[3] - 1 - mousePos[1], 0.0f, modelviewMatrix, projectionMatrix, viewport,
|
||||||
// rayStart);
|
// rayStart);
|
||||||
// GLU.glhUnProjectf(mousePos[0], viewport[3] - 1 - mousePos[1], 1.0f, modelviewMatrix, projectionMatrix, viewport,
|
// GLU.glhUnProjectf(mousePos[0], viewport[3] - 1 - mousePos[1], 1.0f, modelviewMatrix, projectionMatrix, viewport,
|
||||||
// rayEnd);
|
// rayEnd);
|
||||||
|
|
||||||
// Hit test mesh.
|
// Hit test mesh.
|
||||||
// DemoInputGeomProvider inputGeom = sample.getInputGeom();
|
// DemoInputGeomProvider inputGeom = sample.getInputGeom();
|
||||||
// if (processHitTest && sample != null)
|
// if (processHitTest && sample != null)
|
||||||
// {
|
// {
|
||||||
// float? hit = null;
|
// float? hit = null;
|
||||||
// if (inputGeom != null)
|
// if (inputGeom != null)
|
||||||
// {
|
// {
|
||||||
// hit = inputGeom.raycastMesh(rayStart, rayEnd);
|
// hit = inputGeom.raycastMesh(rayStart, rayEnd);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// if (!hit.HasValue && sample.getNavMesh() != null)
|
// if (!hit.HasValue && sample.getNavMesh() != null)
|
||||||
// {
|
// {
|
||||||
// hit = NavMeshRaycast.raycast(sample.getNavMesh(), rayStart, rayEnd);
|
// hit = NavMeshRaycast.raycast(sample.getNavMesh(), rayStart, rayEnd);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// if (!hit.HasValue && sample.getRecastResults() != null)
|
// if (!hit.HasValue && sample.getRecastResults() != null)
|
||||||
// {
|
// {
|
||||||
// hit = PolyMeshRaycast.raycast(sample.getRecastResults(), rayStart, rayEnd);
|
// hit = PolyMeshRaycast.raycast(sample.getRecastResults(), rayStart, rayEnd);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// float[] rayDir = new float[] { rayEnd[0] - rayStart[0], rayEnd[1] - rayStart[1], rayEnd[2] - rayStart[2] };
|
// float[] rayDir = new float[] { rayEnd[0] - rayStart[0], rayEnd[1] - rayStart[1], rayEnd[2] - rayStart[2] };
|
||||||
// Tool rayTool = toolsUI.getTool();
|
// Tool rayTool = toolsUI.getTool();
|
||||||
// vNormalize(rayDir);
|
// vNormalize(rayDir);
|
||||||
// if (rayTool != null)
|
// if (rayTool != null)
|
||||||
// {
|
// {
|
||||||
// rayTool.handleClickRay(rayStart, rayDir, processHitTestShift);
|
// rayTool.handleClickRay(rayStart, rayDir, processHitTestShift);
|
||||||
// }
|
// }
|
||||||
// // TODO : 잠시 주석
|
// // TODO : 잠시 주석
|
||||||
// // if (hit.HasValue) {
|
// // if (hit.HasValue) {
|
||||||
// // float hitTime = hit.Value;
|
// // float hitTime = hit.Value;
|
||||||
// // if ((modState & GLFW_MOD_CONTROL) != 0) {
|
// // if ((modState & GLFW_MOD_CONTROL) != 0) {
|
||||||
// // // Marker
|
// // // Marker
|
||||||
// // markerPositionSet = true;
|
// // markerPositionSet = true;
|
||||||
// // markerPosition[0] = rayStart[0] + (rayEnd[0] - rayStart[0]) * hitTime;
|
// // markerPosition[0] = rayStart[0] + (rayEnd[0] - rayStart[0]) * hitTime;
|
||||||
// // markerPosition[1] = rayStart[1] + (rayEnd[1] - rayStart[1]) * hitTime;
|
// // markerPosition[1] = rayStart[1] + (rayEnd[1] - rayStart[1]) * hitTime;
|
||||||
// // markerPosition[2] = rayStart[2] + (rayEnd[2] - rayStart[2]) * hitTime;
|
// // markerPosition[2] = rayStart[2] + (rayEnd[2] - rayStart[2]) * hitTime;
|
||||||
// // } else {
|
// // } else {
|
||||||
// // float[] pos = new float[3];
|
// // float[] pos = new float[3];
|
||||||
// // pos[0] = rayStart[0] + (rayEnd[0] - rayStart[0]) * hitTime;
|
// // pos[0] = rayStart[0] + (rayEnd[0] - rayStart[0]) * hitTime;
|
||||||
// // pos[1] = rayStart[1] + (rayEnd[1] - rayStart[1]) * hitTime;
|
// // pos[1] = rayStart[1] + (rayEnd[1] - rayStart[1]) * hitTime;
|
||||||
// // pos[2] = rayStart[2] + (rayEnd[2] - rayStart[2]) * hitTime;
|
// // pos[2] = rayStart[2] + (rayEnd[2] - rayStart[2]) * hitTime;
|
||||||
// // if (rayTool != null) {
|
// // if (rayTool != null) {
|
||||||
// // rayTool.handleClick(rayStart, pos, processHitTestShift);
|
// // rayTool.handleClick(rayStart, pos, processHitTestShift);
|
||||||
// // }
|
// // }
|
||||||
// // }
|
// // }
|
||||||
// // } else {
|
// // } else {
|
||||||
// // if ((modState & GLFW_MOD_CONTROL) != 0) {
|
// // if ((modState & GLFW_MOD_CONTROL) != 0) {
|
||||||
// // // Marker
|
// // // Marker
|
||||||
// // markerPositionSet = false;
|
// // markerPositionSet = false;
|
||||||
// // }
|
// // }
|
||||||
// // }
|
// // }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// processHitTest = false;
|
// processHitTest = false;
|
||||||
// }
|
// }
|
||||||
|
@ -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