Global info1$="Driver";Include "../start.bb"Graphics3D 1024,768,32,1SetBuffer BackBuffer()Const GRAVITY#=-.01Const BODY=1,WHEEL=2,SCENE=3Collisions BODY,SCENE,2,3Collisions WHEEL,SCENE,2,3terr=LoadTerrain( "heightmap_256.bmp" )ScaleEntity terr,1000/TerrainSize(terr),70,1000/TerrainSize(terr)TerrainDetail terr,1000,TrueTerrainShading terr,TruePositionEntity terr,-500,0,-500tex=LoadTexture( "terrain-1.jpg" )ScaleTexture tex,15,15 ;50;50EntityTexture terr,texEntityType terr,SCENEcar=LoadMesh( "car.x" )ScaleMesh car,1,1,-1FlipMesh carFitMesh car,-1.5,-1,-3,3,2,6PositionEntity car,0,70,0EntityShininess car,1EntityType car,BODYGlobal wheels[4]cnt=1For z#=1.5 To -1.5 Step -3For x#=-1 To 1 Step 2 wheels[cnt]=CreateSphere( 8,car ) EntityAlpha wheels[cnt],.5 ScaleEntity wheels[cnt],.5,.5,.5 EntityRadius wheels[cnt],.5 PositionEntity wheels[cnt],x,0,z EntityType wheels[cnt],WHEEL cnt=cnt+1NextNextlight=CreateLight()TurnEntity light,45,45,0target=CreatePivot( car )PositionEntity target,0,5,-12camera=CreateCamera()CameraClsColor camera,0,128,255CameraRange camera,0.1,1000speed#=0x_vel#=0:prev_x#=EntityX( car )y_vel#=0:prev_y#=EntityY( car )z_vel#=0:prev_z#=EntityZ( car ); init motionblurmotion_blur_on=1motion_blur_quad=create_blurquad(camera) ; create a special 4-tris quad with a zero Alpha center vertex.EntityFX motion_blur_quad,2 Or 1motion_blur_tex=CreateTexture(1024,1024,256 Or 2); use the following remarked lines if you need to visually control texture alignement (skip copyrect render to tex!);SetBuffer TextureBuffer(motion_blur_tex);Color 0,255,0 ;Rect 0,128,1024,768,0;SetBuffer BackBuffer()EntityTexture motion_blur_quad,motion_blur_texTranslateEntity motion_blur_quad,-(1.0/2048.0),0-(1.0/2048.0), 0.995 ;1.0 would be exact screen matching (pixelperfect)EntityOrder motion_blur_quad,-1000;this 2nd "quad" will amplify the effect (tho slower, so maybe remove it):motion_blur_quad2=CopyEntity(motion_blur_quad)TranslateEntity motion_blur_quad2,0,0,-.0025EntityParent motion_blur_quad2,motion_blur_quadEntityOrder motion_blur_quad2,-2000; eo init motion blurWhile Not KeyHit(1) ; motion blur If KeyHit(57) ; space= toggle motion blur motion_blur_on=motion_blur_on Xor 1 If motion_blur_on=0 Then HideEntity motion_blur_quad Else ShowEntity motion_blur_quad EndIf EndIf ; update motion blur texture If motion_blur_on<>0 CopyRect 0,0,1024,1024,0,128,BackBuffer(),TextureBuffer(motion_blur_tex) EndIf ; ;align car to wheels zx#=(EntityX( wheels[2],True )+EntityX( wheels[4],True ))/2 zx=zx-(EntityX( wheels[1],True )+EntityX( wheels[3],True ))/2 zy#=(EntityY( wheels[2],True )+EntityY( wheels[4],True ))/2 zy=zy-(EntityY( wheels[1],True )+EntityY( wheels[3],True ))/2 zz#=(EntityZ( wheels[2],True )+EntityZ( wheels[4],True ))/2 zz=zz-(EntityZ( wheels[1],True )+EntityZ( wheels[3],True ))/2 AlignToVector car,zx,zy,zz,1 zx#=(EntityX( wheels[1],True )+EntityX( wheels[2],True ))/2 zx=zx-(EntityX( wheels[3],True )+EntityX( wheels[4],True ))/2 zy#=(EntityY( wheels[1],True )+EntityY( wheels[2],True ))/2 zy=zy-(EntityY( wheels[3],True )+EntityY( wheels[4],True ))/2 zz#=(EntityZ( wheels[1],True )+EntityZ( wheels[2],True ))/2 zz=zz-(EntityZ( wheels[3],True )+EntityZ( wheels[4],True ))/2 AlignToVector car,zx,zy,zz,3 ;calculate car velocities cx#=EntityX( car ):x_vel=cx-prev_x:prev_x=cx cy#=EntityY( car ):y_vel=cy-prev_y:prev_y=cy cz#=EntityZ( car ):z_vel=cz-prev_z:prev_z=cz ;resposition wheels cnt=1 For z=1.5 To -1.5 Step -3 For x=-1 To 1 Step 2; PositionEntity wheels[cnt],0,0,0; ResetEntity wheels[cnt] PositionEntity wheels[cnt],x,-1,z cnt=cnt+1 Next Next ;move car If KeyDown(203) TurnEntity car,0,3,0 If KeyDown(205) TurnEntity car,0,-3,0 If EntityCollided( car,SCENE ) If KeyDown(200) speed=speed+.02 If speed>.7 speed=.7 Else If KeyDown(208) speed=speed-.02 If speed<-.5 speed=-.5 Else speed=speed*.9 EndIf MoveEntity car,0,0,speed TranslateEntity car,0,GRAVITY,0 Else TranslateEntity car,x_vel,y_vel+GRAVITY,z_vel EndIf ;update camera If speed>=0 dx#=EntityX( target,True )-EntityX( camera ) dy#=EntityY( target,True )-EntityY( camera ) dz#=EntityZ( target,True )-EntityZ( camera ) TranslateEntity camera,dx*.1,dy*.1,dz*.1 EndIf PointEntity camera,car UpdateWorld RenderWorld Text 0,0,"space= toggle motion blur" VWait:Flip 0 WendEndFunction create_blurquad(par=0) Local al1#,al2#,m,s,v0,v1,v2,tr al1#=1.0 al2#=0.2 m=CreateMesh() s=CreateSurface(m) v0=AddVertex(s,-1,-1,0, 0,1) v1=AddVertex(s,+1,-1,0, 1,1) v2=AddVertex(s, 0,0 ,0, .5,.5) VertexColor s,v0,255,255,255,al1# VertexColor s,v1,255,255,255,al1# VertexColor s,v2,255,255,255,al2# tr=AddTriangle(s,v0,v1,v2) v0=AddVertex(s,+1,-1,0, 1,1) v1=AddVertex(s,+1,+1,0, 1,0) v2=AddVertex(s, 0,0 ,0, .5,.5) VertexColor s,v0,255,255,255,al1# VertexColor s,v1,255,255,255,al1# VertexColor s,v2,255,255,255,al2# tr=AddTriangle(s,v0,v1,v2) v0=AddVertex(s,+1,+1,0, 1,0) v1=AddVertex(s,-1,+1,0, 0,0) v2=AddVertex(s, 0,0 ,0, .5,.5) VertexColor s,v0,255,255,255,al1# VertexColor s,v1,255,255,255,al1# VertexColor s,v2,255,255,255,al2# tr=AddTriangle(s,v0,v1,v2) v0=AddVertex(s,-1,+1,0, 0,0) v1=AddVertex(s,-1,-1,0, 0,1) v2=AddVertex(s, 0,0 ,0, .5,.5) VertexColor s,v0,255,255,255,al1# VertexColor s,v1,255,255,255,al1# VertexColor s,v2,255,255,255,al2# tr=AddTriangle(s,v0,v1,v2) FlipMesh m UpdateNormals m If par <>0 Then EntityParent m,par Return mEnd Function
Global info1$="Driver";Include "../start.bb"Graphics3D 1024,768,32,1SetBuffer BackBuffer()Const GRAVITY#=-.01Const BODY=1,WHEEL=2,SCENE=3Collisions BODY,SCENE,2,3Collisions WHEEL,SCENE,2,3terr=LoadTerrain( "heightmap_256.bmp" )ScaleEntity terr,1000/TerrainSize(terr),70,1000/TerrainSize(terr)TerrainDetail terr,1000,TrueTerrainShading terr,TruePositionEntity terr,-500,0,-500tex=LoadTexture( "terrain-1.jpg" )ScaleTexture tex,15,15 ;50;50EntityTexture terr,texEntityType terr,SCENEcar=LoadMesh( "car.x" )ScaleMesh car,1,1,-1FlipMesh carFitMesh car,-1.5,-1,-3,3,2,6PositionEntity car,0,70,0EntityShininess car,1EntityType car,BODYGlobal wheels[4]cnt=1For z#=1.5 To -1.5 Step -3For x#=-1 To 1 Step 2 wheels[cnt]=CreateSphere( 8,car ) EntityAlpha wheels[cnt],.5 ScaleEntity wheels[cnt],.5,.5,.5 EntityRadius wheels[cnt],.5 PositionEntity wheels[cnt],x,0,z EntityType wheels[cnt],WHEEL cnt=cnt+1NextNextlight=CreateLight()TurnEntity light,45,45,0target=CreatePivot( car )PositionEntity target,0,5,-12camera=CreateCamera()CameraClsColor camera,0,128,255CameraRange camera,0.1,1000speed#=0x_vel#=0:prev_x#=EntityX( car )y_vel#=0:prev_y#=EntityY( car )z_vel#=0:prev_z#=EntityZ( car )Global m; init motionblurmotion_blur_on=1motion_blur_quad=create_blurquad(camera) ; create a special 4-tris quad with a zero Alpha center vertex.;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; changeEntityFX motion_blur_quad,3;2 Or 1motion_blur_tex=CreateTexture(1024,1024,256); Or 2);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; use the following remarked lines if you need to visually control texture alignement (skip copyrect render to tex!);SetBuffer TextureBuffer(motion_blur_tex);Color 0,255,0 ;Rect 0,128,1024,768,0;SetBuffer BackBuffer()EntityTexture motion_blur_quad,motion_blur_texTranslateEntity motion_blur_quad,-(1.0/2048.0),0-(1.0/2048.0), 0.995; 1.0 would be exact screen matching (pixelperfect)EntityOrder motion_blur_quad,-1000;this 2nd "quad" will amplify the effect (tho slower, so maybe remove it):motion_blur_quad2=CopyEntity(motion_blur_quad)TranslateEntity motion_blur_quad2,0,0,-.0025EntityParent motion_blur_quad2,motion_blur_quadEntityOrder motion_blur_quad2,-2000; eo init motion blur;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; addTextureBlend motion_blur_tex,2EntityAlpha motion_blur_quad,.25EntityAlpha motion_blur_quad2,.25;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; While Not KeyHit(1) ; motion blur If KeyHit(57) ; space= toggle motion blur motion_blur_on=motion_blur_on Xor 1 If motion_blur_on=0 Then HideEntity motion_blur_quad Else ShowEntity motion_blur_quad EndIf EndIf ; update motion blur texture If motion_blur_on=True CopyRect 0,0,1024,1024,0,128,BackBuffer(),TextureBuffer(motion_blur_tex) EndIf ; ;align car to wheels zx#=(EntityX( wheels[2],True )+EntityX( wheels[4],True ))/2 zx=zx-(EntityX( wheels[1],True )+EntityX( wheels[3],True ))/2 zy#=(EntityY( wheels[2],True )+EntityY( wheels[4],True ))/2 zy=zy-(EntityY( wheels[1],True )+EntityY( wheels[3],True ))/2 zz#=(EntityZ( wheels[2],True )+EntityZ( wheels[4],True ))/2 zz=zz-(EntityZ( wheels[1],True )+EntityZ( wheels[3],True ))/2 AlignToVector car,zx,zy,zz,1 zx#=(EntityX( wheels[1],True )+EntityX( wheels[2],True ))/2 zx=zx-(EntityX( wheels[3],True )+EntityX( wheels[4],True ))/2 zy#=(EntityY( wheels[1],True )+EntityY( wheels[2],True ))/2 zy=zy-(EntityY( wheels[3],True )+EntityY( wheels[4],True ))/2 zz#=(EntityZ( wheels[1],True )+EntityZ( wheels[2],True ))/2 zz=zz-(EntityZ( wheels[3],True )+EntityZ( wheels[4],True ))/2 AlignToVector car,zx,zy,zz,3 ;calculate car velocities cx#=EntityX( car ):x_vel=cx-prev_x:prev_x=cx cy#=EntityY( car ):y_vel=cy-prev_y:prev_y=cy cz#=EntityZ( car ):z_vel=cz-prev_z:prev_z=cz ;resposition wheels cnt=1 For z=1.5 To -1.5 Step -3 For x=-1 To 1 Step 2; PositionEntity wheels[cnt],0,0,0; ResetEntity wheels[cnt] PositionEntity wheels[cnt],x,-1,z cnt=cnt+1 Next Next ;move car If KeyDown(203) TurnEntity car,0,3,0 If KeyDown(205) TurnEntity car,0,-3,0 If EntityCollided( car,SCENE ) If KeyDown(200) speed=speed+.02 If speed>.7 speed=.7 Else If KeyDown(208) speed=speed-.02 If speed<-.5 speed=-.5 Else speed=speed*.9 EndIf MoveEntity car,0,0,speed TranslateEntity car,0,GRAVITY,0 Else TranslateEntity car,x_vel,y_vel+GRAVITY,z_vel EndIf ;update camera If speed>=0 dx#=EntityX( target,True )-EntityX( camera ) dy#=EntityY( target,True )-EntityY( camera ) dz#=EntityZ( target,True )-EntityZ( camera ) TranslateEntity camera,dx*.1,dy*.1,dz*.1 EndIf PointEntity camera,car UpdateWorld RenderWorld Text 0,0,"space= toggle motion blur" VWait:Flip 0 WendEndFunction create_blurquad(par=0) Local al1#,al2#,s,v0,v1,v2,tr;,m al1#=1.0 al2#=0.2 m=CreateMesh() s=CreateSurface(m) v0=AddVertex(s,-1,-1,0, 0,1) v1=AddVertex(s,+1,-1,0, 1,1) v2=AddVertex(s, 0,0 ,0, .5,.5) VertexColor s,v0,255,255,255,al1# VertexColor s,v1,255,255,255,al1# VertexColor s,v2,255,255,255,al2# tr=AddTriangle(s,v0,v1,v2) v0=AddVertex(s,+1,-1,0, 1,1) v1=AddVertex(s,+1,+1,0, 1,0) v2=AddVertex(s, 0,0 ,0, .5,.5) VertexColor s,v0,255,255,255,al1# VertexColor s,v1,255,255,255,al1# VertexColor s,v2,255,255,255,al2# tr=AddTriangle(s,v0,v1,v2) v0=AddVertex(s,+1,+1,0, 1,0) v1=AddVertex(s,-1,+1,0, 0,0) v2=AddVertex(s, 0,0 ,0, .5,.5) VertexColor s,v0,255,255,255,al1# VertexColor s,v1,255,255,255,al1# VertexColor s,v2,255,255,255,al2# tr=AddTriangle(s,v0,v1,v2) v0=AddVertex(s,-1,+1,0, 0,0) v1=AddVertex(s,-1,-1,0, 0,1) v2=AddVertex(s, 0,0 ,0, .5,.5) VertexColor s,v0,255,255,255,al1# VertexColor s,v1,255,255,255,al1# VertexColor s,v2,255,255,255,al2# tr=AddTriangle(s,v0,v1,v2) FlipMesh m UpdateNormals m If par <>0 Then EntityParent m,par Return mEnd Function