From f37162283c31f6a48dc8f2dd9e7059c741618fc9 Mon Sep 17 00:00:00 2001 From: Ian C Date: Mon, 15 Aug 2005 01:55:25 +0000 Subject: *** empty log message *** --- glflag.mod/glflag.bmx | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 glflag.mod/glflag.bmx diff --git a/glflag.mod/glflag.bmx b/glflag.mod/glflag.bmx new file mode 100644 index 0000000..5b62530 --- /dev/null +++ b/glflag.mod/glflag.bmx @@ -0,0 +1,198 @@ +Module noddybox.glflag + +ModuleInfo "Framework: Simple Open GL Backdrop flag" +ModuleInfo "Copyright: Public Domain" +ModuleInfo "Author: Ian Cowburn" +ModuleInfo "Version: $Revision$" + +' $Id$ + +Import brl.Basic +Import pub.OpenGL + +Strict + +Type GLFlag + + ' These are considered private + ' + Const THRESHOLD:Float=0.0001 + Field v:GLFlagVertex[,] + Field width:Int + Field height:Int + Field txt:Int + Field zpos:Float + + ' Creates a new flag + ' + ' texture - Flag texture + ' horiz - Number of horizontal vertices + ' vert - Number of vertical vertices + ' size - Size of each square + ' tile - Whether the texture is tiled or not + ' z - Distance of flag (flags always created in the XY plane) + ' + ' Returns null for invalid parameters. + ' + Function Create:GLFlag(texture:Int, horiz:Int, vert:Int, size:Float, tile:Int, z:Float) + Local o:GLFlag + + If (horiz<2 Or vert<2) + Return Null + EndIf + + o=New GLFlag + + o.txt=texture + o.zpos=z + o.width=horiz + o.height=vert + o.v=New GLFlagVertex[horiz,vert] + + Local ox:Float + Local oy:Float + + ox=-(size*horiz)/2 + oy=-(size*horiz)/2 + + For Local x=0 Until horiz + For Local y=0 Until vert + Local v:GLFlagVertex=New GLFlagVertex + v.Set(ox+x*size,oy+y*size,0) + + If (tile) + v.u=(x&1) + v.v=(y&1) + Else + v.u=1.0/(horiz-1)*x + v.v=1.0/(vert-1)*(vert-1-y) + EndIf + + o.v[x,y]=v + Next + Next + + Return o + End Function + + ' Call to render the flag + ' + ' dampen - Scale to dampen movements by when bouncing movement + ' friction - Scale to slow down movements + ' + Method Render(dampen:Float=1.0, friction:Float=0.95) + glPushMatrix() + glTranslatef(0,0,zpos) + glBindTexture(GL_TEXTURE_2D,txt) + + For Local vert:GLFlagVertex=EachIn v + If (vert.xi<>0 Or vert.yi<>0 Or vert.zi<>0) + Local s:Float + + s=Sgn(vert.xi) + vert.xi:*friction + If (Abs(vert.xi)