2. Outline
• Introduction to OpenGL
• Introduction to physics engines
• Connecting the two
• A bit more about physics engines
• Tips on writing games
3.
4.
5.
6.
7.
8.
9. What is OpenGL?
• Low-level 2D and 3D graphics library
• Usually hardware accelerated
• Can only draw points, lines, triangles
• But triangles can be textured
• GPUs can evaluate a short program for each vertex or
fragment in a high-level language
32. Linking physical objects with OpenGL
• Draw sprites
• Create physical models corresponding to sprites
• Instantiate objects into physics simulation
Each frame:
• Step time
• Read position + angle of body
• Draw OpenGL quads/sprites at position + angle
36. Collision Callbacks
What happens in game when shapes collide?
Register a callback to take action
• Destroy/change the object
• Create a joint
• Play a sound
38. Joints
• pin joint – bodies attached at a point, can rotate
• prismatic joint – keep bodies aligned, like a piston or
a train on a rail
• distance joint – keep points on the two bodies at the
same distance from one another, like a tow-bar or
crank shaft
• pulley joint – the position of a body along one axis is
linked to the position of another body along another
axis
45. Graphics and Sound
• Cute and colourful is attractive
• Simple shapes and outlines are much easier than
other styles
• Free/CC game art resources available
46.
47. The art of tuning a physics engine
• Tuning magic numbers:
• Forces
• Torques
• Density/Friction/Restitution
• Re-shaping bodies/redrawing sprites
• At which point does a force act?
• Joints/joint limits/joint motors
• Collision groups/filters
48. “To every action there is
always an equal and
opposite reaction: or the
forces of two bodies on each
other are always equal and
are directed in opposite
directions.”
- Archimedes
52. Physics Games
• Intuitive for players
• The game is mastering the physics
• Constrain degrees of freedom to balance
difficulty/reward/punishment
53. Physics Puzzles
Overlapping constraints
• Physical constraints
• Thing in the way
• Thing not in the right place
• How to overcome gravity
• Wrong physical behaviour unless...
• Non-physical constraints
• Player can't breathe underwater
• Only x can pass through this barrier
54. Reasons to use a physics engine
• Tons of maths for free
• Cool effects/cheap animations
• Game world responds to player; player is
empowered/immersed
• Extra layer of complexity/interest for the player
• Intuitive puzzles