diff options
Diffstat (limited to 'glflag.mod')
-rw-r--r-- | glflag.mod/.cvsignore | 3 | ||||
-rw-r--r-- | glflag.mod/glflag.bmx | 184 |
2 files changed, 91 insertions, 96 deletions
diff --git a/glflag.mod/.cvsignore b/glflag.mod/.cvsignore new file mode 100644 index 0000000..22829cb --- /dev/null +++ b/glflag.mod/.cvsignore @@ -0,0 +1,3 @@ +glflag.release.win32.i
+glflag.debug.win32.i
+.bmx
\ No newline at end of file diff --git a/glflag.mod/glflag.bmx b/glflag.mod/glflag.bmx index 5b62530..e0993cf 100644 --- a/glflag.mod/glflag.bmx +++ b/glflag.mod/glflag.bmx @@ -12,16 +12,27 @@ Import pub.OpenGL Strict -Type GLFlag +Type TGLFlag + ' These are public and can be used to modify the flag + ' + Field xpos:Float + Field ypos:Float + Field zpos:Float + Field xrot:Float + Field yrot:Float + Field zrot:Float + ' These are considered private ' - Const THRESHOLD:Float=0.0001 - Field v:GLFlagVertex[,] + Global static:Int=False + Global si:Float[]=Null + Field v:TGLFlagVertex[,] + Field cell:Int + Field move:Int Field width:Int Field height:Int Field txt:Int - Field zpos:Float ' Creates a new flag ' @@ -34,20 +45,36 @@ Type GLFlag ' ' Returns null for invalid parameters. ' - Function Create:GLFlag(texture:Int, horiz:Int, vert:Int, size:Float, tile:Int, z:Float) - Local o:GLFlag + Function Create:TGLFlag(texture:Int, horiz:Int, vert:Int, size:Float, tile:Int, z:Float) + Local o:TGLFlag If (horiz<2 Or vert<2) Return Null EndIf - o=New GLFlag + o=New TGLFlag - o.txt=texture + If (Not o.static) + o.si=New Float[3600] + For Local a:Float=0 Until 3600 + o.si[a]=Sin(a/10) + Next + o.static=True + EndIf + + o.xpos=0 + o.ypos=0 o.zpos=z + o.xrot=0 + o.yrot=0 + o.zrot=0 + + o.txt=texture o.width=horiz o.height=vert - o.v=New GLFlagVertex[horiz,vert] + o.cell=size + o.move=size/2 + o.v=New TGLFlagVertex[horiz,vert] Local ox:Float Local oy:Float @@ -57,8 +84,10 @@ Type GLFlag 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) + Local v:TGLFlagVertex=New TGLFlagVertex + v.x=ox+x*size + v.y=oy+y*size + v.z=0 If (tile) v.u=(x&1) @@ -77,122 +106,85 @@ Type GLFlag ' 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) + Method Render() glPushMatrix() - glTranslatef(0,0,zpos) + glTranslatef(xpos,ypos,zpos) + glRotatef(xrot,1,0,0) + glRotatef(yrot,0,1,0) + glRotatef(zrot,0,0,1) 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)<THRESHOLD) - vert.initxi=vert.initxi*dampen - If (vert.initxi<THRESHOLD) - vert.xi=0 - vert.x=vert.initx - Else - vert.xi=-s*vert.initxi*2 - EndIf - Else - vert.x:+vert.xi - EndIf - - s=Sgn(vert.yi) - vert.yi:*friction - If (Abs(vert.yi)<THRESHOLD) - vert.inityi=vert.inityi*dampen - If (vert.inityi<THRESHOLD) - vert.yi=0 - vert.y=vert.inity - Else - vert.yi=-s*vert.inityi*2 - EndIf - Else - vert.y:+vert.yi - EndIf - - s=Sgn(vert.zi) - vert.zi:*friction - If (Abs(vert.zi)<THRESHOLD) - vert.initzi=vert.initzi*dampen - If (vert.initzi<THRESHOLD) - vert.zi=0 - vert.z=vert.initx - Else - vert.zi=-s*vert.initzi*2 - EndIf - Else - vert.z:+vert.zi - EndIf - EndIf + For Local vert:TGLFlagVertex=EachIn v + vert.ax=(vert.ax+vert.aix) Mod 3600 + vert.ay=(vert.ay+vert.aiy) Mod 3600 + vert.az=(vert.az+vert.aiz) Mod 3600 + vert.cx=vert.x+si[vert.ax]*move + vert.cy=vert.y+si[vert.ay]*move + vert.cz=vert.z+si[vert.az]*move Next For Local x:Int=0 Until width-1 glBegin(GL_TRIANGLE_STRIP) For Local y:Int=0 Until height glTexCoord2f(v[x,y].u,v[x,y].v) - glVertex3f(v[x,y].x,v[x,y].y,v[x,y].z) + glVertex3f(v[x,y].cx,v[x,y].cy,v[x,y].cz) glTexCoord2f(v[x+1,y].u,v[x+1,y].v) - glVertex3f(v[x+1,y].x,v[x+1,y].y,v[x+1,y].z) + glVertex3f(v[x+1,y].cx,v[x+1,y].cy,v[x+1,y].cz) Next glEnd() Next glPopMatrix() End Method + ' Sets the amount of movement for vertex movement (defaults to half the cell size) + ' + Method SetMove(m:Int) + move=m + End Method + ' Sets the movements for a vertex ' ' x - The X co-ord of the vertex ' y - The Y co-ord of the vertex - ' xi - The X movement - ' yi - The Y movement - ' zi - The Z movement + ' angz - The initial angle (movement is done on a sine wave with 3600 positions) for the Z co-ord + ' angiz - The angle increment for the Z co-ord + ' angx - Ditto for X + ' angix - Ditto for X + ' angy - And Y + ' angiy - And Y ' - Method Nudge(x:Int, y:Int, xi:Float, yi:Float, zi:Float) - v[x,y].initxi=Abs(xi) - v[x,y].inityi=Abs(yi) - v[x,y].initzi=Abs(zi) - v[x,y].xi=xi - v[x,y].yi=yi - v[x,y].zi=zi + ' Note increments must be positive - to simulate negative ones pass a large increment (eg. 3599 for -1) + ' + Method Nudge(x:Int, y:Int, angz:Float, angiz:Float=10, angx:Float=0, angix:Float=0, angy:Float=0, angiy:Float=0) + v[x,y].ax=angx + v[x,y].ay=angy + v[x,y].az=angz + v[x,y].aix=angix + v[x,y].aiy=angiy + v[x,y].aiz=angiz End Method End Type -Type GLFlagVertex +Type TGLFlagVertex Field x#,y#,z# + Field cx#,cy#,cz# Field u#,v# - Field initx#,inity#,initz# - Field initxi#,inityi#,initzi# - Field xi#,yi#,zi# + Field ax#,ay#,az# + Field aix#,aiy#,aiz# Method New() x=0 y=0 z=0 - initx=0 - inity=0 - initz=0 - initxi=0 - inityi=0 - initzi=0 - xi=0 - yi=0 - zi=0 - End Method - - Method Set(xc:Float, yc:Float, zc:Float) - x=xc - initx=xc - y=yc - inity=yc - z=zc - initz=zc + cx=0 + cy=0 + cz=0 + ax=0 + ay=0 + az=0 + aix=0 + aiy=0 + aiz=0 End Method End Type
\ No newline at end of file |