Trying to create a circle menu, need to get mouse direction

I’m trying to create a circle menu where you make a choose by holding a button and drags the mouse at the direction of the item and releases button. The problem is I can’t seem to get the mouse direction.

For now I does this (did leave out some code that doesn’t affect the question):

[java] private void registerInput(Trigger keyTrigger) {

app.getInputManager().addMapping(“Trigger”, keyTrigger);

app.getInputManager().addMapping(“Mouse_Up”, new MouseAxisTrigger(MouseInput.AXIS_Y, false));

app.getInputManager().addMapping(“Mouse_Down”, new MouseAxisTrigger(MouseInput.AXIS_Y, true));

app.getInputManager().addMapping(“Mouse_Right”, new MouseAxisTrigger(MouseInput.AXIS_X, false));

app.getInputManager().addMapping(“Mouse_Left”, new MouseAxisTrigger(MouseInput.AXIS_X, true));

app.getInputManager().addListener(this, “Trigger”);

app.getInputManager().addListener(this, “Mouse_Up”);

app.getInputManager().addListener(this, “Mouse_Down”);

app.getInputManager().addListener(this, “Mouse_Right”);

app.getInputManager().addListener(this, “Mouse_Left”);


public void onAction(String name, boolean isPressed, float tpf) {

if (name.equals(“Trigger”)) {

if (isPressed) {


} else {





public void onAnalog(String name, float value, float tpf) {

if (showing) {

if (name.equals(“Mouse_Up”)) {

mouseX = value;

} else if (name.equals(“Mouse_Down”)) {

mouseX = -value;

} else if (name.equals(“Mouse_Right”)) {

mouseY = value;

} else if (name.equals(“Mouse_Left”)) {

mouseY = -value;


mouseVector.set(mouseX, mouseY);




mouseQuaternion.mult(quaternion.fromAngleAxis(tpf, Vector3f.UNIT_Z));




The expected output is that center (a Geometry containing a Line) should rotate and point in the direction the mouse moved.

The current output is that center somewhat follows the mouse and somewhat jumps around nearly randomly.

I don’t know, maybe I have taken completely wrong direction or there are just some simpler mathematical error. Some guidance would be very appreciated :slight_smile:

I don’t think you need to be using onAnalog. Now your angle code updates every time the mouse is moved, and it updates the rotation to the direction the mouse was just moved (since the last time the mouse moved), not the overall movement direction since the mouse was pressed, which is what you are after.

Instead, to get the cursor position you can use :


So you could use that in your onAction method to get a start and end position, or you could use it with onAction and simpleUpdate to get a start position and current position to achieve “live” direction updates until the mouse is released.

Good luck

No no, you have to use RawInputListener. You can access mouse X and Y coords and deltas there. Get cursor position for angle, then you take the sum of all deltas from the time the mouse button is pressed, and unless its like ten times as high as the distance don’t activate the menu buttons. It forces people to shake and swirl the mouse pointer in order for the buttons to work. That is how a great menu is made.

Thank you!

Now I have this


public void onAnalog(String name, float value, float tpf) {

if (showing) {

if (mouseNow.distance(mouseStart) > 40) {

float angle = mouseStart.angleBetween(mouseNow);

mouseQuaternion.fromAngleAxis(angle, Vector3f.UNIT_Z);





mouseStart and mouseNow is set when I show the menu by

[java]mouseStart = app.getInputManager().getCursorPosition().clone();

mouseNow = app.getInputManager().getCursorPosition();[/java]

both are a Vector2f.

This works except when you drag the mouse far to the right (for example) and want to select something on the left, you would have to drag all the way back. I would prefer if you always need to drag the same distance to select, even if you spent half an hour dragging at the other direction :slight_smile:

For this mouseStart needs to be reset by a value calculated from mouseNow, limiting the distance to 40, but I can’t get the mathematic correct.

What I think should work but doesn’t is:

Create a new Vector2f that is a normalized mouseNow.

Multiply this Vector with the distance - 40 to make it the length of distance - 40.

Subtract mouseNow by this Vector and set the result to mouseStart, however this doesn’t work. Why not?