Introduction to Camera Entities

Cameras allow you to see what's going on in the 3D world. Without at least one camera, nothing that may be happening in the world will be rendered to the screen.

Cameras also control a number of other effects, including rendering range, zoom and fog.

 Creating Cameras 

To create a camera, simply use the CreateCamera command:

   
    ;create a new camera!
    camera=CreateCamera()


 

 Camera Viewport 

A camera needs to know where on screen its view of the world is to be rendered. This area of the screen is known as the camera viewport. By default, a new camera's viewport is set to the entire screen.

To change the camera viewport use the CameraViewport command:

   
    ;Draw to top left corner of the screen
    CameraViewport camera,0,0,GraphicsWidth()/2,GraphicsHeight()/2


 

 Camera Range 

Camera range determines how far into the distance a camera can 'see'. You specify 2 values for camera range - a near value and a far value. All rendering is clipped to this range.

Its a good idea to try and keep the near value as high as possible, while keeping the far value as low as possible. This helps to minimize z-buffer problems like 'jaggies'. By default, the near value for a new camera is 1, and the far value is 1000.

To change the camera range, use the CameraRange command:

   
    ;Sets the near range to 5 and the far range to 5000
    CameraRange camera,5,5000


 

 Camera Zoom 

Changing a cameras zoom allows you to 'zoom-in' or 'zoom-out' of the action in the world. The default zoom value for a new camera is 1. Zoom values greater than 1 will cause a 'zoom-in' effect, while zoom values less than 1 will cause a 'zoom-out'. Zoom values should never be set at 0 or less!

The CameraZoom command controls camera zoom:

   
    ;Zoom-in a bit!
    CameraZoom camera,1.5


 

 Fog Effects 

Blitz3D allows you to setup fog effects independently for each camera. This can be useful for limiting what a certain camera can see. For example, a racing game might use a camera for its rearview mirror. However, you might want to limit what is visible in the rearview mirror in order to keep the game running fast.

To setup a simple fog effect for a camera, you might use something like this:

   
     ;Sets the color of fog for this camera
    CameraFogColor camera,0,128,255

    ;Sets the near/far range of fog for this camera
    CameraFogRange camera,1,1000

    ;Sets the fog mode for this camera.
    CameraFogMode camera,1


 

Often, the fog range and camera range will be the same. However, by increasing the near value of fog, you can control how 'thick' fog appears to be. Smaller fog near values will result in a thicker fog effect, since the fog will start nearer to the camera.

Unfortunately, fog is not well supported on all graphics cards. While all cards can perform some kind of fog effect, the quality varies a lot. For this reason, its a good idea to make fog optional in your Blitz3D games.

Copyright 2001 (c) Paul Gerfen - GamecodingUK