Presentation is loading. Please wait.

Presentation is loading. Please wait.

Maths Fundamentals Games Fundamentals © by Jarek Francik Kingston University, London 2008-2013.

Similar presentations


Presentation on theme: "Maths Fundamentals Games Fundamentals © by Jarek Francik Kingston University, London 2008-2013."— Presentation transcript:

1 Maths Fundamentals Games Fundamentals © by Jarek Francik Kingston University, London 2008-2013

2 Trigonometry

3  a b c

4 Detection of Collisions

5 w (X, Y) (p.x, p.y) Condition for collision abs(p.x – X) < w/2 && abs(p.y – Y) < h/2 public boolean hitTest(Point pt); h

6 w (X, Y) Condition for collision abs(p.x – X) < w/2 + R && abs(p.y – Y) < h/2 + R public boolean hitTest(Point pt); h (p.x, p.y) R R R Detection of Collisions small artifact...

7 w (X, Y) Condition for collision abs(r.X – X) < (w + r.w)/2 && abs(r.Y – Y) < (h + r.h)/2 public boolean hitTest(Rectangle rect); h Detection of Collisions r.w (r.X, r.Y)r.h

8 Condition for collision (not complete) abs(s.X – X) < (w + w’)/2 && abs(s.Y – Y) < (h + h’)/2 w (X, Y)h Detection of Collisions s.w (s.X, s.Y) s.h w’ h’

9 s.w (s.X, s.Y) s.h w’ h’   w1w1 h1h1 w2w2 h2h2 Hidden Slide: how to find x’ and h’

10 w (X, Y)h Detection of Collisions s.w (s.X, s.Y) s.h

11 Detection of Collisions w (X, Y)h s.w (s.X, s.Y) s.h

12 Detection of Collisions w (X, Y)h s.w (s.X, s.Y) s.h Condition for collision (not complete) abs(s.X – X) < (s.w + w’’)/2 && abs(s.Y – Y) < (s.h + h’’)/2 w’’ h’’

13 Detection of Collisions w (X, Y) h s.w (s.X, s.Y) s.h general case is like this...

14 Detection of Collisions In general case: 1.rotate around centre of R1 so that edges of R1 are parallel to the axes 2.abs(X 1 – X 2 ) < (w 1 + w’ 2 )/2 && abs(Y 1 – Y 2 ) < (h 1 + h’ 2 )/2 3.rotate around centre of R2 so that edges of R2 are parallel to the axes 4.abs(X 1 – X 2 ) < (w’ 1 + w 2 )/2 && abs(Y 1 – Y 2 ) < (h’ 1 + h 2 )/2 5.if both conditions are true we have a collision public boolean hitTest(Sprite sprite);

15 Thales’ Theorem and Perspective in 3D

16 A DB E C Thales Theorem

17 Perspective in 3D

18 f z x’ x Notice also that:

19 Z f Y z y’ y screen image  Perspective in 3D

20 Linear Function & Linear Equation

21 y = ax + b Ax + By + C = 0 x = x 0 + at y = y 0 + at

22 Linear Function & Linear Equation y = ax + b Ax + By + C = 0 x = x 0 + at y = y 0 + at  b a=tg  cannot represent a vertical line

23 Linear Function & Linear Equation y = ax + b Ax + By + C = 0 x = x 0 + at y = y 0 + at

24 Linear Function & Linear Equation y = ax + b Ax + By + C = 0 x = x 0 + at y = y 0 + bt  (x 0, y 0 ) a b

25 Linear Motion x = x 0 + at y = y 0 + bt direction may be determined by either: pair tangent angle if t is time, a and b determine velocity a b (x,y) (x+a,y+b) Sprite *p = new CSpriteXxx(...); p->SetDirection(angle); p->SetDirection(a, b); p->SetSpeed(v); p->SetVelocity(a, b);

