Drawing vector polygons with Max2D

BlitzMax Forums/BlitzMax Beginners Area/Drawing vector polygons with Max2D

jhague(Posted 2005) [#1]
I'm trying to draw the outline of a square--a vector graphics square in other words--scaled and rotated around its center point. This is easy to do with DrawPoly, except it results in a filled polygon, not an outline.

It seems so easy, with SetOrigin, SetScale, and SetRotation, but I end up with each line rotated around its start point, not the entire square rotated. Here's my code:

Graphics 1280,1024,32,60
HideMouse

While Not KeyHit(KEY_ESCAPE)
	Cls
	SetColor 255,255,0
	SetOrigin 1280/2,1024/2
	SetRotation 0
	SetScale 1,1
	DrawLine -64,-64,64,-64
	DrawLine 64,-64,64,64
	DrawLine 64,64,-64,64
	DrawLine -64,64,-64,-64
	Flip
Wend
This looks fine, until you change SetRotation to something other than zero (10, for example). Then it's obvious that each line is rotated around its start point.

(BTW, I may be a beginner with BlitzMax, but I'm comfortable writing this sort of code in OpenGL.)


SSS(Posted 2005) [#2]
what your code is doing is rotating each line individually. If you want it to rotate the whole object you'll have to code an entire vector graphics library for it that would handle transformations.


jhague(Posted 2005) [#3]
I guess a better question is "What are lines rotated around?" My instinct was the origin, but the correct answer seems to be "the starting point of the line." If it was the origin, then everything would work just fine.

I think Max2D gets this wrong, which is unfortunate. Images and polygons are rotated about the origin (or the handle of the image), but this doesn't carry over to other primitives. Why would anyone want to rotate a line around its start point? If Max2D handled things properly, then you could easily mimic the existing behavior, but more importantly you could do general vector graphics easily.


Yan(Posted 2005) [#4]
Look up SetHandle...
Graphics 800, 600, 0
HideMouse

SetColor 255,255,0
SetOrigin 400, 300

While Not KeyHit(KEY_ESCAPE)
	Cls
	
	SetRotation MilliSecs() / 10.0
	SetScale Sin(MilliSecs() / 10.0), Sin(MilliSecs() / 10.00)
	
	SetHandle 64, 64
	DrawLine 0, 0, 128, 0
	DrawLine 0, 0, 0, 128
	
	SetHandle -64, -64
	DrawLine 0, 0, -128, 0
	DrawLine 0, 0, 0, -128
	
	Flip
Wend



Haramanai(Posted 2005) [#5]
To handle Vector graphics I suggest you to use a Vector lib. Use the Vector2d type of the MaxPhysics Community Project And posted to the BlitzWiki
here it is : http://www.blitzwiki.org/index.php/MaxPhysics_Vector2D

Also I made a test with a simple Poly2d type ( We don't have right now Poly2d type)
Here it is Left and Right to turn

Hope I helped.
If you are serius with Vector graphics or with anythink that have Vectors in computers and more I sugest you to see this also tutorial : http://www.flipcode.com/articles/gprimer1_issue00.shtml
Don't kill me for my spelling...

Edit : I forgot.... to run the example you must have a copy of the Vector2d type from the link I posted in the begining. In the same dyrectory that you will save the codebox example of the post.


jhague(Posted 2005) [#6]
Thanks everyone! It sounds like Max2D just isn't set-up to handle vector graphics transformations without some additional work. That's a bit disappointing, because alll the tools are in place, and *some* of the primitives work perfectly using the exiting transform commands (like DrawPoly), but DrawLine does not. I'll stick to using OpenGL for this sort of thing, as it's ready roll right out of the box.


Haramanai(Posted 2005) [#7]
Yes it will be much easier to use OpenGL for Vector graphics But you will loose almost all the Max2D commands and to get some Images you will have to texture the quads in GL.
Also if you see the example I wrote, you will see that it's not really hard to optimize Max2D for Vector graphics.