not at all :)
lets consider an object moving along a straight line with constant speed
the object is moving at 10 meters per second for the sake of our simulation we will state that 1m = 1 screen pixel so on our screens the object is moving at 10 pixels per second
so lets have a line to represent the surface our object is moving on:
now we need a graphic to represent the object. in this case I am going to use a circle with its y coord and diamter set so it looks like its on the ground.
at the moment the ball is just staying there but we want it to move from left to right at 10pixels per second
whups the ball shot off and that didnt look like 10 pixels per second. this is because we added 10 to the balls x location every program loop and the program loop is far faster than 1 time per second
so lets add some code to work out the program loop time and apply that to the ammount we move the ball by each loop.
There we go, the ball is moving at a nice sedate 10 pixels per second. lets make it do something more interesting.. lets give it some acceleration at ohhh 10m/s/s which translates to 10 pixels per second per second in our program
now we know that the new speed is the old speed + acceleration times time.
v=u+at (recognise this formula?)
crowbaring this into our program makes our code look like this:
tada, well still not _that_ interesting but its an intro to incremental algorithms using a single simple physics rule do work out the displacement (distance traveled) by an object under acceleration in program loop time based on its acceleration and initial velocity per unit time :)
everyone who has ever written a physics prog from scratch has probably started by doing something like this. dont worry if its confusing to start with because it _is_ confusing and we havent even mentioned 2d rigid body physics yet let alone 3d (hope Im not scaring you)
but anyway back to the lecture :) and on to 2d particle physics. give me a short while to extend my code and sort out how I want to explain :) basically Im going to do the old classic projectile where a ball is fired at an angle along a plain obeying newtons laws. the result will be a parabolic flight of the ball untill it hits the ground again. acceleration will be in the Y axis only and X velocity will be assumed to be constant (no friction)
lets consider an object moving along a straight line with constant speed
the object is moving at 10 meters per second for the sake of our simulation we will state that 1m = 1 screen pixel so on our screens the object is moving at 10 pixels per second
so lets have a line to represent the surface our object is moving on:
Graphics 800,600,32,2 SetBuffer BackBuffer() While Not KeyHit (1) Line 100,500,700,500 Flip cls Wend
now we need a graphic to represent the object. in this case I am going to use a circle with its y coord and diamter set so it looks like its on the ground.
Graphics 800,600,32,2 SetBuffer BackBuffer() ballx#=100 bally#=480 ballr=20 xspeed#=10 While Not KeyHit (1) Line 100,500,700,500 Oval ballx,bally,ballr,ballr Flip cls Wend
at the moment the ball is just staying there but we want it to move from left to right at 10pixels per second
Graphics 800,600,32,2 SetBuffer BackBuffer() ballx#=100 bally#=480 ballr=20 xspeed=10 While Not KeyHit (1) Line 100,500,700,500 Oval ballx,bally,ballr,ballr ballx=ballx+xspeed Flip Cls Wend
whups the ball shot off and that didnt look like 10 pixels per second. this is because we added 10 to the balls x location every program loop and the program loop is far faster than 1 time per second
so lets add some code to work out the program loop time and apply that to the ammount we move the ball by each loop.
Graphics 800,600,32,2 SetBuffer BackBuffer() ballx#=100 bally#=480 ballr=20 xspeed# = 10 time=MilliSecs() While Not KeyHit (1) ;this is our loop time calculator oldtime=time time=MilliSecs() t#=Float((time-oldtime))/1000 ;this is just to show the time on the screen Text 10,10,"Program loop time = "+t+" seconds" Line 100,500,700,500 Oval ballx,bally,ballr,ballr ;now we move the ball according to how much time has passed ballx=ballx+10*t Flip Cls Wend
There we go, the ball is moving at a nice sedate 10 pixels per second. lets make it do something more interesting.. lets give it some acceleration at ohhh 10m/s/s which translates to 10 pixels per second per second in our program
now we know that the new speed is the old speed + acceleration times time.
v=u+at (recognise this formula?)
crowbaring this into our program makes our code look like this:
Graphics 800,600,32,2 SetBuffer BackBuffer() ballx#=100 bally#=480 ballr=20 xspeed# = 10 xacceleration = 10 time=MilliSecs() While Not KeyHit (1) ;this is our loop time calculator oldtime=time time=MilliSecs() t#=Float((time-oldtime))/1000 ;this is just to show the time on the screen Text 10,10,"Program loop time = "+t+" seconds" Text 10,30,"xspeed = "+xspeed Line 100,500,700,500 Oval ballx,bally,ballr,ballr ;we are going to accelerate the ball ; v = u + a * t xspeed=xspeed + xacceleration * t ;now we move the ball according to how much time has passed ballx=ballx+xspeed*t Flip Cls Wend
tada, well still not _that_ interesting but its an intro to incremental algorithms using a single simple physics rule do work out the displacement (distance traveled) by an object under acceleration in program loop time based on its acceleration and initial velocity per unit time :)
everyone who has ever written a physics prog from scratch has probably started by doing something like this. dont worry if its confusing to start with because it _is_ confusing and we havent even mentioned 2d rigid body physics yet let alone 3d (hope Im not scaring you)
but anyway back to the lecture :) and on to 2d particle physics. give me a short while to extend my code and sort out how I want to explain :) basically Im going to do the old classic projectile where a ball is fired at an angle along a plain obeying newtons laws. the result will be a parabolic flight of the ball untill it hits the ground again. acceleration will be in the Y axis only and X velocity will be assumed to be constant (no friction)