clockwise or counterclockwise

BlitzMax Forums/BlitzMax Programming/clockwise or counterclockwise

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

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