def attachViewToGlasses(self, visNode): """ Create tracker object that represents the users head position, specifically the center of the eyes. The position provided by the head tracker must be in the same reference frame as the cave wall coordinates. This will normally be a tracking sensor, but for this example we will simulate a head tracker using the keyboard (WASD keys). """ self.head_tracker = viz.link(visNode, viz.NullLinkable, srcFlag=viz.ABS_PARENT) """ Create CaveView object for manipulating the virtual viewpoint. cave_origin is a node that controls the position of the cave within the virtual world. For example, if you wanted to simulate the cave user flying through an environment, you would apply the transformation to the cave_origin node. """ cave_origin = vizcave.CaveView(self.head_tracker) """ The cave_origin node is a standard Vizard node that you can apply any position/rotation to. In this example we will create a keyboard/mouse tracker (using arrow keys) and link it to the cave_origin node, allowing us to fly the cave user through the virtual environment. """ origin_tracker = viztracker.KeyboardMouse6DOF() origin_link = viz.link(origin_tracker, cave_origin) origin_link.setMask(viz.LINK_POS) #head_tracker.setMask(viz.LINK_POS) """ Pass the head tracker to the cave object so it can automatically update the view frustums every frame based on the current head position relative to each wall. """ self.cave.setTracker(self.head_tracker)
def __init__(self): viz.EventClass.__init__(self) self.EH = 1.2 Proj_Dist = 1.0 #front projection distance to Eye Proj_V_F = 1.115 #vertical extent of projection (m) Proj_H_F = 1.985 #1.96#horizontal extent of projection (m) Proj_HfG = .665 #Front projection height from ground. FB = Proj_HfG #FrontBottom FT = Proj_HfG + Proj_V_F #FrontTop FL = -Proj_H_F / 2 #Front Left FR = Proj_H_F / 2 #Front Right FC0 = FL, FB, Proj_Dist # Front Wall: FC0,FC1,FC2,FC3 FC1 = FR, FB, Proj_Dist FC2 = FL, FT, Proj_Dist FC3 = FR, FT, Proj_Dist self.FrontWall = vizcave.Wall(upperLeft=FC2, upperRight=FC3, lowerLeft=FC0, lowerRight=FC1, name='Front Wall') #Create front wall viz.setMultiSample(8) #set anti-aliasing #Initialize graphics window viz.go() # viz.eyeheight(1.2) #for monitor in viz.window.getMonitorList(): # print monitor.name # print ' ',monitor viz.window.setFullscreenMonitor(2) viz.window.setFullscreen(viz.ON) self.cave = vizcave.Cave(stereo=0) self.cave.addWall(self.FrontWall) #,window=self.frontWindow) # print ("1_N: ", self.cave.getNearPlane()) #default is [.1, -1.] # print ("1_F: ", self.cave.getFarPlane()) #set near and far plane. self.cave.setNearPlane(1.0) self.cave.setFarPlane(100.0) view = viz.MainView self.track = viztracker.Keyboard6DOF() #tracker object self.track.setPosition(0, self.EH, 0) viz.link(self.track, view) #linked to mainview self.cave.setTracker(pos=self.track) ##Create CaveView object for manipulating the entire cave environment ##The caveorigin is a node that can be adjusted to move the entire cave around the virtual environment, it needs a tracker object to initialise it. self.caveview = vizcave.CaveView(self.track)
def initDisplays(initFlag=vizconnect.INIT_INDEPENDENT, initList=None): #VC: place any general initialization code here rawDisplay = vizconnect.getRawDisplayDict() #VC: initialize a new display CAVE_CONFIG_NAME = 'cave_manual_configuration' if vizconnect.isPendingInit('display', CAVE_CONFIG_NAME, initFlag, initList): #VC: init which needs to happen before viz.go if initFlag & vizconnect.INIT_PREVIZGO: viz.setOption('viz.stereo', viz.QUAD_BUFFER) #VC: init the raw object if initFlag & vizconnect.INIT_RAW: #VC: set the window for the display _window = viz.MainWindow #APG: constants, 5 total instances running... FRONT_WALL_CLUSTER_CLIENT = viz.CLIENT1 LEFT_WALL_CLUSTER_CLIENT = viz.CLIENT2 RIGHT_WALL_CLUSTER_CLIENT = viz.CLIENT3 FLOOR_LEFT_CLUSTER_CLIENT = viz.CLIENT4 FLOOR_RIGHT_CLUSTER_CLIENT = viz.CLIENT5 #These are determined by testing the monitors FRONT_WALL_MONITOR_ID = 1 LEFT_WALL_MONITOR_ID = 4 RIGHT_WALL_MONITOR_ID = 5 FLOOR_LEFT_MONITOR_ID = 3 FLOOR_RIGHT_MONITOR_ID = 2 #============================================== #Cave calculations #VC: create the raw object # Create a cave object import vizcave cave = vizcave.Cave(stereo=viz.QUAD_BUFFER) # get an origin node originName = CAVE_CONFIG_NAME initGroups(vizconnect.INIT_INDEPENDENT, [originName]) # ensure it's been created originNode = vizconnect.getGroup(originName).getNode3d() frontImageWidth = 5.5372 imageHeight = 2.2225 imageRise = 0.0 originLeft = 3.5503 originRight = 3.5503 sideImageWidth = 2.9591 shiftRight = 0 shiftUp = 0 shiftForward = 0 # get the originLeft angle from the origin measurements import math aOR = math.pi / 4.0 aAOR = (originRight**2 - originLeft**2 - frontImageWidth**2) / (-2 * originLeft * frontImageWidth) if abs(aAOR) <= 1: aOR = math.acos(aAOR) # convert the angle to front and right shifts Sr = -(math.cos(aOR) * originLeft - frontImageWidth / 2.0) Sf = (math.sin(aOR) * originLeft - sideImageWidth / 2.0) # find left/right, up/down, front/back (x,y,z) extent of caves R = frontImageWidth / 2.0 + Sr + shiftRight # right L = -frontImageWidth / 2.0 + Sr + shiftRight # left U = imageRise + imageHeight + shiftUp # up/top D = imageRise + shiftUp # bottom/down F = sideImageWidth / 2.0 + Sf + shiftForward # front B = -sideImageWidth / 2.0 + Sf + shiftForward # back # find corners # e.g. # Front Wall: C1,C2,C5,C6 # Left Wall: C0,C1,C4,C5 # Right Wall: C2,C3,C6,C7 C0 = L, U, B C1 = L, U, F C2 = R, U, F C3 = R, U, B C4 = L, D, B C5 = L, D, F C6 = R, D, F C7 = R, D, B C8 = L, D, 0 C9 = R, D, 0 C10 = -0.19939, D, F C11 = 0.19939, D, F C12 = -0.19939, D, 0 C13 = 0.19939, D, 0 # wall_list = [C0, C1, C2, C3, C4, # C5, C6, C7, C8, # C9, C10, C11, C12, C13] # # for item in wall_list: # print(item) #============================================== WALL_CORNERS = "corners" WALL_NAME = "name" WALL_CLUSTER_ID = "cluster_id" WALL_MONITOR_ID = "monitor_id" #Creates wall, then adds it to the vizcave obj def config_wall(wall_config, window): points = wall_config[WALL_CORNERS] cluster_client_id = wall_config[WALL_CLUSTER_ID] monitor_id = wall_config[WALL_MONITOR_ID] new_wall = vizcave.Wall(upperLeft=points[0], upperRight=points[1], lowerLeft=points[2], lowerRight=points[3], name=wall_config[WALL_NAME]) cave.addWall(new_wall, mask=cluster_client_id, window=window) with viz.cluster.MaskedContext(cluster_client_id): viz.window.setFullscreenMonitor(monitor_id) _window.setStereoSwap(False) viz.window.setFullscreen(True) #Create front wall #================================== wall_config = {} wall_config[WALL_CORNERS] = [C1, C2, C5, C6] wall_config[WALL_NAME] = "Front Wall" wall_config[WALL_CLUSTER_ID] = FRONT_WALL_CLUSTER_CLIENT wall_config[WALL_MONITOR_ID] = FRONT_WALL_MONITOR_ID config_wall(wall_config, _window) #Create right wall #================================== wall_config = {} wall_config[WALL_CORNERS] = [C2, C3, C6, C7] wall_config[WALL_NAME] = "Right Wall" wall_config[WALL_CLUSTER_ID] = RIGHT_WALL_CLUSTER_CLIENT wall_config[WALL_MONITOR_ID] = RIGHT_WALL_MONITOR_ID config_wall(wall_config, _window) # #Create left wall # #================================= wall_config = {} wall_config[WALL_CORNERS] = [C0, C1, C4, C5] wall_config[WALL_NAME] = "Left Wall" wall_config[WALL_CLUSTER_ID] = LEFT_WALL_CLUSTER_CLIENT wall_config[WALL_MONITOR_ID] = LEFT_WALL_MONITOR_ID config_wall(wall_config, _window) #Create floor_left #================================== wall_config = {} wall_config[WALL_CORNERS] = [C5, C11, C8, C13] wall_config[WALL_NAME] = "Floor Left" wall_config[WALL_CLUSTER_ID] = FLOOR_LEFT_CLUSTER_CLIENT wall_config[WALL_MONITOR_ID] = FLOOR_LEFT_MONITOR_ID config_wall(wall_config, _window) #Create floor_right #================================== wall_config = {} wall_config[WALL_CORNERS] = [C10, C6, C12, C9] wall_config[WALL_NAME] = "Floor Right" wall_config[WALL_CLUSTER_ID] = FLOOR_RIGHT_CLUSTER_CLIENT wall_config[WALL_MONITOR_ID] = FLOOR_RIGHT_MONITOR_ID config_wall(wall_config, _window) #================================== # We need to pass an object which will be used to update the projection # or the display to the view's position, typically this would be the # node attached to an avatar's head tracker. viewpoint = viz.addGroup() cave.setTracker(viewpoint) # Create a CaveView object for manipulating the entire cave environment. # The caveView is a node that can be adjusted to move the entire # cave around the virtual environment. caveView = vizcave.CaveView(viewpoint) _window.originLink = viz.link(originNode, caveView, dstFlag=viz.ABS_GLOBAL, srcFlag=viz.ABS_GLOBAL) _window.caveView = caveView _window.originNode = originNode _window.displayNode = cave _window.viewpointNode = viewpoint rawDisplay[CAVE_CONFIG_NAME] = _window #VC: init the wrapper (DO NOT EDIT) if initFlag & vizconnect.INIT_WRAPPERS: vizconnect.addDisplay(rawDisplay[CAVE_CONFIG_NAME], CAVE_CONFIG_NAME, make='Generic', model='Cave Manual Configuration') #VC: set the parent of the node if initFlag & vizconnect.INIT_PARENTS: vizconnect.getDisplay(CAVE_CONFIG_NAME).setParent( vizconnect.getAvatar('head_and_hand').getAttachmentPoint( 'head')) #VC: set the name of the default vizconnect.setDefault('display', 'cave_manual_configuration') #VC: return values can be modified here return None
def initDisplays(initFlag=vizconnect.INIT_INDEPENDENT, initList=None): #VC: place any general initialization code here rawDisplay = vizconnect.getRawDisplayDict() #VC: initialize a new display _name = 'cave_manual_configuration' if vizconnect.isPendingInit('display', _name, initFlag, initList): #VC: init which needs to happen before viz.go if initFlag&vizconnect.INIT_PREVIZGO: #viz.setOption('viz.stereo', viz.QUAD_BUFFER) viz.setOption('viz.fullscreen', 1) viz.setOption('viz.antialias', 8) #VC: init the raw object if initFlag&vizconnect.INIT_RAW: #VC: set the window for the display _window = viz.MainWindow #VC: set some parameters frontWall = [1,2] rightWall = [3,4] backWall = -1 leftWall = [5,6] floor = -1 ceiling = -1 frontImageWidth = 3.6 imageHeight = 2.5 imageRise = 0.02 originLeft = 1.725 originRight = 2.205 sideImageWidth = 4 shiftRight = 0 shiftUp = 0 shiftForward = 0 stereo = viz.QUAD_BUFFER frontWallSwapStereo = False rightWallSwapStereo = False backWallSwapStereo = False leftWallSwapStereo = False floorSwapStereo = False ceilingSwapStereo = False #VC: create the raw object # Create a cave object import vizcave cave = vizcave.Cave(stereo=stereo) # get an origin node originName = _name initGroups(vizconnect.INIT_INDEPENDENT, [originName])# ensure it's been created originNode = vizconnect.getGroup(originName).getNode3d() if sideImageWidth == 0: sideImageWidth = frontImageWidth # extra configuration options to more explicitly control which wall goes where. frontWallClientIndex=-1 rightWallClientIndex=-1 backWallClientIndex=-1 leftWallClientIndex=-1 floorClientIndex=-1 ceilingClientIndex=-1 # get the originLeft angle from the origin measurements import math aOR = math.pi/4.0 aAOR = (originRight**2 - originLeft**2 - frontImageWidth**2)/(-2*originLeft*frontImageWidth) if abs(aAOR) <= 1: aOR = math.acos(aAOR) # convert the angle to front and right shifts Sr =-(math.cos(aOR)*originLeft-frontImageWidth/2.0) Sf = (math.sin(aOR)*originLeft-sideImageWidth/2.0) # find left/right, up/down, front/back (x,y,z) extent of caves R = frontImageWidth/2.0+Sr+shiftRight# right L =-frontImageWidth/2.0+Sr+shiftRight# left U = imageRise+imageHeight+shiftUp# up/top D = imageRise+shiftUp# bottom/down F = sideImageWidth/2.0+Sf+shiftForward# front B =-sideImageWidth/2.0+Sf+shiftForward# back # find corners # e.g. # Front Wall: C1,C2,C5,C6 # Left Wall: C0,C1,C4,C5 # Right Wall: C2,C3,C6,C7 C0 = L, U, B C1 = L, U, F C2 = R, U, F C3 = R, U, B C4 = L, D, B C5 = L, D, F C6 = R, D, F C7 = R, D, B clients = 0 #Create front wall if frontWall >= 0: wall = vizcave.Wall( upperLeft=C1, upperRight=C2, lowerLeft=C5, lowerRight=C6, name='Front Wall' ) if frontWallClientIndex == -1: frontWallClientIndex = clients cave.addWall(wall, mask=2**frontWallClientIndex, window=_window) with viz.cluster.MaskedContext(2**frontWallClientIndex): # check if the fullscreen monitor is defined. viz.window.setFullscreenMonitor(frontWall) _window.setStereoSwap(frontWallSwapStereo) viz.window.setFullscreenRectangle([2563, 15, 2260, 1585]) viz.window.setFullscreen(True) clients += 1 #Create right wall if rightWall >= 0: wall = vizcave.Wall( upperLeft=C2, upperRight=C3, lowerLeft=C6, lowerRight=C7, name='Right Wall' ) if rightWallClientIndex == -1: rightWallClientIndex = clients cave.addWall(wall, mask=2**rightWallClientIndex, window=_window) with viz.cluster.MaskedContext(2**rightWallClientIndex): # check if the fullscreen monitor is defined. viz.window.setFullscreenMonitor(rightWall) _window.setStereoSwap(rightWallSwapStereo) viz.window.setFullscreenRectangle([5120, 12, 2526, 1587]) viz.window.setFullscreen(True) clients += 1 #Create back wall if backWall >= 0: wall = vizcave.Wall( upperLeft=C3, upperRight=C0, lowerLeft=C7, lowerRight=C4, name='Back Wall' ) if backWallClientIndex == -1: backWallClientIndex = clients cave.addWall(wall, mask=2**backWallClientIndex, window=_window) with viz.cluster.MaskedContext(2**backWallClientIndex): # check if the fullscreen monitor is defined. viz.window.setFullscreenMonitor(backWall) _window.setStereoSwap(backWallSwapStereo) viz.window.setFullscreen(True) clients += 1 #Create left wall if leftWall >= 0: wall = vizcave.Wall( upperLeft=C0, upperRight=C1, lowerLeft=C4, lowerRight=C5, name='Left Wall' ) leftWallClientIndex = clients cave.addWall(wall, mask=2**leftWallClientIndex, window=_window) with viz.cluster.MaskedContext(2**leftWallClientIndex): # check if the fullscreen monitor is defined. viz.window.setFullscreenMonitor(leftWall) _window.setStereoSwap(leftWallSwapStereo) viz.window.setFullscreenRectangle([32, 20, 2525, 1580]) viz.window.setFullscreen(True) clients += 1 #Create floor if floor >= 0: wall = vizcave.Wall( upperLeft=C5, upperRight=C6, lowerLeft=C4, lowerRight=C7, name='Floor' ) floorClientIndex = clients cave.addWall(wall, mask=2**floorClientIndex, window=_window) with viz.cluster.MaskedContext(2**floorClientIndex): # check if the fullscreen monitor is defined. viz.window.setFullscreenMonitor(floor) _window.setStereoSwap(floorSwapStereo) viz.window.setFullscreen(True) clients += 1 #Create ceiling if ceiling >= 0: wall = vizcave.Wall( upperLeft=C0, upperRight=C3, lowerLeft=C1, lowerRight=C2, name='Ceiling' ) ceilingClientIndex = clients cave.addWall(wall, mask=2**ceilingClientIndex, window=_window) with viz.cluster.MaskedContext(2**ceilingClientIndex): # check if the fullscreen monitor is defined. viz.window.setFullscreenMonitor(ceiling) _window.setStereoSwap(ceilingSwapStereo) viz.window.setFullscreen(True) clients += 1 # We need to pass an object which will be used to update the projection # or the display to the view's position, typically this would be the # node attached to an avatar's head tracker. viewpoint = viz.addGroup() cave.setTracker(viewpoint) # Create a CaveView object for manipulating the entire cave environment. # The caveView is a node that can be adjusted to move the entire # cave around the virtual environment. caveView = vizcave.CaveView(viewpoint) _window.originLink = viz.link(originNode, caveView, dstFlag=viz.ABS_GLOBAL, srcFlag=viz.ABS_GLOBAL) _window.caveView = caveView _window.originNode = originNode _window.displayNode = cave _window.viewpointNode = viewpoint rawDisplay[_name] = _window #VC: init the wrapper (DO NOT EDIT) if initFlag&vizconnect.INIT_WRAPPERS: vizconnect.addDisplay(rawDisplay[_name], _name, make='Generic', model='Cave Manual Configuration') #VC: set the parent of the node if initFlag&vizconnect.INIT_PARENTS: vizconnect.getDisplay(_name).setParent(vizconnect.getAvatar('head_and_hand').getAttachmentPoint('head')) #VC: return values can be modified here return None
def initDisplays(initFlag=vizconnect.INIT_INDEPENDENT, initList=None): #VC: place any general initialization code here rawDisplay = vizconnect.getRawDisplayDict() #VC: initialize a new display _name = 'cave_data_file' if vizconnect.isPendingInit('display', _name, initFlag, initList): #VC: init which needs to happen before viz.go if initFlag & vizconnect.INIT_PREVIZGO: viz.setOption('viz.stereo', viz.QUAD_BUFFER) viz.setOption('viz.fullscreen', 1) #VC: init the raw object if initFlag & vizconnect.INIT_RAW: #VC: set the window for the display _window = viz.MainWindow #VC: set some parameters stereo = viz.QUAD_BUFFER filename = 'C:/demos/Cave_settings.txt' #VC: create the raw object # Create a cave object import vizcave cave = vizcave.Cave(stereo=stereo) try: cave.load(filename) except IOError: viz.logError( "** Error: unable to load cave configuration file {}.". format(filename)) # get an origin node originName = _name initGroups(vizconnect.INIT_INDEPENDENT, [originName]) # ensure it's been created originNode = vizconnect.getGroup(originName).getNode3d() # We need to pass an object which will be used to update the projection # or the display to the view's position, typically this would be the # node attached to an avatar's head tracker. viewpoint = viz.addGroup() cave.setTracker(viewpoint) # Create a CaveView object for manipulating the entire cave environment. # The caveView is a node that can be adjusted to move the entire # cave around the virtual environment. caveView = vizcave.CaveView(viewpoint) _window.originLink = viz.link(originNode, caveView, dstFlag=viz.ABS_GLOBAL, srcFlag=viz.ABS_GLOBAL) _window.caveView = caveView _window.originNode = originNode _window.displayNode = cave _window.viewpointNode = viewpoint rawDisplay[_name] = _window #VC: init the wrapper (DO NOT EDIT) if initFlag & vizconnect.INIT_WRAPPERS: vizconnect.addDisplay(rawDisplay[_name], _name, make='Generic', model='Cave Data File') #VC: set the parent of the node if initFlag & vizconnect.INIT_PARENTS: vizconnect.getDisplay(_name).setParent( vizconnect.getAvatar('head_and_hand').getAttachmentPoint( 'head')) #VC: return values can be modified here return None
def initDisplays(initFlag=vizconnect.INIT_INDEPENDENT, initList=None): #VC: place any general initialization code here rawDisplay = vizconnect.getRawDisplayDict() #VC: initialize a new display _name = 'main_display' if vizconnect.isPendingInit('display', _name, initFlag, initList): #VC: init which needs to happen before viz.go if initFlag & vizconnect.INIT_PREVIZGO: viz.setOption('viz.stereo', viz.QUAD_BUFFER) viz.setOption('viz.fullscreen', 1) #VC: init the raw object if initFlag & vizconnect.INIT_RAW: #VC: set the window for the display _window = viz.MainWindow #VC: set some parameters imageWidth = 3 imageHeight = 2.25 imageRise = 0.045 originLeft = 2.897 originRight = 2.934 shiftRight = 0 shiftUp = 0 shiftForward = 0 stereo = viz.QUAD_BUFFER swapStereo = False #VC: create the raw object # Create a cave object import vizcave cave = vizcave.Cave(stereo=stereo) # get an origin node originName = _name initGroups(vizconnect.INIT_INDEPENDENT, [originName]) # ensure it's been created originNode = vizconnect.getGroup(originName).getNode3d() # get the originLeft angle from the origin measurements import math aOR = math.pi / 4.0 aAOR = (originRight**2 - originLeft**2 - imageWidth**2) / (-2 * originLeft * imageWidth) if abs(aAOR) <= 1: aOR = math.acos(aAOR) # convert the angle to front and right shifts Sr = -(math.cos(aOR) * originLeft - imageWidth / 2.0) distanceToFront = math.sin(aOR) * originLeft # find left/right, up/down, front/back (x,y,z) extent of caves R = imageWidth / 2.0 + Sr + shiftRight # right L = -imageWidth / 2.0 + Sr + shiftRight # left U = imageRise + imageHeight + shiftUp # up/top D = imageRise + shiftUp # bottom/down F = distanceToFront + shiftForward # front C0 = L, U, F C1 = R, U, F C2 = L, D, F C3 = R, D, F #Create front wall wall = vizcave.Wall(upperLeft=C0, upperRight=C1, lowerLeft=C2, lowerRight=C3, name='Front Wall') cave.addWall(wall, window=_window) _window.setStereoSwap(swapStereo) #_window.setSize([1, 1]) # We need to pass an object which will be used to update the projection # or the display to the view's position, typically this would be the # node attached to an avatar's head tracker. viewpoint = viz.addGroup() cave.setTracker(viewpoint) # Create a CaveView object for manipulating the entire cave environment. # The caveView is a node that can be adjusted to move the entire # cave around the virtual environment. caveView = vizcave.CaveView(viewpoint, view=_window.getView()) _window.originLink = viz.link(originNode, caveView, dstFlag=viz.ABS_GLOBAL, srcFlag=viz.ABS_GLOBAL) _window.caveView = caveView _window.originNode = originNode _window.displayNode = cave _window.viewpointNode = viewpoint rawDisplay[_name] = _window #VC: init the wrapper (DO NOT EDIT) if initFlag & vizconnect.INIT_WRAPPERS: vizconnect.addDisplay(rawDisplay[_name], _name, make='Generic', model='Powerwall') #VC: set the parent of the node if initFlag & vizconnect.INIT_PARENTS: vizconnect.getDisplay(_name).setParent( vizconnect.getAvatar('main_avatar').getAttachmentPoint('head')) #VC: set the name of the default vizconnect.setDefault('display', 'main_display') #VC: return values can be modified here return None