Rounded corner polygon fast draw

Official forum for the Chipmunk2D Physics Library.

Rounded corner polygon fast draw

Postby abakobo » Tue Nov 29, 2016 6:22 am

Hi it's my first post here..

The new monkey2 language (monkey2.monkey-x.com) has a chipmunk port and I'm working on a debugdraw based on monkey2's 2d graphics module(mojo).
I've seen the chipmunk debugdraw implementation with the C demo but I can't really understand all the GL triangles code and it's 60 lines long so kind of low level for a monkey2 user.

In my implementation I have to draw n circle, n fat lines and one n sided poly. This is taking a lot of resources..

here's the code in monkey2 (should be self explanatory)
Code: Select all
_canvas.Color=New Color( fillColor.r,fillColor.g,fillColor.b,fillColor.a )

_canvas.DrawPoly( count,vertices )
      
_canvas.Color=New Color( outlineColor.r,outlineColor.g,outlineColor.b,outlineColor.a )   
_canvas.LineWidth=radius*2      
      
For Local i:=1 Until count      
   _canvas.DrawLine( verts[i-1].x,verts[i-1].y,verts[i].x,verts[i].y )
   _canvas.DrawCircle( verts[i-1].x,verts[i-1].y,radius )         
Next
_canvas.DrawLine( verts[count-1].x,verts[count-1].y,verts[0].x,verts[0].y )
_canvas.DrawCircle( verts[count-1].x,verts[count-1].y,radius )


-Is the attached png (and above algorithm) a correct way to draw these rounded corner polys?
-Is there a "trick" to draw these rounded polys faster?

thx and congrats for the great lib chipmunk is
Attachments
polyround.png
polyround.png (4.74 KiB) Viewed 1944 times
abakobo
 
Posts: 2
Joined: Thu Oct 20, 2016 5:12 am

Re: Rounded corner polygon fast draw

Postby slembcke » Tue Nov 29, 2016 12:10 pm

Not really unfortunately. If there is an API to draw bezier curves, you could use that. Otherwise you have to draw them out of other pieces.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 2 guests

cron