December 03, 2020, 08:21:17 PM

Author Topic: [bmx] DrawPoly(), filled or unfilled by Oddball [ 1+ years ago ]  (Read 861 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : DrawPoly(), filled or unfilled
Author : Oddball
Posted : 1+ years ago

Description : Just add the function below to your project and it will override BlitzMaxs DrawPoly.

Function DrawPoly(xy#[],fill%=True,x#=0,y#=0)

Draws a polygon at coordinates x# and y# with corners defined by an array of x#,y# coordinate pairs. Setting fill=False draws an unfilled polygon. If the optional parameters are left blank DrawPoly acts identically to the standard BlitzMax function.

BlitzMax commands that affect the drawing of polygons include #SetColor, #SetHandle, #SetScale, #SetRotation, #SetOrigin, #SetViewPort, #SetBlend and #SetAlpha.


Code :
Code: BlitzMax
  1. Function DrawPoly( xy:Float[], fill:Int=True, x:Float=0, y:Float=0 )
  2.         Local origin_x:Float
  3.         Local origin_y:Float
  4.         GetOrigin origin_x,origin_y
  5.         Local handle_x:Float
  6.         Local handle_y:Float
  7.         GetHandle handle_x,handle_y
  8.        
  9.         If fill
  10.                 _max2dDriver.DrawPoly xy,..
  11.                 -handle_x,-handle_y,..
  12.                 x+origin_x,y+origin_y
  13.         Else
  14.                 Local x1:Float=xy[xy.Length-2]
  15.                 Local y1:Float=xy[xy.Length-1]
  16.                 For Local i:Int=0 Until Len xy Step 2
  17.                         Local x2:Float=xy[i]
  18.                         Local y2:Float=xy[i+1]
  19.                         _max2dDriver.DrawLine..
  20.                         -handle_x+x1,-handle_y+y1,..
  21.                         -handle_x+x2,-handle_y+y2,..
  22.                         x+origin_x-0.5,y+origin_y-0.5
  23.                         x1=x2
  24.                         y1=y2
  25.                 Next
  26.         EndIf
  27. End Function


Comments :


Oddball(Posted 1+ years ago)

 Slight bugfix. Apparently handle position wasn't mimiced correctly. Not sure how that slipped by for so long.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal