| canvas - a GUI canvas attached to 3D with Graphics3DCanvas |
|
Returns the camera bound to a 3D GUI canvas, or 0. This is part of the GUI canvas system. It reports what SetCanvasCamera last bound: the camera that RenderWorldToCanvas will draw into this canvas, or 0 when the canvas uses the world's normal all-camera rendering order. A multi-view editor uses it to toggle bindings ("if the front camera is bound, swap to the top camera") and to label each view without keeping its own bookkeeping. Expect 0 more often than you might think: a binding is cleared automatically whenever its camera, world, canvas, parent window, or the graphics service is freed, so a stored "which camera did I bind?" variable can go stale while CanvasCamera never does. Asking about a canvas that is not 3D-attached with Graphics3DCanvas is a runtime error. Like the rest of the canvas system, this belongs in a GUI event-loop program: WaitEvent to stay responsive, RenderWorldToCanvas to draw, FlipCanvas to present. Requires Extended mode. See also: SetCanvasCamera, RenderWorldToCanvas, Graphics3DCanvas, CanvasBuffer, FlipCanvas. |
; CanvasCamera Example
; --------------------
; Requires Extended mode.
Const EVENT_WINDOW_CLOSE=$803
; Build a GUI window with a 3D canvas and a status label
window=CreateWindow("CanvasCamera",100,100,640,480,0,15)
canvas=CreateCanvas(8,8,608,396,window)
label=CreateLabel("",8,412,608,36,window)
Graphics3DCanvas canvas
world=GetWorld()
; Two cameras give two different views of the same scene
front_camera=CreateCamera()
PositionEntity front_camera,0,1,-5
top_camera=CreateCamera()
CameraProjMode top_camera,2
PositionEntity top_camera,0,8,0
RotateEntity top_camera,90,0,0
light=CreateLight()
RotateEntity light,45,45,0
cube=CreateCube()
PositionEntity cube,0,1,0
EntityColor cube,80,165,240
; Bind the front camera to the canvas to start with
SetCanvasCamera canvas,front_camera
last_bound=0
running=True
While running
; Pump GUI events so the window stays responsive
event=WaitEvent(1)
While event<>0
If event=EVENT_WINDOW_CLOSE And EventSource()=window Then running=False
event=PeekEvent()
Wend
If KeyHit(1) Then running=False
; Space binds whichever camera is not bound right now
If KeyHit(57)
If CanvasCamera(canvas)=front_camera Then SetCanvasCamera canvas,top_camera Else SetCanvasCamera canvas,front_camera
EndIf
; CanvasCamera reports the camera currently bound to the canvas
bound=CanvasCamera(canvas)
If bound<>last_bound
If bound=front_camera Then view$="the front camera" Else view$="the top camera"
SetGadgetText label,"CanvasCamera(canvas) = "+bound+" - "+view+" Space: swap Esc: exit"
last_bound=bound
EndIf
TurnEntity cube,0,1,0
RenderWorldToCanvas canvas,world
FlipCanvas canvas,True
Wend
EndGraphics
FreeGadget window
End