summaryrefslogtreecommitdiff
path: root/vectorgfx.mod/vectorgfx.bmx
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2005-10-24 00:10:52 +0000
committerIan C <ianc@noddybox.co.uk>2005-10-24 00:10:52 +0000
commit53cc1b3be81ac220f6353bb5206b667261b3eab6 (patch)
tree404ae3aa0977272c6dbd434d1a8f794d0f001504 /vectorgfx.mod/vectorgfx.bmx
parent2c4a357e8f8e62fe50ab489519990e91e718c0d0 (diff)
Added a different method for handling collisions
Diffstat (limited to 'vectorgfx.mod/vectorgfx.bmx')
-rw-r--r--vectorgfx.mod/vectorgfx.bmx206
1 files changed, 69 insertions, 137 deletions
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