Is%20this%20thing%20on? - PowerPoint PPT Presentation

About This Presentation
Title:

Is%20this%20thing%20on?

Description:

Write a 'heap' that manages the memory for objects of fixed size. ... No heap. Solution. Active and free lists. Sentinels #6: The Cows Come Home ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 30
Provided by: MarcLe
Category:
Tags: 20on | 20thing | 20this

less

Transcript and Presenter's Notes

Title: Is%20this%20thing%20on?


1
Is this thing on?
2
Ten Interview Questions for Game Programmers
  • Marc LeBlanc
  • April 2004

3
1 2D Point-in-Triangle
V1
  • Given
  • struct Point
  • float x,y
  • Write
  • bool IsPointInTriangle(Point p, Point v1,
    Point v2, Point v3)

P
V3
V2
4
1 2D Point-in-Triangle
  • Hint
  • bool IsTriangleClockwise(Point v1, Point v2,
    Point v3)

V1
V3
V2
5
1 2D Point-in-Triangle
  • Hint
  • bool IsTriangleClockwise(Point v1, Point v2,
    Point v3)
  • return (v3 v1) ? (v2 v1) gt 0

V1
V3
V2
6
2 Sphere vs. Sphere
  • Given
  • bool LineIntersectsSphere(Point3D p0,
  • Point3D p1,
  • Point3D C,
  • float r)

P1
P0
R
C
7
2 Sphere vs. Sphere
  • Write
  • bool SphereCollidesWithSphere(Point3D a0, Point3D
    a1,
  • float ar,
  • Point3D b0, Point3D b1,
  • float rb)

Ra
A0
B1
B0
A1
Rb
8
Step 1 One Moving Sphere
Ra
A0
B1
B0
Rb
9
Step 1 One Moving Sphere
Ra Rb
A0
B1
B0
10
Step 2 Two Moving Spheres
Ra
A0
B1
B0
A1
Rb
11
Step 2 Two Moving Spheres
B1
Ra
A0
B0
Rb
12
3 Shuffle a Deck
  • Given
  • int rand()
  • Write
  • void ShuffleDeckInPlace(Card deck, int nCards)
  • What are the requirements?

13
3 Shuffle a Deck
  • Given
  • int rand()
  • Write
  • void ShuffleDeckInPlace(Card deck, int nCards)
  • for (int i nCards i gt 0 i--)
  • Swap(nCardsi-1,nCardsrand()i)

14
4 Select from Stream
  • Given
  • class ElementStream
  • bool GetNextElement(Element pElementOut)
  • Write
  • Element SelectRandomElement(ElementStream
    pStream)
  • Each element is equally likely.
  • Use constant space.

15
4 Select from Stream
  • Element SelectRandomElement(ElementStream
    pStream)
  • Element winner Element()
  • Element next
  • int nSeen 0
  • while (pStream-gtGetNextElement(next))
  • nSeen
  • if (rand() nSeen 0)
  • winner next
  • return winner

16
5 Memory Pool
  • Write a heap that manages the memory for
    objects of fixed size.
  • Cope with the console environment
  • No operating system
  • No heap
  • Solution
  • Active and free lists
  • Sentinels

17
6 The Cows Come Home
  • Given a tilemap with cows, barns obstacles

18
6 The Cows Come Home
  • Cows get teleported out to pasture.
  • They come home to the nearest barn.
  • They come home a lot.
  • Sometimes barns obstacles get created or
    destroyed, but not very often.
  • Implement pathfinding for cows.

19
6 The Cows Come Home
  • Precompute a pathing database.
  • Flood-fill each tile with
  • Pointer to next tile on path, or
  • Scalar value for gradient descent

20
5 Silver Spaceship
  • Let M be a 4x4 matrix that describes the position
    and orientation of a spaceship.
  • What is the fastest way to mutate M to move the
    spaceship 10 meters forward?

21
Notational Conventions
  • In the spaceships frame of reference, z is
    forward.
  • M is the body-to-world transform.

22
Solution
  • Mrow 3 10 METER Mrow 2

23
8 Pong AI
  • How would you implement an AI to stand in place
    of a human player in a 2-player pong game?
  • Do you understand the requirements?
  • Smart is easy.
  • Fun is hard.
  • Do you know the difference?

24
9 3D Click
  • In a 3D scene

25
9 3D Click
  • What object did the user click on?

26
9 3D Click
  • Givens
  • Transforms for view and camera
  • For each object
  • Body-space dimensions
  • World-to-body transform

27
Three Strategies
  • Transform objects to screen space bounding rects,
    test against mouse.
  • Doesnt deal with occlusion well.
  • Transform mouse to ray, test ray vs. boxes.
  • Could make good use of culling database
  • Render an off-screen paint-by-numbers image and
    search.
  • Old school, hard to use hardware.

28
10 Extra Credit
  • Write Spherical Linear Interpolate for
    Quaternions.
  • Quaternion Slerp(Quaternion q1, Quaternion q2,
    float t)
  • You should know it.
  • You probably wont need to on an interview.

29
Fin
Write a Comment
User Comments (0)
About PowerShow.com