Physics + Vectors References: xyz
Variable frame rates (review) Two options for handling it: – Option1: Cap frame rates When moving / rotating express in units / updated Good: Easy to understand Bad: Slow machines can't reach the frame-rate – Option2: Let computer run as fast as possible When moving / rotating express in units / second – The multiply by the time since the last frame Good: Runs on any speed machine Bad: A little harder to understand
Velocity and Acceleration Suppose you are moving at 50mph for 3 hours. How far are you from your original position? – A: 150 miles 50 * 3 Express this as a graph – We're really calculating the area of this rectangle. Speed (mph) Time (hours) 50 3
Velocity and Acceleration, cont. What about (abruptly) changing velocity? Speed (mph) Time (hours) 50 3 Q: How far have we travelled after these 5 hours? Q (rephrased): In other words, what is the area of the pink area? A: 0.5*(50x1) + (50x3) + 0.5*(50x1) = 200 miles
Velocity and Acceleration, cont. we can approximate the area of this curve using (small) discreet time intervals Speed (mph) Time (hours) 50 3 A dT value for one iteration of the game loop. import pygame # … clock = pygame.time.Clock() #... (inside the game loop) dT = clock.tick() /
Velocity and Acceleration, cont.
Velocity and Acceleration change in position due to velocity
Velocity and Acceleration, cont. Velocity results in a change in position Acceleration results in a change in velocity Speed (mph) Time (hours) 50 3 Position-offset (miles) Time (hours) Accel (m/h 2 ) 3 50
Acceleration and Vectors, cont.
Gravity Gravity produces an accelaration on objects Assuming we're on the earth, it points downwards
Newton's Laws of Motion
Simple collisions Not physically accurate When we've looked at dot product, we'll re- explore this and do proper – elastic collisions – inelastic collisions For now: – When two objects collide, impart a force Equal magnitude, opposite direction on each body Of a fixed magnitude
A new vector operator
Boundary collisions
Gravity as a Force Gravity is a force – Proportional to the mass – But…when we apply the force We divide by the mass (Newton's 2 nd ) So…the acceleration is the same regardless of mass – Unless there is air resistance (drag)
"Planetary" Gravity
Examples / Labs #1: – Two bodies, exerting "planetary" gravity on the other. – Try to set up a semi-stable orbit. #2: – Create a bunch of circles, subject to gravity and bouncing off walls Bouncing off each other – Click to lay a bomb. #3: – Asteroids! – Bouncing asteroids – Realistic accelaration