Creating a Slower Animtex Frame Timer within RenderTween Loop?Help
Blitz3D Forums/Blitz3D Programming/Creating a Slower Animtex Frame Timer within RenderTween Loop?Help
| ||
Im working on my own Anim texturing function that will animate only the UV coords of the vertices. I need a way to be able to controll the Frame Rate for the animations so as they wont animate as fast as the Program will run. I also want it inside of Marks RenderTweening code so as the animations will still update smoothly regardles of how fast Program execution is going. Here is some code to show kind of what Im after, Youll Notice that the way I have a frame Limiter set up ( as Bogus as it is ) that there is a funny flicker between frames animating.Not Good ! There is a manual Frame counter Included ( keyhit(57) )so you can see that a smooth transfer between frames is possible just need a good way to set it up automaticly. Im really stuck here with somthing that could be really cool. Thanks for any Help you may Have to Offer. P.S I created this code for working on in the forums only so it may be a little sloppy but the concept is still there. Graphics3D 800,600,32,1 Const FPS=50 Global Cam,Cube,Tex,Piv1,Piv2 Global af#,atx# Dim atxarr(1,3,3) ;Animate Texture Dim UVarr#(15,1) ;U,V coords Setup() init=MilliSecs() period=1000/FPS time=MilliSecs()-period While Not KeyHit(1) Cls Repeat elapsed=MilliSecs()-time Until elapsed ticks=elapsed/period tween#=Float(elapsed Mod period)/Float(period) For k=1 To ticks time=time+period If k=ticks Then CaptureWorld Update( ) ; {EDITED} ; AnimTex( time ) ; {EDITED} ; UpdateWorld : tf#=tf#+1 Next RenderWorld tween# Ffps = ff#/(MilliSecs()-init)*1000 Tfps = tf#/(MilliSecs()-init)*1000 Afps = af#/(MilliSecs()-init)*1000 Text 5,10," FLIP fps : "+Ffps Text 5,30," Tween fps : "+Tfps Text 5,50," Anim fps : "+Afps Flip : ff#=ff#+1 Wend End ; Setup......................\ Function setup( ) Piv1=CreatePivot() Piv2=CreatePivot(Piv1) Cam=CreateCamera(Piv2) PositionEntity Cam,0,0,-10 Cube=CreateCube() Tex=CreateTexture(256,256) SetBuffer TextureBuffer( Tex ) For X=0 To 192 Step 64 B=B+50 Y=0 Color 0,0,50+B Rect X,Y,64,64,1 Next For X=0 To 192 Step 64 R=R+50 Y=64 Color 50+R,0,0 Rect X,Y,64,64,1 Next For X=0 To 192 Step 64 G=G+50 Y=128 Color 0,50+G,0 Rect X,Y,64,64,1 Next For X=0 To 192 Step 64 G=G+50 R=R+50 Y=192 Color 50+R,50+G,0 Rect X,Y,64,64,1 Next SetBuffer BackBuffer() S=GetSurface(cube,1) For Tri=0 To CountTriangles( S )-1 Step 2 vi=TriangleVertex( S,tri,0 ) VertexTexCoords( S,vi+0 ,.75 ,.75 ) VertexTexCoords( S,vi+1 ,.75 , 1 ) VertexTexCoords( S,vi+2 , 1 ,.75 ) VertexTexCoords( S,vi+3 , 1 , 1 ) Next EntityTexture Cube,Tex ;Load Arrays____ ;UV Array.................. For au#=0 To .75 Step .25 For av#=0 To .75 Step .25 count=1+count UVarr( count-1,0 )=av# UVarr( count-1,1 )=au# Next Next ;ATX Array ;ARRAY LIST......HARDCODED for Testing ; ?,?, startFrame ; ?,?, end frame ; ?,?, Vertexes current Frame ; ?,?, Vertex to animate UV coords ;Sequence # 1 atxarr(0,0,0)=1 atxarr(0,0,1)=4 atxarr(0,0,2)=2 atxarr(0,0,3)=0 atxarr(0,1,0)=5 atxarr(0,1,1)=8 atxarr(0,1,2)=7 atxarr(0,1,3)=8 ;Sequence # 2 atxarr(1,0,0)=9 atxarr(1,0,1)=12 atxarr(1,0,2)=12 atxarr(1,0,3)=12 atxarr(1,1,0)=13 atxarr(1,1,1)=16 atxarr(1,1,2)=13 atxarr(1,1,3)=16 End Function ;.........................../ ; Update....................\\ Function UpDate( ) If KeyDown(200) MX=+2 If KeyDown(208) MX=-2 If KeyDown(203) MY=+2 If KeyDown(205) MY=-2 TurnEntity Piv2,MX,0,0 TurnEntity Piv1,0,MY,0 End Function ;...........................// ;Animate Texture UVs........\\\ Function AnimTex( Time ) atx = time / 100 Mod 3 ;If KeyHit(57)=True atx=1 ; FOR MANUAL TESTING ONLY If atx=0 ; set atx to =1 for Manual Test af#=af#+1 For seq=0 To 1 For vi=0 To 1 sf=atxarr(seq,vi,0) ;Start Frame ef=atxarr(seq,vi,1) ;End Frame cf=atxarr(seq,vi,2) ;Current Frame c=atxarr(seq,vi,3) ;Veretex cf=cf+1 If cf>ef cf=sf End If U0#=UVarr(cf-1,0) V0#=UVarr(cf-1,1) U1#=U0#+.25 V1#=V0#+.25 S=GetSurface( Cube,1 ) VertexTexCoords(s,c+0,U1,V0 ) VertexTexCoords(s,c+1,U1,V1 ) VertexTexCoords(s,c+2,U0,V1 ) VertexTexCoords(s,c+3,U0,V0 ) atxarr(seq,vi,2)=cf Next Next ;atx=0 ;Reset atx for Manual Testing Only End If End Function ;.........................../// ;End Program................../// |
| ||
Well I got somthing a little smoother working. Setting the animframes is like a gessing game with this. Any Improvments would be great. Changes..... ( in while loop ) While Not KeyHit(1) Cls Repeat elapsed=MilliSecs()-time Until elapsed ticks=elapsed/period tween#=Float(elapsed Mod period)/Float(period) For k=1 To ticks time=time+period If k=ticks Then CaptureWorld Update( ) ; Changed this to ; atx=time/50 Mod 3 If Not atx AnimTex( ) UpdateWorld : tf#=tf#+1 Next RenderWorld tween# and in AnimTex Function() ;Animate Texture UVs........\\\ Function AnimTex( ) af#=af#+1 For seq=0 To 1 For vi=0 To 1 sf=atxarr(seq,vi,0) ;Start Frame ef=atxarr(seq,vi,1) ;End Frame cf=atxarr(seq,vi,2) ;Current Frame c=atxarr(seq,vi,3) ;Veretex cf=cf+1 If cf>ef cf=sf End If U0#=UVarr(cf-1,0) V0#=UVarr(cf-1,1) U1#=U0#+.25 V1#=V0#+.25 S=GetSurface( Cube,1 ) VertexTexCoords(s,c+0,U1,V0 ) VertexTexCoords(s,c+1,U1,V1 ) VertexTexCoords(s,c+2,U0,V1 ) VertexTexCoords(s,c+3,U0,V0 ) atxarr(seq,vi,2)=cf Next Next End Function Any Better Ideas Are welcome. |