Check if 2D points are clockwise or counterclockwise...

Just starting out? Need help? Post your questions and find answers here.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Check if 2D points are clockwise or counterclockwise...

Post by Michael Vogel »

Thanks to eddy I was able to put a map into my small 3D sport program:(demo at http://mr.vogel.googlepages.com/ForerunnerMap.zip)

This is done with the following code lines...

Code: Select all

;***Google Maps***
	;GoogleMapsAvailable=0
	If GoogleMapsAvailable
		If Start3D()
			TransformSprite3D(#GoogleMapSprite,Polygon(0),Polygon(1),Polygon(6),Polygon(7),Polygon(4),Polygon(5),Polygon(2),Polygon(3))
			DisplaySprite3D(#GoogleMapSprite,0,0,255)
			Stop3D()
		EndIf
	EndIf

	windc=StartDrawing(ScreenOutput())

	;***Google Maps***
	Box(Polygon(0),Polygon(1),6,6,#Yellow)
	Box(Polygon(2),Polygon(3),6,6,#Green)
	Box(Polygon(4),Polygon(5),6,6,#Red)
	Box(Polygon(6),Polygon(7),6,6,#Blue)

	:
	:

	If GoogleMapsAvailable=0
		SelectObject_(windc,winbrush)
		Polygon_(windc,@Polygon(),4)
	EndIf

My problem is, to recognize, if the map can be displayed or not. It will be seen, if the corners are in clockwise order (yellow, blue, red green corners). Nothing will be displayed, if the corners are seen like yellow- green - red - blue, but how to check this easily and fast?
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Thanks, will have a look at that tomorrow morning
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Done!
Thanks once again, it was just easy - only two lines (three points) of the rectangle have to be checked, works simple and fast :)

Code: Select all

Crossproduct=(Polygon(6)-Polygon(0))*(Polygon(3)-Polygon(1))-(Polygon(7)-Polygon(1))*(Polygon(2)-Polygon(0))
My "demo" (3D viewer and reporting is fully functional) has been updated and can be downloaded here

Just decompress all files to the same directory, start the Forerunner.exe and press enter for displaying the selected sport track. If you press 'K' while viewing, the "upper side" of the ground plate will change from a single color to a bitmap (will be a downloaded google map in the future) and vice versa, the "backplane" stays colored.

The quality of the map is not perfect, some distorting effects can be seen while rotating the graphic (using the cursor keys or dragging the track with the mouse).

Michael
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

Michael Vogel wrote:
My "demo" (3D viewer and reporting is fully functional) has been updated and can be downloaded here

Michael
it crash when i press 'view' button
AppName: forerunner map.exe AppVer: 0.0.0.0 ModName: forerunner map.exe
ModVer: 0.0.0.0 Offset: 00016684
Please correct my english
http://purebasic.developpez.com/
r_hyde
Enthusiast
Enthusiast
Posts: 155
Joined: Wed Jul 05, 2006 12:40 am

Post by r_hyde »

same here - crash when I press 'View' button, just after screen init.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Thanks, r_hyde and Comtois for your informations, the program works fine here (but checked only on two notebooks) - I think, the problem is related to the graphic card...

So please try one of the following things :roll: :
  • Set the FineLine value in the forerunner.ini to 0 (Disable Antialiazing)
    Set the DirectMemory value in the forerunner.ini to 0 (uses 'normal' plot command instead of PokeB for drawi8ng commands)
    Try the'older version without the Sprite3D (so there is also no map :( )
This tests would give me an indication where to search for the problem - the source code has already more than 7500 lines, so i don't want to post it :wink:

Thanks for your help,
Michael
Post Reply