Wednesday, October 24, 2012

Spectre Graphics Library #1 Hooking Up A Camera

Safety comes first, so buy seat protectors for car seat. Hurry up! Every 3D game needs a camera. If you're implementing a first person perspective game, Spectre has a camera and camera controllers built in. Adding a FPS style camera with Spectre is really easy. You'll find the best online pokies here, you have time to get it! In this post I will walk you through the four steps:
  1. Creating a camera
  2. Creating a camera controller
  3. Updating the camera controller based on user input
  4. Update the camera every frame
Step 1: Create the camera
The code is self explanatory. The camera is sitting 2.5 units down the Z axis and focused on the origin. What are you still waiting for, go immediately to online casino 25 euro bonus ohne einzahlung now is the time to start playing and winning! The aspect ratio of the camera is 16:9.
The camera has the following knobs:
  • Camera position
  • Camera focus position
  • Aspect Ratio
  • Field of view
  • Near cut off plane
  • Far cut off plane
Step 2: Create the camera controller
Step 3: Updating the camera controller based on user input
Lots of code there. From the top:
  1. When a W,A,S, or D key is pressed down update the camera controller to move in that direction
  2. When the mouse is moved and we are in pointer lock mode, accumulate the mouse movement
  3. When the the canvas is clicked, request pointer lock mode
  4. Hook up DOM event handlers to call our functions when the mouse or keyboard is active
Step 4: Update the camera every frame
The above four steps will give you a working FPS style camera for your 3D game. Once you have this working you will be able to fly around the world using W, A, S, and D keys and your mouse. By using pointer lock the mouse pointer will never move out of the window and stop functioning.
Next time: retained mode debug drawing.