26 xx yy (x 5,y 5 ) xx yy (x 3,y 3 ) can be applied iteratively: x n = x n-1 +  x y n = y n-1 +  y (x 0,y 0 ) xx yy (x 1,y 1 ) xx yy (x 2,y 2 ) xx yy (x 4,y 4 ) Linear Motion

27 vxvx vyvy (x 5,y 5 ) vxvx vyvy (x 3,y 3 ) Deltas are the Velocity: x n = x n-1 + v x y n = y n-1 + v y (x, y) position (v x, v y ) velocity vector speed (scalar) (x 0,y 0 ) vxvx vyvy (x 1,y 1 ) vxvx vyvy (x 2,y 2 ) vxvx vyvy (x 4,y 4 ) p->GetXVelocity(); p->GetYVelocity(); p->GetSpeed(); p->SetVelocity (a, b); p->SetSpeed(v); Linear Motion

28 v x3 v y3 (x 3,y 3 ) increase velocity in each step: v xn = v xn-1 + a x v yn = v yn-1 + a y x n = x n-1 + v x y n = y n-1 + v y (ax, ay) acceleration vector acceleration (vector) (x 0,y 0 ) v x1 v y1 (x 1,y 1 ) v x2 v y2 (x 2,y 2 ) x = p->GetXVelocity(); y = p->GetYVelocity(); x += ax; y += ay; p->SetVelocity(x, y) // another method v = p->GetSpeed(); v += a; p->SetSpeed(v); Accelerated Motion

29 Vectors and Vector Algebra

30 Vector Geometrical object that: –has magnitude (length) –has direction –can be added to other vectors In 2D plane: In 3D space: In n-dimensional space

31 Vector In Physics: Vectors: –velocity –acceleration –force –momentum Scalars: –speed –mass –power –energy

32 Normal Vector Vector perpendicular to a surface In CG widely used to model the shapes, e.g.: –lighting & 3D rendering –calculating the collisions

33 Adding Vectors B A A + B

34 Multiplication of 2D Vectors Multiplication of a Vector by a Number A 2A 3A

35 Multiplication of 2D Vectors Multiplication of a Vector by a Number Cross Product of Vectors cross product A  B is a vector perpendicular to both A and B (in 3D space) ABAB A B  B  A = - A  B Interactive demo: http://physics.syr.edu/courses/java-suite/crosspro.html http://physics.syr.edu/courses/java-suite/crosspro.html

36 Multiplication of 2D Vectors Multiplication of a Vector by a Number Cross Product of Vectors Dot Product of Vectors B A  Interactive demo: http://www.falstad.com/dotproduct/ http://www.falstad.com/dotproduct/

37 Multiplication of 2D Vectors Quick calculation: Dot Product: Cross Product: N is the Normal Vector to A and B

38 Multiplication of 2D Vectors ABABABAB number (scalar)vector |A||B|cos  |A||B|sin  N  = 0  max0   = 90  0max quick formula:x a x b + y a y b x a y b - y a x b

39 Multiplication of 3D Vectors Multiplication of a Vector by a Number Dot Product of Vectors Cross Product of Vectors

40 Example Am I approaching him or not? yes, if: VD > 0 VD = V X X + V Y Y D = X, Y = X E – X R, Y E – Y R V = V X, V Y double x = enemy.GetX() – rocket.GetX(); double y = enemy.GetY() – rocket.GetY(); double vx = rocket.GetXVelocity(); double vy = rocket.GetYVelocity(); if (vx * x + vy * y > 0)

41 Example Is it on my left or my right? right, if: VxD > 0 VxD = V X Y - V Y X D = X, Y = X E – X R, Y E – Y R V = V X, V Y double x = enemy.GetX() – rocket.GetX(); double y = enemy.GetY() – rocket.GetY(); double vx = rocket.GetXVelocity(); double vy = rocket.GetYVelocity(); if (vx * y - vy * x > 0)


Download ppt "Maths Fundamentals Games Fundamentals © by Jarek Francik Kingston University, London 2008-2013."

Similar presentations


Ads by Google