1 / 29

Is this thing on?

Is this thing on?. Ten Interview Questions for Game Programmers. Marc LeBlanc April 2004. #1: 2D Point-in-Triangle. V 1. Given: struct Point { float x,y; }; Write: bool IsPointInTriangle(Point p, Point v1, Point v2, Point v3). P. V 3. V 2. #1: 2D Point-in-Triangle.

Download Presentation

Is this thing on?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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) > 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 > 0; i--) Swap(nCards[i-1],nCards[rand()%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->GetNextElement(&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. … … 0 … … … 0 M = fx fy fz 0 tx ty tz 1 Notational Conventions • In the spaceship’s frame of reference, z is forward. • M is the body-to-world transform.

  22. … … 0 … … … 0 M = fx fy fz 0 tx ty tz 1 Solution M[row 3] += 10 * METER * M[row 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. • Doesn’t 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 won’t need to on an interview.

  29. Fin

More Related