Example #1
0
 def __init__(self,
              x=0,
              y=0,
              angle=0,
              scale=4,
              speed=DEFAULT_MAX_SPEED,
              center_offset=0,
              callback=None,
              **kwargs):
     print 'Initializing Joystick.movement'
     global __JOYSTICK_VAR
     frequency = 0.01
     timer_id = 1
     self.motion = __JOYSTICK_VAR = InputHandler(frequency,
                                                 speed * scale / 8,
                                                 **kwargs)
     self.scale = float(scale)
     self.callbacks = {timer_id: self.UpdateLocation}
     self.coords = (x, y, angle)
     self.callback = callback
     self.center_offset = center_offset
     viz.eyeheight(0.0)
     viz.setfov(70, 1)
     viz.mouse(viz.OFF)  # don't want vizard mouse navigation
     viz.callback(viz.TIMER_EVENT, self.TimerCallback)
     viz.starttimer(timer_id, frequency, -1)
Example #2
0
    def __init__(self,
                 callbackFrequency,
                 maxSpeed=DEFAULT_MAX_SPEED,
                 joyCalFile=None,
                 joystick=True,
                 keyboard=False,
                 mouse=False,
                 forward=True,
                 backward=True,
                 turn=True):
        self.JOY_MOVE_FREQUENCY = callbackFrequency
        self.REAL_MAX_SPEED = maxSpeed
        self.COLLISION_BUFFER = 5.0 * maxSpeed * callbackFrequency
        self.joystick = joystick
        self.keyboard = keyboard
        self.mouse = mouse
        self.forward = forward
        self.backward = backward
        self.turn = turn

        if joystick:
            if joyCalFile: self.LoadJoyCalFile(joyCalFile)
            else: self.LoadJoyCalFile()

        self.lastObjectIntersected = None
        viz.eyeheight(0.15)
        #viz.setfov(70,1)
        viz.mouse(viz.OFF)  # don't want mouse input
        self.MoveTo([0, 0, 0])
        self.CONVERT_SPEED = maxSpeed
        self.CONVERT_ROTSPEED = REAL_MAX_ROTSPEED
def enable():
	global enabled
	if not enabled:
		selector.enable()
		counter.enable()
		enabled = True
		
		if SELL_ON_CLICK and enabled:
			global sellObjOnClick
			sellObjOnClick = vizact.onmousedown(viz.MOUSEBUTTON_LEFT, viztask.schedule, sellSelectedObject())
			viz.mouse(viz.OFF)
def disable():
	global enabled
	if enabled:
		selector.disable()
		counter.disable()
		enabled = False
		
		if SELL_ON_CLICK and not enabled:
			global sellObjOnClick
			sellObjOnClick.remove()
			viz.mouse(viz.ON)
Example #5
0
File: mouse.py Project: kevinsp/DvB
def enableDisableMouse(tracker, link, menubar):

    global euler
    global position
    if viz.mouse.getVisible():
        viz.mouse(viz.ON)
        tracker.setEuler(euler)
        tracker.setPosition(position)
        link.enable()
        viz.mouse.setVisible(False)
        menubar.setVisible(False)
    else:
        viz.mouse(viz.OFF)
        euler = tracker.getEuler()
        position = tracker.getPosition()
        link.disable()
        viz.mouse.setVisible(True)
        menubar.setVisible(True)
