Presentation is loading. Please wait.

Presentation is loading. Please wait.

Math / Physics 101 GAM 376 Robin Burke Fall 2006.

Similar presentations


Presentation on theme: "Math / Physics 101 GAM 376 Robin Burke Fall 2006."— Presentation transcript:

1 Math / Physics 101 GAM 376 Robin Burke Fall 2006

2 Admin Lab

3 Begin math / physics 101 Vectors Coordinate spaces Kinematics

4 Vector A multi-dimensional quantity represented by a tuple of numbers We will deal mostly with 2-D vectors 3-D vectors are more mathematically complex but not fundamentally different for AI purposes

5 Vectors can represent positions is a position 1 unit north and 1 unit east of the origin can also represent velocities is a speed of 5 units in a northwesterly direction other quantities orientation, acceleration, angle, etc.

6 Vector operations Magnitude v = | v | = magnitude(v) = sqrt(x1 2 +y1 2 ) the length of the vector Adding + = Scalar multiplication * z = changes only the length Normalization v / |v| makes a vector of length 1 does not change the orientation of the vector

7 More vector operations dot product ● = x1 * x2 + y1 *y2 scalar quantity related to the angle between vectors cos (angle) = u ● v / | u | | v | Note if u and v are normalized (length = 1) then u ● v is the cosine of the angle between them

8 Example we have two agents: a, b each has a vector position and a normalized vector orientation the direction they are facing turn to face an enemy agent: P a, O a enemy: P b, O b vector from agent to enemy P ba = P b -P a normalize it compute dot product norm(P ba ) ● O a compute inverse cosine this is the angle to turn

9 Pa Pb Pb-Pa cos -1 (Oa norm(Pb-Pa))

10 Coordinate transformations We will always want to move back and forth between coordinate systems objects each have their own local coordinate systems related to each other in "world space" Example NPC a character is at a particular position, facing a particular direction he defines a coordinate system Door the door has its own coordinate system in that system, the handle is in a particular spot To make the character reach for the handle we have to make the two coordinate systems interact

11 Transformations We know where the handle is in door space where the agent's hand is in agent space what is the vector in agent space Set of transformations transform handle location L 0 to world space L w transform handle location to agent space L a Each transformation is a translation (changing the origin) and a rotation changing the orientation

12 Affine transformations Usually coordinate transformations are done through matrix multiplications we multiply a vector by a matrix and get another vector out The curious thing is that to do this we have to use vectors and matrices one size larger than our current number of dimensions you will see as the representation of 2-D vector and for 3-D

13 Example rotation around the origin by angle θ matrix multiply by current vector [1, 0] becomes ? answer x = cos(θ) – sin (θ) + 0 y = sin(θ) + cos(θ) + 0

14 x' = x cos(θ) – y sin(θ) y' = x sin(θ) + y cos(θ) (1, 2) θ = -π / 4 (2.12, 0.70)

15 Translation Achieved by adding values at the ends of the top two rows This rotates and translates by (3, -4)

16 Efficiency Mathematical operations are expensive especially trigonometric ones (inverse cosine) also square root multiplication and division, too Normalization is particularly expensive square root, squaring and division We want to consider ways to make our calculations faster especially if we are doing them a lot we can do calculations in "squared space" never have to do square roots

17 Kinematics the physics of motion we worry about this a lot in computer games moving through space, collisions, etc. our NPCs have to understand this too in order to not look stupid

18 Basic kinematics position a vector in space (point position) for a large object we use a convenient point classically the center of mass velocity the change of position over time expressed as a vector p t+1 = p t + vΔt if we define the time interval Δt to be 1 we avoid a multiplication

19 Basic kinematics II Acceleration change in velocity over time also expressed as a vector v t+1 = v t + a Δt Pair of difference equations

20 Numerical methods We want to run a simulation that shows what happens But now we have a problem there is a lag of 1 time step before acceleration impacts position not physically accurate Example deceleration to stop t = 0, d = 0, v = 10, a = 0 t = 1, d = 10, v = 10, a = -5 t = 2, d = 20, v = 5, a = -5 t = 3, d = 25, v = 0, a = 0 Correct distance traveled Δd = v 0 Δt + ½ a Δt 2 Δd = 10 d = 20

21 We can improve our simulation finer time step (very expensive) improved estimation methods for example instead of using v t, we can use the average of v t and v t+1 Example t=0, d=0, v=10, a =0 t=1, d=10, v=10, a = -5 t=2, d=17.5, v=5, a=-5 t=3, d=20, v=0, a=0 better we slow down in the first time step correct final answer but only works if acceleration is constant take GAM 350 for better ways

22 What does this have to do with AI? Imagine a NPC baseball player he has to decide when to swing that judgment has to be based on an estimate of the ball's trajectory When NPC take physical actions we have to know what the parameters of those actions should be very often physics calculations are required not as detailed as the calculations needed to run the game

23 Approximation in Prediction NPC will frequently need to predict the future where will the player be by the time my rocket gets there? Assumptions current velocity stays constant we know the speed of the rocket Correct way vector algebra lots of square roots and trig functions Typical approximation use the current distance won't change that much if the rocket is fast

24 Accuracy? Accuracy may be overrated for NPC enemies We want an enjoyable playing experience no warnings sniper attack is realistic but no fun a game has to give the player a chance Built-in inaccuracy many games have enemies deliberately miss on the first couple of shots others build random inaccuracy into all calculations

25 Force Netwon's law F = m*a In other words acceleration is a function of force and mass Force is also a vector quantity

26 Example When a bat hits a ball we will want to determine the force imparted to the ball we could simulate this with the mass of the bat and its speed more likely, we would just have a built-in value direction of the force we need to know the angle of the bat when it strikes the ball

27 More complex motions To handle rotation we also have to worry about torque and angular momentum But for the purposes of this class we will deal only with "particles" game physics is often simplified this way

28 Example rocket-jumping

29 Wednesday Finite state machines


Download ppt "Math / Physics 101 GAM 376 Robin Burke Fall 2006."

Similar presentations


Ads by Google