How do I get this when the mouse is moved clockwise?
Asked Answered
T

18

0

How do I know if the mouse is moving clockwise or counterclockwise? What algorithm should I apply?

Tobitobiah answered 8/11, 2023 at 19:32 Comment(0)
S
0

Tobitobiah Do you know where the center of the clock is?

Skew answered 8/11, 2023 at 20:9 Comment(0)
T
0

Skew No, the center of the clock is not clear. What I'm trying to do is to make a rotation with a gizmo in the editor, I'm trying to make a rotation movement like that.

Tobitobiah answered 8/11, 2023 at 20:18 Comment(0)
S
0

Tobitobiah You must have a reference point i.e. rotation center, otherwise the winding direction cannot be determined with certainty. A gizmo should have the centerpoint, shouldn't it?

Skew answered 8/11, 2023 at 20:31 Comment(0)
T
0

Skew I tried a lot, but I couldn't get the result I wanted, where can I find a code example that moves a meshinstance in a 3D scene clockwise or counterclockwise with mouse dragging movements?

Tobitobiah answered 9/11, 2023 at 2:12 Comment(0)
S
0

Tobitobiah clockwise or counterclockwise

Relative to what? You must go around something in order for cw/ccw distinction to make sense. I don't know if there's an example because it's not clear what you're looking for.

Skew answered 9/11, 2023 at 3:21 Comment(0)
T
0

Is this 3d or 2d ? Can you show a prints of your scene ? I think what you need is the look_at function so your object will point rotate to your mouse pos.

Tarragona answered 9/11, 2023 at 4:56 Comment(0)
T
0

Tarragona I am trying to move the object with mouse movements in 3D scene.

Tobitobiah answered 9/11, 2023 at 15:2 Comment(0)
S
0

Tobitobiah I am trying to move the object

Move or rotate? Those are two different things. So you want to rotate a 3D object around its pivot with rotation axis perpendicular to screen plane? Or is it something else?

In things concerning coding, you need to learn to communicate with precision and clarity. Otherwise you're wasting yours and everyone else's time on deciphering your thoughts. Also stating the problem unambiguously in writing (and/or drawing) may help you yourself figure out a solution.

Skew answered 9/11, 2023 at 16:10 Comment(0)
T
0

Skew I meant the action of rotation.

Tobitobiah answered 9/11, 2023 at 16:12 Comment(0)
T
0

Skew I need to know whether I am moving clockwise or anti-clockwise with mouse movements, how do I know this, I need this algorithm.

Tobitobiah answered 9/11, 2023 at 16:13 Comment(0)
S
0

Tobitobiah Here it is:

  • (un)project object's pivot into 2D screen plane. Let's call this point C (for center)
  • if mouse is dragging, get the mouse position in this and previous frame. Let's call these points M1 and M2 (for mouse)
  • construct vectors CM1 and CM2.
  • get the sign of the signed angle between them - that's your direction
Skew answered 9/11, 2023 at 16:19 Comment(0)
T
0

The following code block does not work for me. How do I distinguish whether the x-axis moves in the - or + direction when drawing a circle shape with the mouse.

Vector3 MouseRelative;
Vector3 StartingMousePosition;
Vector3 CurrentPosition;
if (@event is InputEventMouseButton mouseMotionEvent)
		{
			if (mouseMotionEvent.ButtonIndex == MouseButton.Left && mouseMotionEvent.IsPressed())
                       {				
                            StartingMousePosition = mouseMotionEvent.Position;
                       }
               }
if (@event is InputEventMouseMotion mouseSlideEvent)
        {
			MouseRelative = mouseSlideEvent.Relative;
			Vector2 CurrentPosition = mouseSlideEvent.Position;
			float DirX = CurrentPosition.X - StartingMousePosition.X;
			float DirY = CurrentPosition.Y - StartingMousePosition.Y;
			GD.Print(Math.Sign(Mathf.Atan2(DirY, DirX)));
                       StartingMousePosition = CurrentPosition;
}
Tobitobiah answered 9/11, 2023 at 18:25 Comment(0)
S
0

Tobitobiah Try to implement the algorithm from my previous post.

Skew answered 9/11, 2023 at 18:30 Comment(0)
T
0

Skew The y-axis can be irregular as in the blue line, but I can tell with the x-axis whether it is clockwise or counterclockwise, but how do I make this distinction because the x-axis can be negative clockwise or counterclockwise?

Tobitobiah answered 9/11, 2023 at 18:44 Comment(0)
T
0

Skew Can you share a code that contains the algorithm? It would be fine in gdscript, I'll do it in c#🙂 I wonder if I'm applying the algorithm incorrectly? First it rotates clockwise and then counterclockwise, even though I move the mouse clockwise.

Tobitobiah answered 9/11, 2023 at 18:49 Comment(0)
S
0

Tobitobiah

Vector2 center;
public override void _Input(InputEvent e){
	if (e is InputEventMouseButton button ){
		center = button.Position;
	}
	if (e is InputEventMouseMotion motion){
		if (motion.ButtonMask != 0){
			GD.Print((motion.Position - motion.Relative - center).AngleTo(motion.Position - center)>0 ? "CW" : "CCW");
		}
	}
}
Skew answered 9/11, 2023 at 18:54 Comment(0)
T
0

Skew unfortunately the situation is the same, the mouse movement is correct when I move clockwise, but when I move counterclockwise it turns clockwise again.

Tobitobiah answered 9/11, 2023 at 19:13 Comment(0)
S
0

Tobitobiah No it doesn't if you move around the center. It works precisely as it should. CCW vs CW only makes sense when going around some fixed point. For an actual clock it's the center of the clock. In this example it's your click point.

Skew answered 9/11, 2023 at 19:17 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.