summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2005-10-10 23:03:00 +0000
committerIan C <ianc@noddybox.co.uk>2005-10-10 23:03:00 +0000
commit388748a48418441108e039d97d0623826d9bc709 (patch)
treed00fc52f8fc26256ff78bfd8922c681e153cb125
parent48ec73936fa8458f27cd71e01b9a9cee47e5b62f (diff)
Added routines to get adjusted co-ords and normals from lines.
-rw-r--r--vectorgfx.mod/vectorgfx.bmx59
1 files changed, 55 insertions, 4 deletions
diff --git a/vectorgfx.mod/vectorgfx.bmx b/vectorgfx.mod/vectorgfx.bmx
index f504141..a79b79c 100644
--- a/vectorgfx.mod/vectorgfx.bmx
+++ b/vectorgfx.mod/vectorgfx.bmx
@@ -22,6 +22,11 @@ Rem
bbdoc: Defines a method for drawing vector lines
EndRem
Type TVectorGfxLineStyle Abstract
+ Rem
+ bbdoc: Draws a vector line.
+ returns: The or'ed mask of all collision IDs overwritten in @colmap by this line.
+ about: This routine must draw a line from @x1, @y1 to @x2, @y2 using the colour @r,@g,@b. @id must be written into the collision map @colmap.
+ EndRem
Method Draw:Int(x1:Int, y1:Int, x2:Int, y2:Int, r:Int, g:Int, b:Int, id:Int, colmap:TVectorGfxCollisionMap) Abstract
End Type
@@ -55,6 +60,13 @@ Function VectorGfxSetThickAlpha(line_alpha:Double)
End Function
Rem
+bbdoc: Set to use a custom drawing method.
+EndRem
+Function VectorGfxSetCustom(linedraw:TVectorGfxLineStyle)
+ Static.linedraw=linedraw
+End Function
+
+Rem
bbdoc: Defines a vector graphics collision map.
about: Collisions in the library a defined using a bitmask (allowing 32 collision masks).
EndRem
@@ -129,8 +141,10 @@ Rem
bbdoc: Defines a 2D vector graphics object
EndRem
Type TVectorGfxObject
+ Rem
+ bbdoc: The lines making up this object
+ EndRem
Field lines:TList
-
Rem
bbdoc: The X co-ordinate of the object
EndRem
@@ -160,6 +174,7 @@ Type TVectorGfxObject
about: @line is the line to add.
EndRem
Method AddLine(line:TVectorGfxLine)
+ line.parent=Self
lines.AddLast(line)
End Method
@@ -168,6 +183,7 @@ Type TVectorGfxObject
about: @line is the line to remove.
EndRem
Method RemoveLine(line:TVectorGfxLine)
+ line.parent=Null
lines.Remove(line)
End Method
@@ -232,10 +248,9 @@ Type TVectorGfxObject
Method Draw:Int(colmap:TVectorGfxCollisionMap)
Local col:Int=0
For Local l:TVectorGfxLine=EachIn lines
- Local p1:TAlgoPoint=DoRotate(l.x1,l.y1,ang)
- Local p2:TAlgoPoint=DoRotate(l.x2,l.y2,ang)
+ Local p:TAlgoPoint[]=l.AdjustedCoords()
- col:|Static.linedraw.draw(x+p1.x,y+p1.y,x+p2.x,y+p2.y,l.r,l.g,l.b,l.id,colmap)
+ col:|Static.linedraw.draw(p[0].x,p[0].y,p[1].x,p[1].y,l.r,l.g,l.b,l.id,colmap)
Next
Return col
@@ -246,6 +261,7 @@ Rem
bbdoc: Defines a line
EndRem
Type TVectorGfxLine
+ Field parent:TVectorGfxObject
Field x1:Int
Field y1:Int
Field x2:Int
@@ -276,6 +292,41 @@ Type TVectorGfxLine
End Function
Rem
+ bbdoc: The line's normal.
+ returns: The normal of the line.
+ about: When this line is assigned to an object, this will return the normal due to the rotation of the object
+ EndRem
+ Method Normal:TVector()
+ Local p:TAlgoPoint[]=AdjustedCoords()
+ Local v:TVector=TVector.Create(p[0].y-p[1].y,p[1].x-p[0].x)
+ v.Normalise()
+ Return v
+ End Method
+
+ Rem
+ bbdoc: The line's rotated and adjusted co-ords.
+ returns: The two points defining the screen co-ordinates used.
+ about: This won't really return anything useful unless the line is assigned to an object.
+ EndRem
+ Method AdjustedCoords:TAlgoPoint[]()
+ Local p:TAlgoPoint[]=New TAlgoPoint[2]
+
+ If parent<>Null
+ p[0]=DoRotate(x1,y1,parent.ang)
+ p[1]=DoRotate(x2,y2,parent.ang)
+ p[0].x:+parent.x
+ p[0].y:+parent.y
+ p[1].x:+parent.x
+ p[1].y:+parent.y
+ Else
+ p[0]=TAlgoPoint.Create(x1,y1)
+ p[1]=TAlgoPoint.Create(x2,y2)
+ EndIf
+
+ Return p
+ End Method
+
+ Rem
bbdoc: This is for internal library use.
EndRem
Function Load:TVectorGfxLine(s:TStream)