clockwise or counterclockwise

BlitzMax Forums/BlitzMax Programming/clockwise or counterclockwise

VinceA(Posted 2007) [#1]
Problem: How can I determine if the mouse is moved clockwise or counterclockwise given only the movement of the mouse?

Any suggestions appreciated!!


Dreamora(Posted 2007) [#2]
store a list of past positions and use that to determine where the center of movement has been. That allows you to say if the angular changement where CW or CCW


VinceA(Posted 2007) [#3]
Thanks!
I will make a small demo to see what happens..


Vertex(Posted 2007) [#4]
SuperStrict

Framework BRL.Blitz
Import BRL.GLMax2D

Const CW_ORIENTATION  : Int = 1, ..
      CCW_ORIENTATION : Int = 2

Global Points      : Float[3, 2], ..
       A           : Float[2], ..
       B           : Float[2], ..
       Orientation : Int

Graphics(640, 480)

While Not KeyDown(KEY_ESCAPE)
	Points[0, 0] = Points[1, 0] ; Points[0, 1] = Points[1, 1]
	Points[1, 0] = Points[2, 0] ; Points[1, 1] = Points[2, 1]
	Points[2, 0] = MouseX()     ; Points[2, 1] = MouseY()
	
	Rem
		->  |p1.x|   |p0.x|
		a = |p1.y| - |p0.y|

		->  |p2.x|   |p1.x|
		b = |p2.y| - |p1.y|
		
		->   ->   ->
		c  = a  x b
		
		c.z >  0 --> clock wise
		c.z <= 0 --> counter clock wise
	End Rem
	
	A[0] = Points[1, 0] - Points[0, 0]
	A[1] = Points[1, 1] - Points[0, 1]

	B[0] = Points[2, 0] - Points[1, 0]
	B[1] = Points[2, 1] - Points[1, 1]

	If A[0]*B[1] - A[1]*B[0] > 0.0 Then
		Orientation = CW_ORIENTATION
	Else
		Orientation = CCW_ORIENTATION
	EndIf
	
	
	Cls()
	If Orientation = CW_ORIENTATION Then
		SetColor(255, 0, 0)
	Else
		SetColor(0, 255, 0)
	EndIf
	
	DrawLine(Points[0, 0], Points[0, 1], ..
	         Points[1, 0], Points[1, 1])
	DrawLine(Points[1, 0], Points[1, 1], ..
	         Points[2, 0], Points[2, 1])
	Flip()
Wend

End

Move your mouse very fast clock wise you will see red lines and move it counter clock wise you will see green lines.

The demo do the following:
Tracking 3 points
calculating the cross product
decide, if the cross product vector c "points in or out the monitor"

cu olli


VinceA(Posted 2007) [#5]
Actually I had just stumbled upon the same solution, and was about to post the solution...

But well your implementation is so much cleaner !! : )