CreedVI/Raylib-J-Examples

Zoom and Drag Example Help Porting

Closed this issue · 1 comments

Raylib has a 2D camera Drag and zoom example (https://github.com/raysan5/raylib/blob/master/examples/core/core_2d_camera_mouse_zoom.c, code for the original C Raylib used as reference), I try to port that to Raylib-j, however I was able to get the zooming part to work, I couldn’t get the dragging part to work.

The attempted part ported Code to Raylib-j:

...

// Translate based on mouse right click - this does not work
            if (rCore.IsMouseButtonDown(Mouse.MouseButton.MOUSE_BUTTON_RIGHT))
            {
                Vector2 delta = rlj.core.GetMouseDelta();
                delta = Raymath.Vector2Scale(delta, -1.0f/camera.zoom);

                camera.target = Raymath.Vector2Add(camera.target, delta);
            }

            // Zoom based on mouse wheel - this works
            float wheel = rCore.GetMouseWheelMove();
            if (wheel != 0)
            {
                // Get the world point that is under the mouse
                Vector2 mouseWorldPos = rlj.core.GetScreenToWorld2D(rCore.GetMousePosition(), camera);

                // Set the offset to where the mouse is
                camera.offset = rCore.GetMousePosition();

                // Set the target to match, so that the camera maps the world space point
                // under the cursor to the screen space point under the cursor at any zoom
                camera.target = mouseWorldPos;

                // Zoom increment
                final float zoomIncrement = 0.125f;

                camera.zoom += (wheel*zoomIncrement);

                if (camera.zoom < zoomIncrement)
                {
                    camera.zoom = zoomIncrement;
                }

Is anyone able to help out?

Thanks for submitting this issue!

The issue was a bug in the Mouse Cursor Callback in Raylib-J. I've fixed the bug in the latest commit to the Raylib-J repo, so you should be able to run the example if you compile the .jar from the repo.