; Two Windows, Two Worlds ; Requires Extended language mode. ; ; Each top-level window has its own resizable 3D canvas, camera, controls, ; and world. Close either window and the other keeps rendering. The final ; FlipCanvas in each frame is the only one that waits for vertical sync. Const EVENT_GADGET_ACTION=$401 Const EVENT_WINDOW_CLOSE=$803 windowA=CreateWindow("World A - Copper Workshop",50,70,580,520,0,15) windowB=CreateWindow("World B - Azure Observatory",650,70,580,520,0,15) SetMinWindowSize windowA,420,320 SetMinWindowSize windowB,420,320 canvasA=CreateCanvas(8,8,548,420,windowA) pauseAButton=CreateButton("Pause world A",8,438,118,30,windowA) resetAButton=CreateButton("Reset cube",134,438,118,30,windowA) statusA=CreateLabel("World A is running",260,442,290,24,windowA,2) canvasB=CreateCanvas(8,8,548,420,windowB) pauseBButton=CreateButton("Pause world B",8,438,118,30,windowB) wireBButton=CreateButton("Enable wireframe",134,438,126,30,windowB) statusB=CreateLabel("World B is running",268,442,282,24,windowB,2) Graphics3DCanvas canvasA Graphics3DCanvas canvasB worldA=CreateWorld() SetWorld worldA AmbientLight 62,34,20 cameraA=CreateCamera() CameraClsColor cameraA,48,18,10 PositionEntity cameraA,0,2,-8 lightA=CreateLight() RotateEntity lightA,35,-35,0 cubeA=CreateCube() EntityColor cubeA,235,120,48 ScaleEntity cubeA,1.25,1.25,1.25 floorA=CreatePlane(6) EntityColor floorA,92,48,28 PositionEntity floorA,0,-1.4,0 orbitA=CreatePivot() satelliteA=CreateSphere(16,orbitA) ScaleEntity satelliteA,.3,.3,.3 PositionEntity satelliteA,2.2,.4,0 EntityColor satelliteA,255,220,120 SetCanvasCamera canvasA,cameraA worldB=CreateWorld() SetWorld worldB AmbientLight 18,42,78 cameraB=CreateCamera() CameraClsColor cameraB,6,20,52 PositionEntity cameraB,0,1.5,-8 lightB=CreateLight() RotateEntity lightB,30,30,0 sphereB=CreateSphere(32) EntityColor sphereB,55,145,255 ScaleEntity sphereB,1.3,1.3,1.3 floorB=CreatePlane(6) EntityColor floorB,22,52,90 PositionEntity floorB,0,-1.6,0 orbitB=CreatePivot() satelliteB=CreateCube(orbitB) ScaleEntity satelliteB,.32,.32,.32 PositionEntity satelliteB,-2.4,.6,0 EntityColor satelliteB,120,235,255 SetCanvasCamera canvasB,cameraB windowAOpen=True windowBOpen=True pausedA=False pausedB=False wireframeB=False lastAWidth=0:lastAHeight=0 lastBWidth=0:lastBHeight=0 While windowAOpen Or windowBOpen eventID=WaitEvent(1) While eventID<>0 eventGadget=EventSource() If eventID=EVENT_WINDOW_CLOSE If eventGadget=windowA And windowAOpen FreeGadget windowA windowA=0:canvasA=0:windowAOpen=False EndIf If eventGadget=windowB And windowBOpen FreeGadget windowB windowB=0:canvasB=0:windowBOpen=False EndIf EndIf If eventID=EVENT_GADGET_ACTION If windowAOpen If eventGadget=pauseAButton pausedA=Not pausedA If pausedA SetGadgetText pauseAButton,"Resume world A" SetGadgetText statusA,"World A is paused" Else SetGadgetText pauseAButton,"Pause world A" SetGadgetText statusA,"World A is running" EndIf EndIf If eventGadget=resetAButton RotateEntity cubeA,0,0,0 RotateEntity orbitA,0,0,0 SetGadgetText statusA,"World A objects reset" EndIf EndIf If windowBOpen If eventGadget=pauseBButton pausedB=Not pausedB If pausedB SetGadgetText pauseBButton,"Resume world B" SetGadgetText statusB,"World B is paused" Else SetGadgetText pauseBButton,"Pause world B" SetGadgetText statusB,"World B is running" EndIf EndIf If eventGadget=wireBButton wireframeB=Not wireframeB SetWorld worldB WireFrame wireframeB If wireframeB SetGadgetText wireBButton,"Disable wireframe" SetGadgetText statusB,"Wireframe affects only world B" Else SetGadgetText wireBButton,"Enable wireframe" SetGadgetText statusB,"World B is solid" EndIf EndIf EndIf EndIf eventID=PeekEvent() Wend If KeyHit(1) Then Exit If windowAOpen clientAWidth=ClientWidth(windowA):clientAHeight=ClientHeight(windowA) If clientAWidth<>lastAWidth Or clientAHeight<>lastAHeight SetGadgetShape canvasA,8,8,clientAWidth-16,clientAHeight-54 SetGadgetShape pauseAButton,8,clientAHeight-38,118,30 SetGadgetShape resetAButton,134,clientAHeight-38,118,30 SetGadgetShape statusA,260,clientAHeight-34,clientAWidth-268,24 lastAWidth=clientAWidth:lastAHeight=clientAHeight EndIf SetWorld worldA If Not pausedA TurnEntity cubeA,.18,.42,.07 TurnEntity orbitA,0,.65,0 EndIf UpdateWorld RenderWorldToCanvas canvasA,worldA EndIf If windowBOpen clientBWidth=ClientWidth(windowB):clientBHeight=ClientHeight(windowB) If clientBWidth<>lastBWidth Or clientBHeight<>lastBHeight SetGadgetShape canvasB,8,8,clientBWidth-16,clientBHeight-54 SetGadgetShape pauseBButton,8,clientBHeight-38,118,30 SetGadgetShape wireBButton,134,clientBHeight-38,126,30 SetGadgetShape statusB,268,clientBHeight-34,clientBWidth-276,24 lastBWidth=clientBWidth:lastBHeight=clientBHeight EndIf SetWorld worldB If Not pausedB TurnEntity sphereB,.12,-.32,.05 TurnEntity orbitB,0,-.5,0 EndIf UpdateWorld RenderWorldToCanvas canvasB,worldB EndIf If windowAOpen If windowBOpen Then FlipCanvas canvasA,False Else FlipCanvas canvasA,True EndIf If windowBOpen Then FlipCanvas canvasB,True Wend FreeWorld worldA FreeWorld worldB EndGraphics If windowA<>0 Then FreeGadget windowA If windowB<>0 Then FreeGadget windowB End