Blitz3D+ Command Reference

CameraZoom camera,zoom#

Parameters

camera - camera handle

zoom# - zoom factor of camera; 1.0 (default)

Description

Sets the zoom factor for a camera - in effect, its field of view.

Zoom works like a camera lens: values above 1 magnify the view and narrow the field of view (telephoto), values below 1 widen it (wide-angle). A sniper scope might smoothly raise zoom towards 8; a speed effect in a racer might drop it towards 0.8.

The relationship to field of view is: fov = 2 * ATan( 1.0 / zoom ), so the default zoom of 1.0 gives a 90 degree field of view, zoom 2 gives about 53 degrees, and zoom 0.5 about 127 degrees. To request a specific field of view, use zoom = 1.0 / Tan( fov / 2 ).

The field of view applies to the camera's 'fit' axis - horizontal by default - with the other axis following the viewport shape; see CameraAspectMode.

Extreme wide-angle zooms distort heavily at the screen edges, and high zooms amplify every camera wobble - both facts you can use, or avoid.

See also: CameraRange, CameraAspect, CameraAspectMode, CreateCamera.

Example

; CameraZoom Example
; ------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,2,0

light=CreateLight()
RotateEntity light,45,45,0

; Textured ground plane gives a sense of distance
plane=CreatePlane()
ground_tex=LoadTexture("media/MossyGround.BMP")
ScaleTexture ground_tex,4,4
EntityTexture plane,ground_tex

; Two gate pillars close to the camera
pillar=CreateCylinder()
ScaleEntity pillar,0.5,3,0.5
PositionEntity pillar,-3,3,10
pillar=CreateCylinder()
ScaleEntity pillar,0.5,3,0.5
PositionEntity pillar,3,3,10

; A distant treasure chest on the horizon - zoom in to spot it
chest=CreateCube()
ScaleEntity chest,2,2,2
EntityColor chest,255,200,0
PositionEntity chest,0,2,200

zoom#=1

While Not KeyDown(1)

    ; Up / Down raise and lower the camera zoom factor
    If KeyDown(200) And zoom<100 Then zoom=zoom+0.1
    If KeyDown(208) And zoom>1 Then zoom=zoom-0.1

    ; Left / Right turn the camera
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    ; Apply the zoom factor to the camera
    CameraZoom camera,zoom

    TurnEntity chest,0,1,0

    RenderWorld

    Text 0,0,"Up / Down: zoom   Left / Right: turn   Esc: exit"
    Text 0,20,"A golden chest sits far ahead between the pillars - zoom in to see it"
    Text 0,40,"CameraZoom camera,"+zoom

    Flip

Wend

End

Index