About Monkey 2 › Forums › Monkey 2 Code Library › chipmunk debugdraw
This topic contains 0 replies, has 1 voice, and was last updated by
abakobo
1 year, 10 months ago.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
June 11, 2017 at 7:53 am #8611
here’s my chumpmunk debug draw, it has some more features than the one provided with the module:
-rounded corner polys and rounded end segments
-chose between FastDraw and Complete Draw
-complete draw shows sleeping bodies (greyed), contact points, constrains and make a border to each shape so they are not mixed if of the same color.
-a canvas extension for setting a camera by centerpoint, zoom and rotationMonkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330#Import "<std>"#Import "<mojo>"#Import "<chipmunk>"Using std..Using mojo..Using chipmunk..Class ChipmunkDebuggerField options:=New cpSpaceDebugDrawOptionsMethod New()options.drawCircle=DrawCircleFoptions.drawSegment=DrawSegmentFoptions.drawFatSegment=DrawFatSegmentFoptions.drawPolygon=DrawPolygonFoptions.drawDot=DrawDotFoptions.colorForShape=ColorForShapeFoptions.flags=CP_SPACE_DEBUG_DRAW_SHAPES'|CP_SPACE_DEBUG_DRAW_CONSTRAINTS|CP_SPACE_DEBUG_DRAW_COLLISION_POINTSoptions.shapeOutlineColor=RGBAColor(200.0/255.0, 210.0/255.0, 230.0/255.0, 1.0)options.constraintColor=RGBAColor(0.0, 0.75, 0.0, 1.0)options.collisionPointColor=RGBAColor(1.0, 0.0, 0.0, 1.0)EndMethod DebugDraw( canvas:Canvas,space:cpSpace )_canvas=canvascpSpaceDebugDraw( space,options )EndMethod FastDraw()options.drawCircle=DrawCircleFoptions.drawSegment=DrawSegmentFoptions.drawFatSegment=DrawFatSegmentFoptions.drawPolygon=DrawPolygonFoptions.drawDot=DrawDotFoptions.colorForShape=ColorForShapeFoptions.flags=CP_SPACE_DEBUG_DRAW_SHAPESEndMethod CompleteDraw()options.drawCircle=DrawCircleoptions.drawSegment=DrawSegmentoptions.drawFatSegment=DrawFatSegmentoptions.drawPolygon=DrawPolygonoptions.drawDot=DrawDotoptions.colorForShape=ColorForShapeoptions.flags=CP_SPACE_DEBUG_DRAW_SHAPES |CP_SPACE_DEBUG_DRAW_CONSTRAINTS|CP_SPACE_DEBUG_DRAW_COLLISION_POINTSEndProtectedMethod DrawCircle( pos:cpVect,angle:cpFloat,radius:cpFloat,outlineColor:cpSpaceDebugColor,fillColor:cpSpaceDebugColor,data:cpDataPointer )_canvas.Color=New Color( outlineColor.r,outlineColor.g,outlineColor.b,outlineColor.a )_canvas.DrawCircle( pos.x,pos.y,radius )_canvas.Color=New Color( fillColor.r,fillColor.g,fillColor.b,fillColor.a )_canvas.DrawCircle( pos.x,pos.y,radius*0.75 )_canvas.Color=Color.Black_canvas.LineWidth=0_canvas.DrawLine( pos.x,pos.y,pos.x+Cos( angle )*radius,pos.y+Sin( angle )*radius )EndMethod DrawSegment( a:cpVect,b:cpVect,color:cpSpaceDebugColor,data:cpDataPointer=Null )_canvas.Color=New Color( color.r,color.g,color.b,color.a )_canvas.LineWidth=0_canvas.DrawLine( a.x,a.y,b.x,b.y )EndMethod DrawFatSegment( a:cpVect,b:cpVect,radius:cpFloat,outlineColor:cpSpaceDebugColor,fillColor:cpSpaceDebugColor,data:cpDataPointer )_canvas.BlendMode=BlendMode.Opaque_canvas.LineWidth=radius*2_canvas.Color=New Color( outlineColor.r,outlineColor.g,outlineColor.b,outlineColor.a )_canvas.DrawLine( a.x,a.y,b.x,b.y )_canvas.DrawCircle( a.x,a.y,radius )_canvas.DrawCircle( b.x,b.y,radius )_canvas.Color=New Color( fillColor.r,fillColor.g,fillColor.b,fillColor.a )_canvas.LineWidth=radius*2*0.65_canvas.DrawLine( a.x,a.y,b.x,b.y )_canvas.DrawCircle( a.x,a.y,radius*0.65 )_canvas.DrawCircle( b.x,b.y,radius*0.65 )EndMethod DrawPolygon( count:Int,verts:cpVect Ptr,radius:cpFloat,outlineColor:cpSpaceDebugColor,fillColor:cpSpaceDebugColor,data:cpDataPointer )_canvas.BlendMode=BlendMode.OpaqueLocal vs:=New Float[count*2]For Local i:=0 Until countvs[i*2]=verts[i].xvs[i*2+1]=verts[i].yNext_canvas.Color=New Color( fillColor.r,fillColor.g,fillColor.b,fillColor.a )_canvas.DrawPolys( count,1,vs )_canvas.Color=New Color( outlineColor.r,outlineColor.g,outlineColor.b,outlineColor.a )If radius=0For Local i:=1 Until countDrawSegment( verts[i-1],verts[i],outlineColor)NextDrawSegment( verts[0],verts[count-1],outlineColor)Else_canvas.LineWidth=radius*2For 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 )EndifEndMethod DrawDot( size:cpFloat,pos:cpVect,color:cpSpaceDebugColor,data:cpDataPointer )_canvas.Color=New Color( color.r,color.g,color.b,color.a )_canvas.PointSize=size_canvas.DrawPoint( pos.x,pos.y )EndMethod ColorForShape:cpSpaceDebugColor( shape:cpShape,data:cpDataPointer )If cpShapeGetSensor(shape)return LAColor(1.0, 0.1)ElseLocal body:=cpShapeGetBody(shape)If cpBodyIsSleeping(body)Return LAColor(0.2, 1.0)ElseLocal color:=_colors[shape]If color.a Return colorcolor.r=Rnd( 1 )color.g=Rnd( 1-color.r )color.b=Rnd( 1-color.r-color.g )color.a=1_colors[shape]=colorReturn colorEndifEndifEndMethod DrawCircleF( pos:cpVect,angle:cpFloat,radius:cpFloat,outlineColor:cpSpaceDebugColor,fillColor:cpSpaceDebugColor,data:cpDataPointer )_canvas.Color=New Color( fillColor.r,fillColor.g,fillColor.b,fillColor.a )_canvas.DrawCircle( pos.x,pos.y,radius )_canvas.Color=Color.Black_canvas.LineWidth=0_canvas.DrawLine( pos.x,pos.y,pos.x+Cos( angle )*radius,pos.y+Sin( angle )*radius )EndMethod DrawSegmentF( a:cpVect,b:cpVect,color:cpSpaceDebugColor,data:cpDataPointer )_canvas.Color=New Color( color.r,color.g,color.b,color.a )_canvas.LineWidth=0_canvas.DrawLine( a.x,a.y,b.x,b.y )EndMethod DrawFatSegmentF( a:cpVect,b:cpVect,radius:cpFloat,outlineColor:cpSpaceDebugColor,fillColor:cpSpaceDebugColor,data:cpDataPointer )_canvas.Color=New Color( fillColor.r,fillColor.g,fillColor.b,fillColor.a )_canvas.LineWidth=radius*2_canvas.BlendMode=BlendMode.Opaque_canvas.DrawLine( a.x,a.y,b.x,b.y )_canvas.DrawCircle( a.x,a.y,radius )_canvas.DrawCircle( b.x,b.y,radius )EndMethod DrawPolygonF( count:Int,verts:cpVect Ptr,radius:cpFloat,outlineColor:cpSpaceDebugColor,fillColor:cpSpaceDebugColor,data:cpDataPointer )_canvas.BlendMode=BlendMode.Opaque_canvas.Color=New Color( fillColor.r,fillColor.g,fillColor.b,fillColor.a )'Local rad:=radius*2_canvas.LineWidth=radius*2For 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 )EndMethod DrawDotF( size:cpFloat,pos:cpVect,color:cpSpaceDebugColor,data:cpDataPointer )_canvas.Color=New Color( color.r,color.g,color.b,color.a )_canvas.PointSize=size_canvas.DrawPoint( pos.x,pos.y )EndMethod ColorForShapeF:cpSpaceDebugColor( shape:cpShape,data:cpDataPointer )Local color:=_colors[shape]If color.a Return colorcolor.r=Rnd( 1 )color.g=Rnd( 1-color.r )color.b=Rnd( 1-color.r-color.g )color.a=1_colors[shape]=colorReturn colorEndPrivateField _colors:=New Map<cpShape,cpSpaceDebugColor>Field _canvas:CanvasEndFunction RGBAColor:cpSpaceDebugColor (r:float, g:float, b:float, a:float)Local color:cpSpaceDebugColorcolor.r=rcolor.g=gcolor.b=bcolor.a=areturn colorEndFunction LAColor:cpSpaceDebugColor (l:float , a:float )Local color:cpSpaceDebugColorcolor.r=lcolor.g=lcolor.b=lcolor.a=areturn colorEndClass Canvas ExtensionMethod SetCamera(centerpoint_x:Float,centerpoint_y:Float,zoom:Float=1.0,rotation:Float=0.0)Translate(Viewport.Width/2,Viewport.Height/2)Scale(zoom,zoom)Rotate(rotation)Translate(-centerpoint_x,-centerpoint_y)EndMethod SetCamera(centerpoint:Vec2f,zoom:Float=1.0,rotation:Float=0)Translate(Viewport.Width/2,Viewport.Height/2)Scale(zoom,zoom)Rotate(rotation)Translate(-centerpoint)EndEnd -
AuthorPosts
Viewing 1 post (of 1 total)
You must be logged in to reply to this topic.