Blitz3D+ Command Reference

CameraViewport camera,x,y,width,height

Parameters

camera - camera handle

x - x coordinate of top left hand corner of viewport
y - y coordinate of top left hand corner of viewport
width - width of viewport
height - height of viewport

Description

Sets the camera viewport position and size.

The viewport is the rectangle of the 2D screen that the camera's view is drawn into. By default it covers the whole screen; giving each camera its own rectangle is how you build split-screen two-player views, rear-view mirrors, security monitors and picture-in-picture map views - each camera renders into its own viewport during RenderWorld.

The camera's aspect ratio follows the viewport shape automatically, so a half-width viewport does not stretch the picture (override this with CameraAspect if needed). Viewport coordinates also set the frame of reference for CameraPick and CameraProject/ProjectedX - their x,y values are relative to the camera's viewport, not the screen.

See also: CreateCamera, CameraAspect, CameraClsColor, RenderWorld.

Example

; CameraViewport Example
; ----------------------

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

; The chase camera draws to the top half of the screen
chase_cam=CreateCamera()
CameraViewport chase_cam,0,0,640,240
PositionEntity chase_cam,0,4,-14
CameraClsColor chase_cam,0,0,64

; The overhead camera looks straight down, drawing to the bottom half
top_cam=CreateCamera()
CameraViewport top_cam,0,240,640,240
PositionEntity top_cam,0,30,0
RotateEntity top_cam,90,0,0
CameraClsColor top_cam,0,32,0

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

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

; A racing car that drives round a circular track
car=CreateCube()
EntityColor car,255,50,50
angle#=0

While Not KeyDown(1)

    ; Drive the car around the track
    angle=angle+1
    PositionEntity car,Cos(angle)*8,0.5,Sin(angle)*8
    RotateEntity car,0,-angle,0

    ; Keep the chase camera watching the car
    PointEntity chase_cam,car

    ; One RenderWorld draws every camera into its own viewport
    RenderWorld

    Text 0,0,"Top: chase camera   Esc: exit"
    Text 0,20,"CameraViewport chase_cam,0,0,640,240"
    Text 0,240,"Bottom: overhead camera"
    Text 0,260,"CameraViewport top_cam,0,240,640,240"

    Flip

Wend

End

Index