winview.py

This script demonstrates how to add multiple windows.

 

# WorldViz Copyright 2002=====================================================
#
# This script demonstrates how to create extra windows and viewports.
# Extra windows let you render "mini"-screens superimposed on top of
# the normal graphics window which can either show variations of the
# primary view (say at wide angle), or can show an entirely different
# view (say a bird's eye view of the terrain).
#
# In this example, the upper left corner shows a bird's eye view of
# the room, while the upper right corner shows a rear view of our
# current position.
#
#=====================================================================

import viz
import vizact

viz.go()

import vizinfo
info = vizinfo.add('This script demonstrates how to add multiple windows.\nThe upper right window is a rear view of the scene\nThe upper left window is a birds eye view')
info.translate(0.95,0.05)
info.alignment(vizinfo.LOWER_RIGHT)

#Add the room and arrow
room = viz.add('gallery.ive')
arrow = viz.add('arrow.wrl')
arrow.setScale([0.5,0.5,0.5])

# Create a new window in the upper left corner
UpperLeftWindow = viz.addWindow(pos=(0,1.0),size=(0.2,0.2))
UpperLeftWindow.visible(0,viz.SCREEN)

#Create a new window in the upper right corner
UpperRightWindow = viz.addWindow(pos=(0.8,1.0),size=(0.2,0.2))
UpperRightWindow.visible(0,viz.SCREEN)

# Create a new viewpoint
BirdView = viz.addView()

#Attach the bird's eye view to the upper left window
UpperLeftWindow.setView(BirdView)

#Move the view above the center of the room
BirdView.setPosition([0,9,0])

#Rotate the view so that it looks down
BirdView.setEuler([0,90,0])

#Create another viewpoint
RearView = viz.addView()

#Attach the rear view to the upper right window
UpperRightWindow.setView(RearView)

#Increase the field-of-view for the window so that the rear view has a wide angle
UpperRightWindow.fov(60,1.3)

def UpdateViews():
    #Get the current head orientation and position
    yaw,pitch,roll = viz.MainView.getEuler()
    pos = viz.MainView.getPosition()
   
    #Move the rear view to the current position
    RearView.setPosition(pos)
   
    #Rotate the rear view so that it faces behind us
    RearView.setEuler([yaw+180,0,0])
   
    #Move the arrow to our current location
    arrow.setPosition([pos[0],0,pos[2]])
    arrow.setEuler([yaw,-90,0])
   
vizact.ontimer(0,UpdateViews)

# Turn on collision detection so we can't go through walls
viz.collision(viz.ON)

# Disable collisions with the arrow
arrow.disable(viz.COLLISION)