Example #6
0
def bmw_card_driver():
	
	car = viz.addChild('bmw.dae')
	car.setEuler([0,0,0])
	car.setScale(0.5,0.5,0.5)
	MOVE_SPEED = 5
	TURN_SPEED = 60

	def updatecar():
		#move view forward and backward
		if viz.key.isDown(viz.KEY_UP):
			view.move([0,0,MOVE_SPEED*viz.elapsed()],viz.BODY_ORI)
		elif viz.key.isDown(viz.KEY_DOWN):
			view.move([0,0,-MOVE_SPEED*viz.elapsed()],viz.BODY_ORI)

		#rotate body of view left and right
		if viz.key.isDown(viz.KEY_RIGHT):
			view.setEuler([TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT)
		elif viz.key.isDown(viz.KEY_LEFT):
			view.setEuler([-TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT)

		#set the car to view position and body orientation
		car.setPosition(view.getPosition())
		car.setEuler(view.getEuler(viz.BODY_ORI))
		car.setPosition([3.02,-5.50,5.04],viz.REL_LOCAL)

	vizact.ontimer(0,updatecar)

	#update head of view based on mouse movements
	def mousemove(e):
		euler = view.getEuler(viz.HEAD_ORI)
		euler[0] += e.dx*0.1
		euler[1] += -e.dy*0.1
		euler[1] = viz.clamp(euler[1],-85.0,85.0)
		view.setEuler(euler,viz.HEAD_ORI)

	viz.callback(viz.MOUSE_MOVE_EVENT,mousemove)
	viz.mouse(viz.OFF)
	viz.mouse.setVisible(False)

	vizact.onmousedown(viz.MOUSEBUTTON_LEFT,view.reset,viz.HEAD_ORI)
	vizact.onmousedown(viz.MOUSEBUTTON_RIGHT,view.reset, viz.BODY_ORI |viz.HEAD_POS)
	vizact.onmousedown(viz.MOUSEBUTTON_RIGHT,updatecar)
def Init(LayoutFile=None,scale=4,speed=None,center_offset=0):
	"""
	Initialize the module. Must be called before any of the module functions can be called.

	Parameters:
	All parameters are optional.

	LayoutFile: <String> The name of the text file defining the map. If this parameter is
	provided, then the module will keep track of the subject's position in the layout and the subject will
	be prevented from moving through walls. This parameter must be given to use CanMoveForward and GetView.

	scale: <Float> The distance in meters between the center of two nodes in the environment. This is
	the distance that the subject will move when GoForward is called.

	speed: <Float> The speed that the subject will move forward in meters per second. If None, then
	the speed will be set to scale.

	center_offset: <Float> The distance in meters that the subject is separated from his axis of
	rotation. The axis of rotation is always the center of a node.

	Return Value: None.
	"""
	global __MOVEMENT_VAR, __PLAT_VAR
	if not speed: speed = scale
	__MOVEMENT_VAR = __MOVEMENT_CLASS(0,0,0,scale,speed,center_offset)
	viz.eyeheight(0.0)
	#viz.setfov(70,1)
	viz.mouse(viz.OFF) # don't want mouse input
	viz.callback(viz.TIMER_EVENT, TimerCallback)
	if LayoutFile:
		try:
			# use __PLAT_VAR to hold info about LayoutFile
			width, height, size = Navigator.getPlatDim(LayoutFile)
			__PLAT_VAR = Navigator.PLAT(width,height,size)
			__PLAT_VAR.ReadTextImage(LayoutFile)
			__PLAT_VAR.ComputeAllViews(100)
		except:
			__PLAT_VAR = None
			raise ("\n****** Error in Movement.Init ******\nUnable to initialize Plat Object with '%s'\n"%LayoutFile)
Example #8
0
    def gameOver(self, gameWon):
        self.killtimer(0)
        self.killtimer(1)
        self.killtimer(2)

        self.map.remove()
        self.gun.remove()
        self.sky.remove()
        self.skybox.remove()
        viz.mouse(viz.OFF)

        for enemy in self.enemyList:
            enemy.remove()

        for bullet in self.bullets:
            bullet.remove()

        if not gameWon:
            text = viz.addText3D('Game Over \nScore: ' + str(self.score))
            text.color(viz.BLACK)
            text.font('COURIER NEW')
        else:
            text = viz.addText('You Win \nScore: ' + str(self.score))
            text.color(viz.BLACK)
            text.font('COURIER NEW')

        self.gameOverText = text

        mat = viz.Matrix()
        mat.postTrans(0, 0, 0)
        self.camera.setMatrix(mat)
        mat.postTrans(-4, 2, 15)
        self.gameOverText.setMatrix(mat)

        self.killtimer(0)
        self.killtimer(1)
        self.killtimer(2)
Example #9
0
File: GUI.py Project: kevinsp/DvB
	def __init__(self):
		#viz.window.setFullscreen(True)

		viz.MainWindow.fov(60)
		#viz.window.setFullscreen(True)


		#Popups
		fullscreenItem = vizpopup.Item('Fullscreen')

		mymenu = vizpopup.Menu('Main',[fullscreenItem])



		#Bei Rechtklick Menüaufruf
		vizact.onmouseup(viz.MOUSEBUTTON_RIGHT, self.showMenu)

		#Fullscreen on/off
		vizpopup.onMenuItem(fullscreenItem,viz.window.setFullscreen,viz.TOGGLE)


		#Menübar
		self.menubar = vizmenu.add()
		self.menubar.setVisible(False)

		#Bearbeiten
		self.BearbeitenMenu = self.menubar.add("Bearbeiten")
		self.buttonDateiOeffnen = self.BearbeitenMenu.add(viz.BUTTON_LABEL, "Datei öffnen")
		self.buttonModelEntfernen = self.BearbeitenMenu.add(viz.BUTTON_LABEL, "Model entfernen")

		#Ansicht DropDown
		self.AnsichtsMenu = self.menubar.add("Ansicht")
		self.checkRohre = self.AnsichtsMenu.add(viz.CHECKBOX, "Rohre")
		self.checkWaende = self.AnsichtsMenu.add(viz.CHECKBOX, "Wände")
		self.checkBirdEyeView = self.AnsichtsMenu.add(viz.CHECKBOX, "Vogelperspektive")
		self.checkPointsView = self.AnsichtsMenu.add(viz.CHECKBOX, "Checkpoints")
		self.checkPointSetzen = self.AnsichtsMenu.add(viz.BUTTON_LABEL, "Checkpoint setzen")
		self.checkPointLoeschen = self.AnsichtsMenu.add(viz.BUTTON_LABEL, "Checkpoint löschen")
		self.checkPortButton = self.AnsichtsMenu.add(viz.BUTTON_LABEL, "Zu Checkpoints porten")
		self.noteViewButton = self.AnsichtsMenu.add(viz.CHECKBOX, "Notizen")
		self.deleteNoteButton = self.AnsichtsMenu.add(viz.BUTTON_LABEL, "Lösche 3D Notiz")
		self.notePortButton = self.AnsichtsMenu.add(viz.BUTTON_LABEL, "Zu 3D Notizen porten")
		self.beliebigPortButton = self.AnsichtsMenu.add(viz.BUTTON_LABEL, "Porten")

		#Einfügen DropDown
		self.EinfuegenMenu = self.menubar.add("Einfügen")
		self.buttonNotizEinfuegen = self.EinfuegenMenu.add(viz.BUTTON_LABEL, "Notiz")

		#Optionen DropDown
		self.OptionenMenu = self.menubar.add("Optionen")

		#Alphawert
		self.alphaSlider = self.AnsichtsMenu.add(viz.SLIDER, "Alphawert")
		self.alphaSlider.set(1.0)

		#Steuerung
		viz.mouse(viz.ON)
		viz.mouse.setTrap()
		self.tracker = vizcam.addWalkNavigate(moveScale=2.0)
		self.tracker.setPosition([0,1.8,0])
		self.link = viz.link(self.tracker,viz.MainView)
		viz.mouse.setVisible(False)


		#Erstes Model laden
		self.model = viz.addChild(r'C:\Users\pasca_000\Downloads\CADModellHofner.obj')
		modelIsLoaded = True
		self.model.disable(viz.CULL_FACE)
		self.model.setPosition(0,0,60, viz.ABS_GLOBAL)
		self.model.setEuler([0,0,0])
		viz.collision(viz.ON)

		#Boden laden
		self.ground1 = viz.addChild('ground.osgb')
		self.ground2 = viz.addChild('ground.osgb')
		self.ground2.setPosition(0,0,50)
		
		#Begrüßungsnachricht
		message = """Danke, dass Sie sich für unsere Software entschieden haben.
		\nHier die wichtigsten Shortcuts zum bedienen des Programmes:
		C:   Anzeigen der bereits gesetzten Checkpoints
		N:   Anzeigen der bereits gesetzten 3D Notizen
		V:   Anzeigen der Vogelperspektive
		H:   Anzeigen dieser Hilfe"""
		checkPointsPanel = vizinfo.InfoPanel(message,align=viz.ALIGN_CENTER,fontSize=15,icon=False,key="h")
		checkPointsPanel.visible(True)
		
		
		#Button Definition
		vizact.onbuttondown(self.buttonDateiOeffnen, self.setModel, r'C:\Users\pasca_000\Downloads\CADModellHofner.obj' )
		vizact.onbuttondown(self.buttonModelEntfernen, self.deleteModel)

		#Note Buttons
		vizact.onbuttondown(self.buttonNotizEinfuegen, notes.openTextBox)
		vizact.onbuttondown(self.noteViewButton, notes.noteView, False)
		vizact.onbuttonup(self.noteViewButton, notes.noteView, False)
		vizact.onbuttondown(self.deleteNoteButton, notes.delete3DNote)
		vizact.onbuttondown(self.notePortButton, notes.port3DNote, self.tracker)

		#BirdEyeView Buttons
		vizact.onbuttondown(self.checkBirdEyeView, birdView.enableBirdEyeView)
		vizact.onbuttonup(self.checkBirdEyeView, birdView.enableBirdEyeView)

		#Checkpoints Buttons
		vizact.onbuttondown(self.checkPointsView, checkpoints.checkPoints, False)
		vizact.onbuttonup(self.checkPointsView, checkpoints.checkPoints, False)
		vizact.onbuttondown(self.checkPointSetzen, checkpoints.createCheckpoint)
		vizact.onbuttondown(self.checkPointLoeschen, checkpoints.deleteCheckpoint)
		vizact.onbuttondown(self.checkPortButton, checkpoints.portCheckPoint, self.tracker)

		#Port Button
		vizact.onbuttondown(self.beliebigPortButton, porten.porten, self.tracker)
	
		#Shortcuts
		vizact.onkeydown(viz.KEY_CONTROL_L, mouse.enableDisableMouse, self.tracker, self.link, self.menubar)
		vizact.onkeydown("c", checkpoints.checkPoints, False)
		vizact.onkeydown("v", birdView.enableBirdEyeView)
		vizact.onkeydown("n", notes.noteView, False)
Example #10
0
def maze_choice():

    # load start box
    choice_box = vizinfo.add('')
    choice_box.title('Maze Choice')
    choice_box.scale(2, 2)
    choice_box.translate(0.85, 0.65)
    choice_box.drag(viz.OFF)

    # add options for different mazes
    maze_a = choice_box.add(viz.BUTTON, 'Maze Layout A')
    maze_b = choice_box.add(viz.BUTTON, 'Maze Layout B')
    maze_c = choice_box.add(viz.BUTTON, 'Maze Layout C')
    maze_d = choice_box.add(viz.BUTTON, 'Maze Layout D')

    # add variables for user chocies
    maze_a_pressed = viztask.waitButtonDown(maze_a)
    maze_b_pressed = viztask.waitButtonDown(maze_b)
    maze_c_pressed = viztask.waitButtonDown(maze_c)
    maze_d_pressed = viztask.waitButtonDown(maze_d)

    # data variable to hold user choices
    data = viz.Data()

    # get the maze name root, and start/end coordinates from user choice
    global maze_root
    global start_coords
    global start_ori
    global end_coords
    yield viztask.waitAny(
        [maze_a_pressed, maze_b_pressed, maze_c_pressed, maze_d_pressed], data)
    if data.condition is maze_a_pressed:
        choice_box.remove()
        yield phase_choice()
        maze_root = 'C:\Experiments\Bike_Extend_Pilot\SNAP\SNAPMazeA'
        start_coords = (0, 40, 0)
        start_ori = (0, 0, 0)
        end_coords = (-745, -700, 2125, 2180)
    elif data.condition is maze_b_pressed:
        choice_box.remove()
        yield phase_choice()
        maze_root = 'C:\Experiments\Bike_Extend_Pilot\SNAP\SNAPMazeB'
        start_coords = (-1114, 40, 2151)
        start_ori = (-180, 0, 0)
        end_coords = (-1876, -1795, 115, 156)
    elif data.condition is maze_c_pressed:
        choice_box.remove()
        yield phase_choice()
        maze_root = 'C:\Experiments\Bike_Extend_Pilot\SNAP\SNAPMazeC'
        start_coords = (100, 0, -47)
        start_ori = (90, 0, 0)
        end_coords = (640, 750, 2080, 2120)
    elif data.condition is maze_d_pressed:
        choice_box.remove()
        yield phase_choice()
        maze_root = 'C:\Experiments\Bike_Extend_Pilot\SNAP\SNAPMazeD'
        start_coords = (414, 0, 285)
        start_ori = (0, 0, 0)
        end_coords = (550, 575, 1100, 1200)
    choice_box.remove()

    # turn the mouse off so it doesn't interfere with the environment
    viz.mouse(viz.OFF)
    viz.mouse.setVisible(viz.OFF)
Example #11
0
def task_choice():

    # ensure that the mouse is turned on
    viz.mouse(viz.ON)
    viz.mouse.setVisible(viz.ON)

    # load condition_box
    condition_box = vizinfo.add('')
    condition_box.title('SNAP')
    condition_box.scale(2, 2)
    condition_box.translate(0.85, 0.65)
    condition_box.drag(viz.OFF)

    # add different options
    condition_one = condition_box.add(viz.BUTTON, 'Condition 1')
    condition_two = condition_box.add(viz.BUTTON, 'Condition 2')
    practice = condition_box.add(viz.BUTTON, 'Practice Program')
    expertise = condition_box.add(viz.BUTTON, 'Visuomotor Expertise Program')
    maze_quit = condition_box.add(viz.BUTTON, 'Quit Maze Program')

    # add variables for user chocies
    condition_one_pressed = viztask.waitButtonDown(condition_one)
    condition_two_pressed = viztask.waitButtonDown(condition_two)
    practice_pressed = viztask.waitButtonDown(practice)
    expertise_pressed = viztask.waitButtonDown(expertise)
    maze_quit_pressed = viztask.waitButtonDown(maze_quit)

    # data variable to hold user choices
    data = viz.Data()

    # setup globals
    global condition
    global maze_root
    global start_coords
    global start_ori
    global end_coords

    # While statment that will run a different maze based on user choice.
    # Will keep looping until the user selects quit and ends the program
    while True:
        yield viztask.waitAny([
            condition_one_pressed, condition_two_pressed, practice_pressed,
            expertise_pressed, maze_quit_pressed
        ], data)
        condition_box.remove()
        if data.condition is condition_one_pressed:
            condition = 1
            yield maze_choice()
            yield run_condition_one()
            yield task_choice()
        elif data.condition is condition_two_pressed:
            condition = 2
            yield maze_choice()
            yield run_condition_two()
            yield task_choice()
        elif data.condition is practice_pressed:
            viz.mouse(viz.OFF)
            viz.mouse.setVisible(viz.OFF)
            maze_root = 'C:\Experiments\Bike_Extend_Pilot\SNAP\PMS'
            start_coords = (0, 40, 0)
            start_ori = (3.5, 0, 0)
            yield practice_maze()
            yield task_choice()
        elif data.condition is expertise_pressed:
            viz.mouse(viz.OFF)
            viz.mouse.setVisible(viz.OFF)
            maze_root = 'C:\Experiments\Bike_Extend_Pilot\SNAP\VMS'
            start_coords = (0, 40, 0)
            start_ori = (0, 0, 0)
            end_coords = [1150, 1275, -190, -100]
            yield expertise_maze()
            yield task_choice()
        elif data.condition is maze_quit_pressed:
            viz.quit()

    viz.quit()
Example #12
0
    def __init__(self, config):
        viz.EventClass.__init__(self)
        viz.mouse(viz.ON)
        self.config = config

        # set first person movement controls and hide mouse
        viz.cam.setHandler(vizcam.WalkNavigate(moveScale=2.0, turnScale=2.0))
        viz.mouse.setVisible(viz.OFF)

        # initialize camera and map
        self.camera = viz.MainView
        self.map = viz.add(self.config[0])
        self.camX = self.config[1]
        self.camY = self.config[2]
        self.camZ = self.config[3]
        self.camAngle = self.camera.getAxisAngle()
        self.camVector = [0, 0, 0]
        self.bulletVector = [0, 0, 0]

        # initialize gun
        self.gun = viz.add('gun.dae')

        # track active bullets
        self.bullets = []

        # reload indicator
        self.reload = viz.addText3D('   R\n   to Reload')
        self.reload.color(viz.WHITE)
        self.reload.font('COURIER NEW')
        self.reload.visible(viz.OFF)

        self.gunX = self.config[1]
        self.gunY = self.config[2]
        self.gunZ = self.config[3] + 2
        mat = viz.Matrix()
        mat.postTrans(self.gunX, self.gunY, self.gunZ)
        self.gun.setMatrix(mat)

        # position the camera
        self.setCameraTransforms()

        # add enemies
        enemyCoords = self.config[4]
        self.enemyList = []
        counter = 0
        for x, y, z, radius in enemyCoords:
            self.enemyList.append(viz.add('model.dae'))
            mat = viz.Matrix()
            mat.postScale(0.125, 0.125, 0.125)
            mat.postTrans(x, y, z)
            self.enemyList[counter].setMatrix(mat)
            counter += 1

        # scoring variables
        self.enemyCount = 0
        for enemy in self.enemyList:
            self.enemyCount += 1
        self.score = 0

        # game over variables
        self.gameIsOver = False
        self.gameOverText = None

        # add a sky
        self.sky = viz.add(viz.ENVIRONMENT_MAP, 'sky.jpg')
        self.skybox = viz.add('skydome.dlc')
        self.skybox.texture(self.sky)

        # enable physics
        self.setPhysics()

        self.callback(viz.TIMER_EVENT, self.onTimer)
        self.callback(viz.MOUSEDOWN_EVENT, self.onMouseDown)
        self.callback(viz.COLLIDE_BEGIN_EVENT, self.onCollide)
        self.callback(viz.COLLISION_EVENT, self.camCollide)
        self.callback(viz.KEYDOWN_EVENT, self.onKeyDown)
        self.starttimer(0, 1 / 2, viz.FOREVER)
Example #13
0
    def __init__(self):
        viz.mouse(viz.OFF)
        viz.EventClass.__init__(self)

        #Title Screen - disappears after user pushes RETURN
        self.title = viz.addText3D(
            'Michael Ippolito and Christopher McCoy \n' +
            '        Graphics Final Project \n' +
            '        Press Enter to Start')
        self.title.color(viz.BLACK)
        self.title.font('COURIER NEW')

        #Boolean set true after the title disappears
        self.mapSelect = False

        #Map 1: Shipment
        self.shipment = viz.addText3D('Shipment')
        self.shipment.color(viz.BLACK)
        self.shipment.font('COURIER NEW')

        mat = viz.Matrix()
        mat.postTrans(-11, 3, 25)
        self.title.setMatrix(mat)

        self.shipment.setMatrix(mat)
        self.shipment.visible(viz.OFF)

        #Map 2:
        self.factory = viz.addText3D('Factory')
        self.factory.color(viz.BLACK)
        self.factory.font('COURIER NEW')

        mat = viz.Matrix()
        mat.postTrans(0, 3, 25)

        self.factory.setMatrix(mat)
        self.factory.visible(viz.OFF)

        #Instructions
        self.mapText = viz.addText3D(
            'Press Left and Right to select.\nPress enter to start.')
        self.mapText.color(viz.BLACK)
        self.mapText.font('COURIER NEW')

        mat = viz.Matrix()
        mat.postTrans(-11, 5, 25)

        self.mapText.setMatrix(mat)
        self.mapText.visible(viz.OFF)

        self.maps = [self.shipment, self.factory]
        self.curMap = 0

        #Configuration for each map
        #[filename, startX, startY, startZ, [[enemy1x,enemy1y,enemy1z, enemy1radius][...]]]

        self.config = [[
            'shipment.dae', 50, 2.5, 50,
            [[50, 0, 88, 3.5], [39, 0, 71, 2], [72, 0, 110, 1.5],
             [102, 0, 96, 2], [69, 0, 80, 2], [110, 0, 33, 3]]
        ], ['factory.dae', 15, 2.0, 5, [[15, 0, 9, 1]]]]

        self.callback(viz.KEYDOWN_EVENT, self.onKeyDown)
Example #14
0
# File: main.py
# Purpose: driver program for the bouncing ball example

import viz

# get access to controller class
from Controller import *

# set size (in pixels) and title of application window
viz.window.setSize(500, 500)
viz.window.setName("Bouncing Ball")

# get graphics window
window = viz.MainWindow
# setup viewing rectangle
window.ortho(-100, 100, -100, 100, -1, 1)
# set background color of window to black
viz.MainWindow.clearcolor(viz.BLACK)
# turn off mouse navigation
viz.mouse(viz.ON)
# center viewpoint
viz.eyeheight(0)

# create a controller object
Controller()

# render the scene in the window
viz.go()
Example #15
0
# File: main.py
# Purpose: driver program for the bouncing ball example

import viz

# get access to controller class
from Controller import *

# set size (in pixels) and title of application window
viz.window.setSize(500, 500)
viz.window.setName("Bouncing Ball")

# get graphics window
window = viz.MainWindow
# setup viewing rectangle
window.ortho(-100, 100, -100, 100, -1, 1)
# set background color of window to black
viz.MainWindow.clearcolor(viz.BLACK)
# turn off mouse navigation
viz.mouse(viz.OFF)
# center viewpoint
viz.eyeheight(0)

# create a controller object
c = Controller()

# render the scene in the window
viz.go()
Example #16
0
def createEnvironment():
    global point
    global arrow
    global goal
    global thrust
    global shadow

    #create 3D environment
    if parameters.dreiDEnvironment:

        piazza = viz.addChild('piazza.osgb')

        #look from above
        viz.MainView.setPosition([0, 1.8, -5])
        viz.MainView.setEuler([0, 20, 0])
        viz.collision(viz.ON)
        # gorund for collision
        ground = viz.add('tut_ground.wrl')  # Add ground
        ground.collidePlane()  # Make collideable plane
        ground.disable(viz.RENDERING)
        ground.disable(viz.DEPTH_WRITE)

        # point
        #point = viz.add('ball.wrl')
        point = vizshape.addSphere(radius=parameters.pointRadius,
                                   slices=20,
                                   stacks=20,
                                   axis=vizshape.AXIS_Y)
        pointPhys = point.collideSphere()  # Define ball's physical properties

        point.setEuler(0, 90, 0)
        point.setPosition(0, parameters.point_height, 0)
        point.color(viz.RED)
        point.setScale(0.5, 0.5, 0.5)
        point.enable(viz.COLLIDE_NOTIFY)

        #goal
        goal = vizshape.addCircle(slices=100, radius=0.3)
        goal.setEuler(0, 90, 0)
        goal.color(viz.GREEN)
        goal.setPosition(0, parameters.goal_height, 0)
        goal.setScale(parameters.goal_scale3D, parameters.goal_scale3D,
                      parameters.goal_scale3D)

        #shadow
        shadow = vizshape.addCircle(slices=100, radius=0.3)
        shadow.setEuler(0, 90, 0)
        shadow.color(viz.GRAY)
        shadow.setPosition(0, parameters.shadow_height, 0)
        shadow.setScale(parameters.shadow_scale3D, parameters.shadow_scale3D,
                        parameters.shadow_scale3D)

        #arrow
        arrow = vizshape.addArrow()
        arrow.setPosition(0, parameters.arrow_height3D, 0)
        arrow.color(viz.BLUE)

        #thrust
        thrust = point.addThruster(force=[0, 0, 0])

    #or create 2d environment
    else:
        viz.clearcolor(viz.WHITE)

        #look from above
        viz.MainView.setPosition([0, 8, 0])
        viz.MainView.setEuler([0, 90, 0])

        #point = viz.add('ball.wrl')
        point = vizshape.addSphere(radius=parameters.pointRadius,
                                   slices=20,
                                   stacks=20,
                                   axis=vizshape.AXIS_Y)
        pointPhys = point.collideSphere()  # Define ball's physical properties
        point.setEuler(0, 90, 0)
        point.setPosition(0, parameters.point_height, 0)
        point.color(viz.RED)
        point.visible(False)
        point.enable(viz.COLLIDE_NOTIFY)

        #wind force
        thrust = point.addThruster(force=[0, 0, 0])

        #goal
        goal = vizshape.addCircle(slices=100, radius=0.2)
        goal.setEuler(0, 90, 0)
        goal.color(viz.GREEN)
        goal.visible(False)
        goal.setScale(parameters.goal_scale2D, parameters.goal_scale2D,
                      parameters.goal_scale2D)

        #arrow
        arrow = vizshape.addArrow()
        viz.mouse(viz.OFF)
        arrow.setPosition(0, parameters.arrow_height2D, 0)
        arrow.color(viz.BLUE)
        arrow.visible(False)
def waitForNextClick():
	if SELL_ON_CLICK:
			global sellObjOnClick, SELLABLES, selector
			selector.enable()
			sellObjOnClick = vizact.onmousedown(viz.MOUSEBUTTON_LEFT, viztask.schedule, sellSelectedObject())
			viz.mouse(viz.OFF)
Example #18
0
tool = grabber.Grabber(usingPhysics=usingPhysics, usingSprings=usingPhysics, highlightMode=highlighter.MODE_OUTLINE)
tool.setItems([soccerball,basketball,volleyball])

# update code for grabber
def updateGrabber(tool):
    state = viz.mouse.getState()
    if state & viz. MOUSEBUTTON_LEFT:
        tool.grabAndHold()
tool.setUpdateFunction(updateGrabber)

#Link the grabber to an arrow in order to
#visualize it's position
from vizconnect.util import virtual_trackers
mouseTracker = virtual_trackers.ScrollWheel(followMouse = True)
mouseTracker.distance = 1.4
arrow = vizshape.addArrow(length=0.2,color=viz.BLUE)
arrowLink = viz.link(mouseTracker,arrow)
arrowLink.postMultLinkable(viz.MainView)
viz.link(arrowLink,tool)

spin = vizact.spin(0,1,0,30,2)

#Add a spin action to the ball when its released
def onRelease(e):
    e.released.runAction(spin)
    
viz.callback(grabber.RELEASE_EVENT,onRelease)

#Disable mouse navigation and hide the mouse curser
viz.mouse(viz.OFF)
viz.mouse.setVisible(viz.OFF)
Example #19
0
def createEnvironment():	
	global point 
	global arrow 
	global goal	 
	global thrust
	global shadow

	#create 3D environment
	if parameters.dreiDEnvironment:

		piazza = viz.addChild('piazza.osgb')
	
		#look from above
		viz.MainView.setPosition([0,1.8,-5])
		viz.MainView.setEuler([0,20,0])
		viz.collision(viz.ON)
		# gorund for collision
		ground = viz.add('tut_ground.wrl')  # Add ground
		ground.collidePlane()   # Make collideable plane 
		ground.disable(viz.RENDERING)
		ground.disable(viz.DEPTH_WRITE)
		
		# point
		#point = viz.add('ball.wrl')
		point = vizshape.addSphere(radius = parameters.pointRadius, slices = 20, stacks = 20, axis = vizshape.AXIS_Y)
		pointPhys = point.collideSphere()   # Define ball's physical properties 
	
		point.setEuler(0,90,0)
		point.setPosition(0,parameters.point_height,0)
		point.color(viz.RED)
		point.setScale(0.5,0.5,0.5)
		point.enable( viz.COLLIDE_NOTIFY )
		
		#goal
		goal = vizshape.addCircle(slices=100, radius=0.3)		
		goal.setEuler(0,90,0)
		goal.color(viz.GREEN)		
		goal.setPosition(0,parameters.goal_height,0)
		goal.setScale(parameters.goal_scale3D,parameters.goal_scale3D,parameters.goal_scale3D)
		
		#shadow
		shadow = vizshape.addCircle(slices=100, radius=0.3)		
		shadow.setEuler(0,90,0)
		shadow.color(viz.GRAY)		
		shadow.setPosition(0,parameters.shadow_height,0)
		shadow.setScale(parameters.shadow_scale3D,parameters.shadow_scale3D,parameters.shadow_scale3D)

		#arrow
		arrow = vizshape.addArrow()	
		arrow.setPosition(0,parameters.arrow_height3D,0)
		arrow.color(viz.BLUE)
		
		#thrust
		thrust = point.addThruster(force=[0,0,0]) 

	#or create 2d environment
	else:
		viz.clearcolor(viz.WHITE)

		#look from above
		viz.MainView.setPosition([0,8,0])
		viz.MainView.setEuler([0,90,0])
		
		#point = viz.add('ball.wrl')
		point = vizshape.addSphere(radius = parameters.pointRadius, slices = 20, stacks = 20, axis = vizshape.AXIS_Y)
		pointPhys = point.collideSphere()   # Define ball's physical properties 		
		point.setEuler(0,90,0)
		point.setPosition(0,parameters.point_height,0)
		point.color(viz.RED)	
		point.visible(False)
		point.enable( viz.COLLIDE_NOTIFY )

		#wind force
		thrust = point.addThruster(force=[0,0,0]) 
		
		#goal
		goal = vizshape.addCircle(slices=100, radius=0.2)
		goal.setEuler(0,90,0)
		goal.color(viz.GREEN)
		goal.visible(False)
		goal.setScale(parameters.goal_scale2D,parameters.goal_scale2D,parameters.goal_scale2D)
		
		#arrow
		arrow = vizshape.addArrow()
		viz.mouse(viz.OFF)
		arrow.setPosition(0,parameters.arrow_height2D,0)
		arrow.color(viz.BLUE)
		arrow.visible(False)
    'Undefined'
]

gestureText = viz.addText('', viz.SCREEN)
gestureText.setPosition(0.5, 0.1)
gestureText.alignment(viz.ALIGN_CENTER)

########## ADDITIONAL STUFF ###############
hand = viz.add('white_ball.wrl')  # Add the object that will do the grabbing

# Link the hand to a 3D mousetracker
mouseTracker = viztracker.MouseTracker()
mouseTracker.scroll(-8)
viz.link(mouseTracker, hand)

viz.mouse(viz.OFF)  # Disable mouse navigation

# Link the hand to a 3D mousetracker
mouseTracker = viztracker.MouseTracker()
mouseTracker.scroll(-8)
viz.link(mouseTracker, hand)

viz.mouse(viz.OFF)  # Disable mouse navigation

# Add a box model and set its position
basketball = viz.addChild('basketball.osgb')
basketball.setPosition([0, 1, 1.5])

link = None

    def use_control(self, control_style):
        """
        Enable the control modality depending on the provided input modality.

        Different experimental setup make use of different ways to exert control over the experimental world.
        Use this function to define and setup the necessary things depending on the control modality to be used.

        Args:
            control_style: interaction possibilities between subject and VR world. Currently supports:
            'mouse and keyboard', 'joystick', 'wiimote with dk2 head', 'dk2 head only', 'dk2 head hands'

        """

        # control type for test purposes
        if control_style == 'mouse and keyboard': # control type for test purposes

            viz.mouse(viz.ON)
            vizact.onmousedown(viz.MOUSEBUTTON_LEFT, self.on_button_press, 'A')
            vizact.onmousedown(viz.MOUSEBUTTON_RIGHT, self.on_button_press, 'B')

            self.sphere_radius = 0.02
            self.right_hand_sphere = vizshape.addSphere(radius=self.sphere_radius)
            self.right_hand_sphere.color(viz.GREEN)
            self.right_hand_target = self.right_hand_sphere.collideSphere()
            self.right_hand_sphere.disable(viz.DYNAMICS)

            self.right_hand_sphere.alpha(1)

            self.head_sphere = vizshape.addSphere(radius=self.sphere_radius)
            self.head_sphere.color(viz.YELLOW)
            self.head_target = self.head_sphere.collideSphere()
            self.head_sphere.disable(viz.DYNAMICS)

            MOVE_SPEED = 0.025

            def move_hand():
                if viz.key.isDown(viz.KEY_UP):
                    self.right_hand_sphere.setPosition([self.right_hand_sphere.getPosition()[0], 1.6, self.right_hand_sphere.getPosition()[2]+MOVE_SPEED])
                elif viz.key.isDown(viz.KEY_DOWN):
                    self.right_hand_sphere.setPosition([self.right_hand_sphere.getPosition()[0], 1.6, self.right_hand_sphere.getPosition()[2]-MOVE_SPEED])
                elif viz.key.isDown(viz.KEY_LEFT):
                    self.right_hand_sphere.setPosition(self.right_hand_sphere.getPosition()[0]-MOVE_SPEED, 1.6, self.right_hand_sphere.getPosition()[2])
                elif viz.key.isDown(viz.KEY_RIGHT):
                    self.right_hand_sphere.setPosition(self.right_hand_sphere.getPosition()[0]+MOVE_SPEED, 1.6, self.right_hand_sphere.getPosition()[2])

            def move_head():
                if viz.key.isDown('w'):
                    self.head_sphere.setPosition([self.head_sphere.getPosition()[0], 1.6, self.head_sphere.getPosition()[2]+MOVE_SPEED])
                elif viz.key.isDown('s'):
                    self.head_sphere.setPosition([self.head_sphere.getPosition()[0], 1.6, self.head_sphere.getPosition()[2]-MOVE_SPEED])
                elif viz.key.isDown('a'):
                    self.head_sphere.setPosition(self.head_sphere.getPosition()[0]-MOVE_SPEED, 1.6, self.head_sphere.getPosition()[2])
                elif viz.key.isDown('d'):
                    self.head_sphere.setPosition(self.head_sphere.getPosition()[0]+MOVE_SPEED, 1.6, self.head_sphere.getPosition()[2])

            vizact.ontimer(0, move_hand)
            vizact.ontimer(0, move_head)

        elif control_style == 'joystick':

            # first load the oculus rift plugin and link sensor to viewpoint
            import oculus
            hmd = oculus.Rift()

            # loads the DirectInput plug-in and adds first available joystick
            dinput = viz.add('DirectInput.dle')
            self.joy = dinput.addJoystick()

            # Set dead zone threshold so small movements of joystick are ignored
            self.joy.setDeadZone(0.2)

            # add viewpoint at subject height
            eye_height = float(self._height) - 0.05

            joystick_node = viz.addGroup(pos=(0, eye_height, 0))
            viz.link(joystick_node, viz.MainView)

            # joystick control class with lsl streams of pos and ori as in the dk2 tracker class
            # stream pos and ori in joystick movement function which gets called with ontimer / onupdate
            # set lsl stream parameters
            lsl_streamName = 'vizard_hmd6dof_stateLog_joystick'
            lsl_streamType = 'sixFloat'  # no official lsl type (not recognized by eeglab or mobilab)
            lsl_numChannels = 6
            lsl_regularSPS = 75  # regular rate, one sample per DK2 frame
            lsl_dataType = 'float32'
            lsl_streamUuid = socket.gethostname()  # PC name as uuid

            # create stream
            lsl_hmd6dofStreamInfo = StreamInfo(lsl_streamName, lsl_streamType, lsl_numChannels, lsl_regularSPS,
                                                    lsl_dataType, lsl_streamUuid)
            lsl_hmd6dofStreamInfo.desc().append_child('synchronization').append_child_value('can_drop_samples',
                                                                                                 'true')
            lsl_hmd6dofOutlet = StreamOutlet(lsl_hmd6dofStreamInfo)

            viz.callback(viz.SENSOR_DOWN_EVENT, self.on_button_press)
            vizact.onupdate(0, self.update_joystick_movement, self.joy, joystick_node, 5, 90, lsl_hmd6dofOutlet)

        else:
            self.start_dk2_head_tracker(control_style)