CS 1666 www.cs.pitt.edu/~nlf4/cs1666/ Collision detection - - PowerPoint PPT Presentation

cs 1666
SMART_READER_LITE
LIVE PREVIEW

CS 1666 www.cs.pitt.edu/~nlf4/cs1666/ Collision detection - - PowerPoint PPT Presentation

CS 1666 www.cs.pitt.edu/~nlf4/cs1666/ Collision detection Collision detection We already had to implement some basic collision detection in the motion example I.e., to keep our square from moving out of the window Checking for


slide-1
SLIDE 1

CS 1666

www.cs.pitt.edu/~nlf4/cs1666/

Collision detection

slide-2
SLIDE 2
  • We already had to implement some basic collision detection

in the motion example

○ I.e., to keep our square from moving out of the window ○ Checking for collisions with the boundary of the window

  • Generally, games will have many objects moving around the

screen, how can we check whether they've hit one another?

Collision detection

2

slide-3
SLIDE 3

No Collision

3

slide-4
SLIDE 4

No Collision

4

slide-5
SLIDE 5

No Collision

5

slide-6
SLIDE 6

COLLISION!

6

slide-7
SLIDE 7

Colliding circles

7

slide-8
SLIDE 8

Complex collisions

8

slide-9
SLIDE 9

Complex collisions in action

9

slide-10
SLIDE 10

Even more complex collisions

10

slide-11
SLIDE 11

Really complex collisions

11

slide-12
SLIDE 12

Street Fighter II Hitboxes

12

slide-13
SLIDE 13

The same idea is used in 3D games

13

slide-14
SLIDE 14
  • And some help from SDL

○ SDL_bool SDL_HasIntersection(const SDL_Rect* A, const SDL_Rect* B) ■ True if the two SDL_Rect's intersect ■ False otherwise ○ SDL_bool SDL_IntersectRect(const SDL_Rect* A, constSDL_Rect* B, SDL_Rect* result) ■ Same returns, but will also set result to the intersection

  • f A and B if one exists

■ result will be NULL if there is no intersection

Back to 2D

14