ok,... here is some working code with all but the skid stuff stripped out,... lets see your techniques!
Good point about the flag,... I'll try it and see if it helps. Edit: Yippee! this really sped things up,... no more noticable lag when drawing the marks. Anyways, I'm still interested on seeing how some of you would handle these.
Arrow keys to drive, hold space bar to make marks. The thing I love about this method, is that I can drive for an hour making skidmarks, and they will all still be there. With a dynamic mesh, you have to start removing old ones after a while so you don't bring everything to a halt.
; skid mark test
; use arrow keys to drive, hold space bar to draw skidmarks
Graphics3D 1024,768,0,2
Global carspeed#=0
Global carspeedmax=4
Global turncar#=0
Global car=CreateCube()
Global wheel_rf=CreateCylinder(8,1,car)
PositionEntity wheel_rf,-4.9,2,-4.9
RotateEntity wheel_rf,90,90,0
ScaleEntity wheel_rf,2,1,2
EntityColor wheel_rf,64,64,64
Global wheel_lf = CopyMesh (wheel_RF,car)
PositionEntity wheel_lf,4.9,2,-4.9
RotateEntity wheel_lf,90,90,0
ScaleEntity wheel_lf,2,1,2
EntityColor wheel_lf,64,64,64
Global wheel_rr = CopyMesh (wheel_RF,car)
PositionEntity wheel_rr,-4.9,2,5.1
RotateEntity wheel_rr,90,90,0
ScaleEntity wheel_rr,2,1,2
EntityColor wheel_rr,64,64,64
Global wheel_lr = CopyMesh (wheel_RF,car)
PositionEntity wheel_lr,4.9,2,5.1
RotateEntity wheel_lr,90,90,0
ScaleEntity wheel_lr,2,1,2
EntityColor wheel_lr,64,64,64
ground=CreateCube()
ScaleEntity ground,512,.01,512
Global tracktex=CreateTexture(1024,1024,256)
SetBuffer TextureBuffer(tracktex)
Color 0,200,0
Rect 0,0,1023,1023
SetBuffer BackBuffer()
EntityTexture ground,tracktex
;Create And position camera
camera=CreateCamera()
PositionEntity camera,0,100,-300
CameraZoom camera,2
PointEntity camera,ground
light1= CreateLight(2)
PositionEntity light1,0,500,-1000
;#########################################################################################################################
;Main loop until esc key is hit
Timer=CreateTimer(60)
While Not KeyHit(1)
WaitTimer(timer) ; maintain constant FPS on faster machines (60)
playerinput()
MoveEntity car,0,0,carspeed
TurnEntity car,0,turncar,0
UpdateWorld
RenderWorld
Flip
Wend
End ;end program
;#########################################################################################################################
Function playerinput()
If KeyDown( 200 ) ; upkey
carspeed=carspeed+.1
EndIf
If KeyDown( 208 ) ;downkey
carspeed=carspeed-.1
If carspeed<0 Then carspeed=0
EndIf
If KeyDown( 203 ) ;leftkey
turncar=turncar+1
EndIf
If KeyDown( 205 ) ;rightkey
turncar=turncar-1
EndIf
If KeyDown(57)
maketracks()
EndIf
Turncar=turncar*.75
carspeed=carspeed*.98
If carspeed>carspeedmax Then carspeed=carspeedmax
End Function
Function maketracks()
SetBuffer TextureBuffer(tracktex )
LockBuffer TextureBuffer(tracktex )
WritePixelFast EntityX(wheel_rf,1)+512,512-EntityZ(wheel_rf,1),0
WritePixelFast EntityX(wheel_lf,1)+512,512-EntityZ(wheel_lf,1),0
WritePixelFast EntityX(wheel_rr,1)+512,512-EntityZ(wheel_rr,1),0
WritePixelFast EntityX(wheel_lr,1)+512,512-EntityZ(wheel_lr,1),0
UnlockBuffer TextureBuffer(tracktex )
SetBuffer BackBuffer()
End Function