News
Forums
Code
Logs
Gallery
Specs
Search
Car wheel track
Blitz3D Forums
/
Blitz3D Programming
/
Car wheel track
Mike0101
(Posted 2009)
[#1]
Here is a small sample of wheel track. Easy code
If you can make better, feel free.
; With a transparent background texture the paralell wheeltrack is perfect, this sample has no texture ; structure for wheeltruck Type wheeltrack Field trail_mesh%, trail_surf%, trail_vert% Field timer% Field add_cnt%, add_flag% End Type Global k.wheeltrack Graphics3D 800,600,32,0 ;plane with a simple texture grid_tex=CreateTexture( 32,32,8 ) ScaleTexture grid_tex,10,10 SetBuffer TextureBuffer( grid_tex ) Color 0,64,64:Rect 0,0,32,32 Color 0,255,255:Rect 0,0,32,32,False SetBuffer BackBuffer() grid_plane=CreatePlane() EntityTexture grid_plane,grid_tex EntityBlend grid_plane,1 EntityFX grid_plane,1 Global trail_mesh Global trail_brush, trail_surf, trial_vert ; a global brush for wheeltrack mesh trail_brush=CreateBrush() BrushAlpha trail_brush,.51 ; here you can apply a texture ; the vehicle bike=CreateCube() ScaleMesh bike,1.2,1,2 PositionEntity bike,20,1,20 ; the camera target for chase cam. target=CreatePivot( bike ) PositionEntity target,0,5,-12 create_wheeltrack(20,1,20,0,0,0) camera=CreateCamera() ; main cycle While Not KeyHit(1) If KeyHit(17) wire=Not wire WireFrame wire EndIf turn=0 If KeyDown(203) turn=3 If KeyDown(205) turn=-3 If turn TurnEntity bike,0,turn,0 EndIf MoveEntity bike,0,0,.5 update_wheeltrack(bike%) UpdateWorld ; the chasecam update 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 PointEntity camera,bike RenderWorld Flip Wend End Function update_wheeltrack(bike%) k\add_cnt=k\add_cnt+1 If k\add_cnt>=4 k\add_cnt=0 k\add_flag=True Else k\add_flag=False EndIf If k\add_flag TFormPoint 1,0,0,bike,0 AddVertex k\trail_surf,TFormedX(),0.1,TFormedZ() ,0,0 TFormPoint -1,0,0,bike,0 AddVertex k\trail_surf,TFormedX(),0.1,TFormedZ() ,0,1 AddTriangle k\trail_surf,k\trail_vert,k\trail_vert+2,k\trail_vert+3 AddTriangle k\trail_surf,k\trail_vert,k\trail_vert+3,k\trail_vert+1 AddTriangle k\trail_surf,k\trail_vert,k\trail_vert+3,k\trail_vert+2 AddTriangle k\trail_surf,k\trail_vert,k\trail_vert+1,k\trail_vert+3 k\trail_vert=k\trail_vert+2 EndIf ; clear and remake If k\timer < MilliSecs() FreeEntity k\trail_mesh Delete k create_wheeltrack(EntityX(bike,1), EntityY(bike,1),EntityZ(bike,1), EntityPitch(bike,1),EntityYaw(bike,1), EntityRoll(bike,1)) EndIf End Function Function create_wheeltrack(x#,y#,z#, rx#,ry#,rz#) k.wheeltrack=New wheeltrack k\trail_mesh=CreateMesh() PositionMesh k\trail_mesh,x,y,z RotateMesh k\trail_mesh,rx,ry,rz k\trail_surf=CreateSurface( k\trail_mesh,trail_brush ) AddVertex k\trail_surf,x+2,0.1, z , 0,0 AddVertex k\trail_surf, x, 0.1, z, 0,1 AddVertex k\trail_surf, x+2,0.1, z, 0,0 AddVertex k\trail_surf, x, 0.1, z, 0,1 AddTriangle k\trail_surf,0,2,3 AddTriangle k\trail_surf,0,3,1 AddTriangle k\trail_surf,0,3,2 AddTriangle k\trail_surf,0,1,3 k\trail_vert=2 ; this is important, each 4 seconds the wheeltrack is clear and create a new because of lower polygon number k\timer=MilliSecs() + 4000 End Function