diff options
-rw-r--r-- | vectorgfx.mod/.cvsignore | 1 | ||||
-rw-r--r-- | vectorgfx.mod/doc/.cvsignore | 1 | ||||
-rw-r--r-- | vectorgfx.mod/doc/intro.html | 44 | ||||
-rw-r--r-- | vectorgfx.mod/vectorgfx.bmx | 206 |
4 files changed, 114 insertions, 138 deletions
diff --git a/vectorgfx.mod/.cvsignore b/vectorgfx.mod/.cvsignore index ae424d8..eda0494 100644 --- a/vectorgfx.mod/.cvsignore +++ b/vectorgfx.mod/.cvsignore @@ -3,4 +3,3 @@ vectorgfx.debug.win32.a vectorgfx.debug.win32.i
vectorgfx.release.win32.a
.bmx
-doc
diff --git a/vectorgfx.mod/doc/.cvsignore b/vectorgfx.mod/doc/.cvsignore new file mode 100644 index 0000000..2ec3ca5 --- /dev/null +++ b/vectorgfx.mod/doc/.cvsignore @@ -0,0 +1 @@ +commands.html
\ No newline at end of file diff --git a/vectorgfx.mod/doc/intro.html b/vectorgfx.mod/doc/intro.html new file mode 100644 index 0000000..c456aa1 --- /dev/null +++ b/vectorgfx.mod/doc/intro.html @@ -0,0 +1,44 @@ +<html> +<head> +<title></title> +<link rel="styleSheet" href="../../../../doc/css/bmxref.css" type="text/css"> +</head> +<body> +<h1>noddybox.VectorGfx</h1> +This module provides methods for displaying 2D vector graphics, and finding +collisions between objects. +This is implemented in two different ways depending on how you want collisions +work work. +<p> + +<ul> + +<li> +A collision map can be used, whereby objects can be drawn into the map when +being drawn onto the screen. A mask of these collisions, as well as the +actual objects and lines involved with the collisions is returned. This +method uses a <a href="commands.html#TVectorGfxCollisionMap" class="token"> +TVectorGfxCollisionMap</a> to store collision data, and is invoked using the +<a href=commands.html#DrawToCollisionMap class=token>DrawToCollisionMap</a> +method in +<a href="commands.html#TVectorGfxObject" class="token">TVectorGfxObject</a>. +</li> + +<li> +The other method is more manual in that a point of lists is returned (defined +using +<a href="commands.html#TVectorGfxPoint" class="token">TVectorGfxPoint</a> +objects) defining all the points drawn for an object. +This is invoked using the +<a href=commands.html#DrawToPointList class=token>DrawToPointList</a> +method in +<a href="commands.html#TVectorGfxObject" class="token">TVectorGfxObject</a>. +</li> + +</ul> + +It should be noted that the collision map method is not fool-proof. For +example, two diagnal lines may pass through each other without colliding. + +</body> +</html> diff --git a/vectorgfx.mod/vectorgfx.bmx b/vectorgfx.mod/vectorgfx.bmx index 3da763a..4dfc801 100644 --- a/vectorgfx.mod/vectorgfx.bmx +++ b/vectorgfx.mod/vectorgfx.bmx @@ -19,20 +19,33 @@ Import noddybox.vector Import noddybox.algorithm Rem +bbdoc: Wibble +about: Wobble +EndRem + +Rem bbdoc: Defines a method for drawing vector lines +about: For an example of creating a line drawing routine view the LineSolid type in the private section of this module. EndRem Type TVectorGfxLineStyle Abstract Rem - bbdoc: Draws a vector line. + bbdoc: Draws a vector line using IDs and @TVectorGfxCollisionMap method. returns: The or'ed mask of all collision IDs overwritten in @colmap by this line, or zero if @colmap is null. about: This routine must draw a line from @x1, @y1 to @x2, @y2 using the colour @r,@g,@b. about: @id, @obj and @line must be written into the collision map @colmap if @colmap is not null and @actor is false. about: If @colmap is set and @actor true, then collisions must be returned but no points written into the collision map. about: If @colmap is set, @actor is true and @list is not null then any collisions should be recorded into this list about: (no requirement for duplicate checking). + EndRem + Method LineToCollisionMap:Int(x1:Int, y1:Int, x2:Int, y2:Int, r:Int, g:Int, b:Int, id:Int, obj:TVectorGfxObject, line:Int, colmap:TVectorGfxCollisionMap, actor:Int, list:TList) Abstract + + Rem + bbdoc: Draws a vector line using the point list method. + about: This routine must draw a line from @x1, @y1 to @x2, @y2 using the colour @r,@g,@b. + about: If list is not null, then the points drawn must be stored in the list as @TVectorGfxPoint objects. about: For an example of creating a line drawing routine view the LineSolid type in the private section of this module. EndRem - Method Draw:Int(x1:Int, y1:Int, x2:Int, y2:Int, r:Int, g:Int, b:Int, id:Int, obj:TVectorGfxObject, line:Int, colmap:TVectorGfxCollisionMap, actor:Int, list:TList) Abstract + Method LineToPointList:Int(x1:Int, y1:Int, x2:Int, y2:Int, r:Int, g:Int, b:Int, list:TList) Abstract End Type Rem @@ -44,27 +57,6 @@ Function VectorGfxSetSolid() End Function Rem -bbdoc: Set to use alpha lines for drawing. -about: This mode draws vector lines using a @line_alpha for the lines, except for the end-points drawn with @end_alpha. -EndRem -Function VectorGfxSetAlpha(line_alpha:Double,end_alpha:Double) - Local l:LineAlpha=New LineAlpha - l.la=line_alpha - l.ea=end_alpha - Static.linedraw=l -End Function - -Rem -bbdoc: Set to use thick lines for drawing. -about: This mode draws vector lines using solid line, surrounded by points of alpha @line_alpha. -EndRem -Function VectorGfxSetThickAlpha(line_alpha:Double) - Local l:ThickAlpha=New ThickAlpha - l.a=line_alpha - Static.linedraw=l -End Function - -Rem bbdoc: Set to use a custom drawing method. EndRem Function VectorGfxSetCustom(linedraw:TVectorGfxLineStyle) @@ -114,9 +106,7 @@ End Type Rem bbdoc: Defines a vector graphics collision map. -about: Collisions in the library are defined using a bitmask (allowing 32 collision masks). -about: Note that with the way that lines are drawn in an object you are likely -about: to receive collisions for the IDs used by the lines in the object. +about: Collisions using this method in the library are defined using a bitmask (allowing 32 collision masks). EndRem Type TVectorGfxCollisionMap @@ -458,14 +448,30 @@ Type TVectorGfxObject End Method Rem - bbdoc: Draw the object. + bbdoc: Draw the object, not bothering about collisions. + EndRem + Method Draw() + rotated=New TVectorGfxPoint[points.length] + + For Local f:Int=0 Until points.length + Local p:TAlgoPointD=DoRotateD(points[f].x*scale,points[f].y*scale,ang) + rotated[f]=TVectorGfxPoint.Create(p.x,p.y) + Next + + For Local l:TVectorGfxLine=EachIn lines + Static.linedraw.LineToCollisionMap(x+rotated[l.i1].x,y+rotated[l.i1].y,x+rotated[l.i2].x,y+rotated[l.i2].y,l.r,l.g,l.b,0,Self,0,Null,True,Null) + Next + End Method + + Rem + bbdoc: Draw the object, using the collision map routines. returns: A bitmask of collisions. about: Draws the object. If @colmap is null then no collision processing takes place. about: If @actor is true then collision processing takes place, but the object will about: not write into the collision map. about: If @list is not null then any collisions will be written into this list. This only applies if @colmap is set and @actor true. EndRem - Method Draw:Int(colmap:TVectorGfxCollisionMap=Null, actor:Int=False, list:TList=Null) + Method DrawToCollisionMap:Int(colmap:TVectorGfxCollisionMap=Null, actor:Int=False, list:TList=Null) Local col:Int=0 rotated=New TVectorGfxPoint[points.length] @@ -478,19 +484,50 @@ Type TVectorGfxObject Local i:Int=0 For Local l:TVectorGfxLine=EachIn lines - col:|Static.linedraw.draw(x+rotated[l.i1].x,y+rotated[l.i1].y,x+rotated[l.i2].x,y+rotated[l.i2].y,l.r,l.g,l.b,l.id,Self,i,colmap,actor,list) + col:|Static.linedraw.LineToCollisionMap(x+rotated[l.i1].x,y+rotated[l.i1].y,x+rotated[l.i2].x,y+rotated[l.i2].y,l.r,l.g,l.b,l.id,Self,i,colmap,actor,list) i:+1 Next Return col End Method + + Rem + bbdoc: Draw the object, using returning a point list. + returns: The list of points plotted as @TVectorGfxPoint objects. + EndRem + Method DrawToPointList:TList() + Local list:TList=CreateList() + Local col:Int=0 + + rotated=New TVectorGfxPoint[points.length] + + For Local f:Int=0 Until points.length + Local p:TAlgoPointD=DoRotateD(points[f].x*scale,points[f].y*scale,ang) + rotated[f]=TVectorGfxPoint.Create(p.x,p.y) + Next + + Local i:Int=0 + + For Local l:TVectorGfxLine=EachIn lines + col:|Static.linedraw.LineToPointList(x+rotated[l.i1].x,y+rotated[l.i1].y,x+rotated[l.i2].x,y+rotated[l.i2].y,l.r,l.g,l.b,list) + i:+1 + Next + + Return list + End Method End Type Rem bbdoc: Defines a point EndRem Type TVectorGfxPoint + Rem + bbdoc: The X co-ordinate of the point + EndRem Field x:Int + Rem + bbdoc: The Y co-ordinate of the point + EndRem Field y:Int Rem @@ -581,7 +618,7 @@ Type Static End Type Type LineSolid Extends TVectorGfxLineStyle - Method Draw:Int(x1:Int, y1:Int, x2:Int, y2:Int, r:Int, g:Int, b:Int, id:Int, obj:TVectorGfxObject, line:Int, colmap:TVectorGfxCollisionMap, actor:Int, list:TList) + Method LineToCollisionMap:Int(x1:Int, y1:Int, x2:Int, y2:Int, r:Int, g:Int, b:Int, id:Int, obj:TVectorGfxObject, line:Int, colmap:TVectorGfxCollisionMap, actor:Int, list:TList) Local mask:Int=0 Local lp:TList=DoLine(x1,y1,x2,y2) @@ -607,124 +644,19 @@ Type LineSolid Extends TVectorGfxLineStyle Return mask End Method -End Type - -Type LineAlpha Extends TVectorGfxLineStyle - Field la:Double - Field ea:Double - Method Draw:Int(x1:Int, y1:Int, x2:Int, y2:Int, r:Int, g:Int, b:Int, id:Int, obj:TVectorGfxObject, line:Int, colmap:TVectorGfxCollisionMap, actor:Int, list:TList) + Method LineToPointList:Int(x1:Int, y1:Int, x2:Int, y2:Int, r:Int, g:Int, b:Int, list:TList) Local mask:Int=0 Local lp:TList=DoLine(x1,y1,x2,y2) - Local p:TAlgoPoint - Local a:Double=GetAlpha() SetColor(r,g,b) - SetAlpha(ea) - - p=TAlgoPoint(lp.RemoveFirst()) - - If colmap - If actor - Local c:TVectorGfxCollision=colmap.GetCollision(p.x,p.y) - - If c - mask:|c.mask - If list - list.AddLast(c) - EndIf - EndIf - Else - mask:|colmap.SetCollision(p.x,p.y,id,obj,line) - EndIf - EndIf - Plot(p.x,p.y) - - If lp.Count()=0 - Return id - EndIf - - p=TAlgoPoint(lp.RemoveLast()) - - If colmap - If actor - Local c:TVectorGfxCollision=colmap.GetCollision(p.x,p.y) - - If c - mask:|c.mask - If list - list.AddLast(c) - EndIf - EndIf - Else - mask:|colmap.SetCollision(p.x,p.y,id,obj,line) - EndIf - EndIf - Plot(p.x,p.y) - SetAlpha(la) - For Local p:TAlgoPoint=EachIn lp - If colmap - If actor - Local c:TVectorGfxCollision=colmap.GetCollision(p.x,p.y) - - If c - mask:|c.mask - If list - list.AddLast(c) - EndIf - EndIf - Else - mask:|colmap.SetCollision(p.x,p.y,id,obj,line) - EndIf - EndIf Plot(p.x,p.y) - Next - - SetAlpha(a) - - Return mask - End Method -End Type - - -Type ThickAlpha Extends TVectorGfxLineStyle - Field a:Double - - Method PlotPoint(x,y) - SetAlpha(a) - DrawRect(x-1,y-1,3,3) - SetAlpha(1.0) - Plot(x,y) - End Method - - Method Draw:Int(x1:Int, y1:Int, x2:Int, y2:Int, r:Int, g:Int, b:Int, id:Int, obj:TVectorGfxObject, line:Int, colmap:TVectorGfxCollisionMap, actor:Int, list:TList) - Local mask:Int=0 - Local lp:TList=DoLine(x1,y1,x2,y2) - - SetColor(r,g,b) - - For Local p:TAlgoPoint=EachIn lp - If colmap - If actor - Local c:TVectorGfxCollision=colmap.GetCollision(p.x,p.y) - - If c - mask:|c.mask - If list - list.AddLast(c) - EndIf - EndIf - Else - mask:|colmap.SetCollision(p.x,p.y,id,obj,line) - EndIf - EndIf - PlotPoint(p.x,p.y) + list.AddLast(TVectorGfxPoint.Create(p.x,p.y)) Next Return mask - End Method End Type |