Hi there, i was playing around with GLBasic, trying to make a polygon editing tool, i've included some code down below, it doesn't have any media included so you can just paste it into GLBasic and it should work. Anyways, currently I can add several poly vectors, which you can then create a shape with, however you can only create ONE shape.
Can anyone help me figure out on how to add more shapes?
// --------------------------------- //
// Project: PolyEdit
// --------------------------------- //
width=640
height=480
SETSCREEN width, height, 0 // Set the width and height of my screen
ALLOWESCAPE TRUE
SYSTEMPOINTER TRUE
setup: // Set up all variables and other systems
maxpoints=1
clicktogg=FALSE
TYPE poly
x=0
y=0
active=FALSE
ENDTYPE
GLOBAL polypoints[] AS poly
DIM polypoints[maxpoints]
GOTO main
main: // The main loop
MOUSESTATE mx, my, mba, mbb // Return mouse values
GOSUB polypoint
IF KEY(57) // Quickly resets the game
GOTO setup
ENDIF
drawpointer()
SHOWSCREEN
GOTO main
SUB polypoint:
IF mba=1 // Add a poly point once clicked
IF clicktogg=FALSE
clicktogg=TRUE
i=maxpoints-1
polypoints[i].x=mx
polypoints[i].y=my
polypoints[i].active=TRUE
maxpoints=maxpoints+1
LOCAL pointtmp AS poly
DIMPUSH polypoints[], pointtmp
FOR i=maxpoints-1 TO maxpoints-1
polypoints[i].x=0
polypoints[i].y=0
polypoints[i].active=FALSE
NEXT
ENDIF
ELSE
clicktogg=FALSE
ENDIF
FOR i=0 TO maxpoints-1 // Draw a little X at each poly point
IF polypoints[i].active=TRUE
PRINT "x", polypoints[i].x-7, polypoints[i].y-9
ENDIF
NEXT
STARTPOLY 1 // Draw the poly itself
FOR i=0 TO maxpoints-2
POLYVECTOR polypoints[i].x, polypoints[i].y, 0, 0, RGB(255,255,255)
NEXT
ENDPOLY
RETURN
ENDSUB
FUNCTION drawpointer:
DRAWLINE 0, my, width, my, RGB(255,255,255)
DRAWLINE mx, 0, mx, width, RGB(255,255,255)
ENDFUNCTION
Ps. Sorry for the messy code, I haven't cleaned it up yet
I haven´t used polivectors enough to feel confident in helping you out.
Out of memory, I recall one can start and end each polivector call, and should have at least 3 points within that that should be called in an anti-clockwise order.
I think you also can´t have some commands in between start and end poly.
I ran and read your code and it seems ( I could be wrong) that you are only calling polystart an polyend once and that will always draw a single polygon, you would have to call that again or probably put that inside a loop to call it as many times as you have full separated shapes.
If you want to resolve the thing in a single call, like your code shows, you could use the polynewstrip command?
That would lift the "pen" and create disconnected shapes.
I suspect though that calling polystart/end for each closed shape is a better solution and am confident I have seen code for that around the forum.
If I can find it I will add here, otherwise we just wait a bit for a more knowledge user to pop by. ;)
A quick look into the 2d snippets, I think this 2 examples will help you out:
http://www.glbasic.com/forum/index.php?topic=11073.0
In this case, Spacefractal is substituting drawrect for polyvectors and he is generating multiple rectangles shapes that way.
He seems to be using POLYNEWSTRIP command for that.
http://www.glbasic.com/forum/index.php?topic=10411.0
This is by Hemlos and also does a great job with polyvectors and multiple shapes.
I recall this impressed me a lot on the polyvector side of things so it might be a good place to start.
I hope that helps you out, sorry it took a while to answer. ;)
Polynews is faster than start/end.