[SOLVED] Rotate an object by making circles with mouse

Hi all,

I’m rotating a wheel in my game using the mouse’s X axis.
When the player moves the mouse right the wheel turns clockwise and when the players moves the mouse left the wheel turns counter clockwise.

Now what I’d like to do is rotate the wheel, not by moving the mouse left or right, but by drawing circles with the mouse.

How do you detect such “gestures” ? Please tell me it’s much simpler than machine vision / pattern recognition / neural nets / math headaches.

Bare in mind I’ve never done anything like this but you could do something along the line of having a bunch of waypoints which the mouse cursor has to hit in a specific order within a specific error margin. This would also allow for different gestures in the future if needed. Exactly how I would implement this I don’t know. It could also be that the player could start the gesture at any waypoint of course if it’s for instance a circle they need to gesture around several laps.

Sorry, I’m just ranting really with some ideas that just popped into my head.

Since I don’t fully know your requirements I will mention this other thing as well. If the wheel just needs turning X degrees and not require real time precision while moving it you could just turn the wheel at a constant rotation and just have the player click and hold the mouse to start the action and then move the mouse to the position of there the action should stop, if that makes sense.

There might of course be something completely easier to do out there which I have no clue about, but I’ve not really been looking around myself :smiley:

If you want to rotate an object with your mouse rotating around your object (like blender)

you can simply do this not the best and there is still few bugs.

private void rotateObject(float value, float dist) {
    Vector2f click2dn = inputManager.getCursorPosition();
    Vector3f temp = cam.getScreenCoordinates(currentGeom.getWorldBound().getCenter());
    Vector2f center = new Vector2f(temp.x, temp.y);
    Vector2f sub1 = click2dn.subtract(center);
    Vector2f sub2 = dir2d.subtract(center);
    float angle = FastMath.sign(sub1.angleBetween(sub2));
    Quaternion q = new Quaternion();
    if (xAxis) {
        q.fromAngleAxis(value * dist * angle, Vector3f.UNIT_X);
    } else if (yAxis) {
        q.fromAngleAxis(value * dist * angle, Vector3f.UNIT_Y);
    } else if (zAxis) {
        q.fromAngleAxis(value * dist * angle, Vector3f.UNIT_Z);

//cam is the Camera
//dir2d is the last mouse position
//currentGeom is the current selected Geometry
//xAxis,yAxis,zAxis are the rotation donuts

1 Like


If you want to rotate an object with your mouse rotating around your object (like blender)

I think you gave me the answer with just this sentence. it’s about angles, not positions !
The key is not to use the x or y axis delta but an angle delta. I’m so stupid for not finding that myself.

Thank you sir !