示例#1
0
def addRayPrimitive(origin, direction, length=100, color=viz.RED, 
                    alpha=0.6, linewidth=3, parent=None):
    """ Create a Vizard ray primitive from two vertices. Can be used
    to e.g. indicate a raycast or gaze vector in a VR environment.
    
    Args:
        origin (3-tuple): Ray origin
        direction (3-tuple): Unit direction vector
        length (float): Ray length (set to 1 and use direction=<end>
            to draw point-to-point ray)
        color (3-tuple): Ray color
        alpha (float): Ray alpha value
        linewidth (int): OpenGL line drawing width in pixels
        parent: Vizard node to use as parent
    """
    viz.startLayer(viz.LINES)
    viz.lineWidth(linewidth)
    viz.vertexColor(color)
    viz.vertex(origin)
    viz.vertex([x * length for x in direction])
    ray = viz.endLayer()
    ray.disable([viz.INTERSECTION, viz.SHADOW_CASTING])
    ray.alpha(alpha)
    if parent is not None:
        ray.setParent(parent)
    return ray
示例#2
0
 def getViewXYZ(self, dist="far", reFrame=viz.ABS_GLOBAL):
     
     # temporarily add vertex to track parcel pos in abs coords
     viz.startLayer(viz.POINTS)
     viz.vertexColor(1,0,0)
     viz.pointSize(30)
     viz.vertex(0,0,0)
     cV = viz.endLayer()
     cV.setParent(self.bNodeOp)
             
     if dist == "far":
         cV.setPosition(self.viewLocFar, mode=viz.ABS_LOCAL)
         zoneXYZ = cV.getPosition(mode=reFrame)
     elif dist == "near":
         cV.setPosition(self.viewLocNear, mode=viz.ABS_LOCAL)
         zoneXYZ = cV.getPosition(mode=reFrame)
     elif dist == 'center':
         zoneXYZ = self.bNodeOp.getPosition(mode=reFrame)
         
     cV.visible(viz.OFF)        
     cV.remove()
     
     # set y to eye height
     zoneXYZ[1] = ct.EYE_HEIGHT
     
     return zoneXYZ
    def generateLayer(self, terrainData):
        viz.startLayer(viz.TRIANGLES)
        for r in range(0, len(terrainData) - 1):
            for c in range(0, len(terrainData) - 1):
                # each array location generates two triangles

                viz.vertexColor(0.545, .2, 0.074)
                # corners of first triangle, in ccw order when looking down on the surface
                c1 = [c, terrainData[r][c], r]
                c2 = [c + 1, terrainData[r + 1][c + 1], r + 1]
                c3 = [c, terrainData[r + 1][c], r + 1]

                viz.normal(self.normal(c1, c2, c3))
                viz.vertex(c1)
                viz.vertex(c2)
                viz.vertex(c3)

                viz.vertexColor(0.545, .2, 0.074)
                # corners of second triangle, in ccw order when looking down on the surface
                c1 = [c, terrainData[r][c], r]
                c2 = [c + 1, terrainData[r][c + 1], r]
                c3 = [c + 1, terrainData[r + 1][c + 1], r + 1]

                viz.normal(self.normal(c1, c2, c3))
                viz.vertex(c1)
                viz.vertex(c2)
                viz.vertex(c3)

        return viz.endLayer()
示例#4
0
	def __init__(self, row, col):
		# Length of each block
		self.length = 20
		
		# Instance variables
		self.x = (row * self.length) - 100
		self.y = 100 - (col * self.length)
		self.row = col
		self.col = row
		
		viz.startLayer(viz.POLYGON)
		
		# Assign vertices a random color
		viz.vertexColor(random.uniform(.2, 1),random.uniform(.2, 1), random.uniform(.2, 1))
		
		# Define vertices
		viz.vertex(0, 0)
		viz.vertex(self.length, 0)
		viz.vertex(self.length, -self.length)
		viz.vertex(0, -self.length)
		
		# Capture layer and set its transformation matrix
		self.vertices = viz.endLayer()
		m = viz.Matrix()
		m.postTrans(self.x, self.y)
		self.vertices.setMatrix(m)
示例#5
0
def GenerateStarDome(numStars, pointSize, minRadius, maxRadius, scene=1, yCenter=0):
 #Create a star dome of random points
 viz.startLayer(viz.POINTS)
 viz.pointSize(pointSize)
 for i in range(0, numStars):
  x = random() - 0.5
  y = random() - 0.5
  z = random() - 0.5
  length = math.sqrt(x*x + y*y + z*z)
  rad = vizmat.GetRandom(minRadius,maxRadius)
  x = x / length * rad
  y = y / length * rad
  y += yCenter
  z = z / length * rad
  color = vizmat.GetRandom(0.4,1)
  viz.vertexColor([color,color,color-vizmat.GetRandom(0,0.2)])
  viz.vertex([x, y, z])

 stardome = viz.endLayer()
 stardome.setParent(viz.WORLD, scene=scene)
 stardome.texture( viz.addTexture('particle.rgb') )
 stardome.blendFunc(viz.GL_SRC_ALPHA,viz.GL_DST_ALPHA)
 stardome.enable(viz.POINT_SPRITE)
 stardome.disable(viz.DEPTH_TEST)
 stardome.draworder(-100000)
def make_kinect_mesh(depthMap):
	#Build cube
	RADIUS = 1
	
	depthArray = depthMap.get_array()
	
	viz.startLayer(viz.QUADS)
	
	for y in range(0,depthMap.height-1,DOWNSAMPLE):
		for x in range(0,depthMap.width-1,DOWNSAMPLE):
			
			depth_val = depthMap[x,y]/(4*1000.0);

			viz.vertex([x*1.0/depthMap.width, 1 - y*1.0/depthMap.height, depth_val])
			viz.vertex([x*1.0/depthMap.width, 1 - (y+DOWNSAMPLE)*1.0/depthMap.height, depth_val])
			viz.vertex([(x+DOWNSAMPLE)*1.0/depthMap.width, 1 - (y+DOWNSAMPLE)*1.0/depthMap.height, depth_val])
			viz.vertex([(x+DOWNSAMPLE)*1.0/depthMap.width, 1 - (y)*1.0/depthMap.height, depth_val])
			
			pixel_colour = 1 - depthMap[x,y]/(1000.0 * 3.0)
			viz.vertexColor([ pixel_colour, 1, 1, MESH_VISIBLE ])

	kinect_mesh = viz.endLayer()
	kinect_mesh.setPosition([0,0.5,3])
	
	return kinect_mesh
示例#7
0
def addCircle(r, color):
    viz.startLayer(viz.POLYGON)
    viz.vertexColor(color)
    for angle in range(0, 360, 10):
        viz.vertex(r * math.cos(math.radians(angle)),
                   r * math.sin(math.radians(angle)))
    return viz.endLayer()
示例#8
0
	def __init__(self, angle):
		
		# Initialize Ball Instance Variables
		# radius 
		self.radius = 3
		# number of sides of regular polygon representing the ball
		self.sides = 50
		# velocity vector describing its direction and speed
		self.angle = angle

		self.vy = math.sin(math.radians(angle)) * 2
		self.vx = math.cos(math.radians(angle)) * 2

		# center location 
		self.x = 0
		self.y = 0
		
		# create layer for a circle, centered at (0,0)
		viz.startLayer(viz.POLYGON)
		viz.vertexColor(1,1,0)
		for i in range(0, 360, 360/self.sides):
			x = math.cos( math.radians(i) ) * self.radius
			y = math.sin( math.radians(i) ) * self.radius
			viz.vertex(x, y)
		# saves layer of vertices in instance variable called vertices
		self.vertices = viz.endLayer()
示例#9
0
        def motion():
            # Create Fixation Dot
            viz.startLayer(viz.POINTS)
            viz.pointSize(self.POINTSIZE)
            viz.vertexColor(viz.GRAY)
            viz.vertex(0, 1.8, 4)
            points = viz.endLayer()
            points.disable(viz.CULLING)
            # Create the circles
            sphere = self.createCircles(26, 1, 30, -26)
            sphere2 = self.createCircles(22, 0.8, 30, -26)
            sphere3 = self.createCircles(18, 0.6, 30, -26)
            sphere4 = self.createCircles(14, 0.4, 30, -26)
            sphere5 = self.createCircles(10, 0.2, 30, -26)
            viz.MainView.move([0, 0, 3])

            def keydown(key):

                if key == 'f':
                    self.response = 'self motion'
                    self.keyPressTime = viz.tick()  # get time for keypress
                    print(self.response, self.keyPressTime)
                    self.STATE = 'State - self Motion'

                if key == 'j':
                    self.response = 'object motion'
                    self.keyPressTime = viz.tick()  # get time for keypress
                    print(self.response, self.keyPressTime)
                    self.STATE = 'State - Object Motion'

            viz.callback(viz.KEYDOWN_EVENT, keydown)
示例#10
0
def room_line(high, wide, dep, pixel):
    room = viz.addGroup()

    pos = np.array([[[wide / 2, 0, 0], [wide / 2, high, 0]],
                    [[-wide / 2, 0, 0], [-wide / 2, high, 0]],
                    [[wide / 2, 0, 0], [-wide / 2, 0, 0]],
                    [[wide / 2, high, 0], [-wide / 2, high, 0]],
                    [[wide / 2, 0, -dep], [wide / 2, high, -dep]],
                    [[-wide / 2, 0, -dep], [-wide / 2, high, -dep]],
                    [[wide / 2, 0, -dep], [-wide / 2, 0, -dep]],
                    [[wide / 2, high, -dep], [-wide / 2, high, -dep]],
                    [[wide / 2, 0, 0], [wide / 2, 0, -dep]],
                    [[wide / 2, high, 0], [wide / 2, high, -dep]],
                    [[-wide / 2, 0, 0], [-wide / 2, 0, -dep]],
                    [[-wide / 2, high, 0], [-wide / 2, high, -dep]]])

    for i in range(12):
        viz.startLayer(viz.LINES)
        viz.lineWidth(pixel)
        viz.vertexColor(1, 0, 0)
        viz.vertex(pos[i, 0, :].tolist())
        viz.vertex(pos[i, 1, :].tolist())
        outline = viz.endLayer()
        outline.setParent(room)

    return room
示例#11
0
 def addCoordinateAxes(self):
     viz.startLayer(viz.LINES)
     viz.linewidth(7)
     viz.vertexColor(viz.RED)
     # positive y axis
     viz.vertex(0, 0, 0)
     viz.vertex(0, 20, 0)
     #positive x axis
     viz.vertex(0, 0, 0)
     viz.vertex(20, 0, 0)
     #positive z axis
     viz.vertex(0, 0, 0)
     viz.vertex(0, 0, 20)
     #y=1 tick mark
     viz.vertex(-0.25, 1, 0)
     viz.vertex(0.25, 1, 0)
     #y=2 tick mark
     viz.vertex(-0.25, 2, 0)
     viz.vertex(0.25, 2, 0)
     #x=1 tick mark
     viz.vertex(1, 0, -.25)
     viz.vertex(1, 0, .25)
     #x=2 tick mark
     viz.vertex(2, 0, -.25)
     viz.vertex(2, 0, +.25)
     #z=1 tick mark
     viz.vertex(-.25, 0, 1)
     viz.vertex(.25, 0, 1)
     #z=2 tick mark
     viz.vertex(-.25, 0, 2)
     viz.vertex(.25, 0, 2)
     viz.endLayer()
示例#12
0
    def generate_surface(self, data, color_array_name):
        """
		Render the vtk data as a surface, centered at origin and return the Vizard object.
		color_array_name defines the name of the CellData array (for example: "equivalent_stress" or "material")
		"""
        # Start creating the model
        viz.startLayer(viz.TRIANGLES)
        # Use the range of the complete data set to ensure consitency
        minimum, maximum = self.vtk_data_local.GetCellData().GetArray(
            color_array_name).GetRange()

        # Generate surface model by iterating over every polygon
        polys = data.GetPolys()
        polys.InitTraversal()
        id_list = vtk.vtkIdList()
        cell = polys.GetNextCell(id_list)
        while not cell == 0:
            # Get the value of the cell for color calculation
            value = data.GetCellData().GetArray(color_array_name).GetValue(
                polys.GetTraversalLocation() / 4)
            color = Simulation_Data._get_color(minimum, maximum, value)
            viz.vertexColor(color[0], color[1], color[2])

            # Read the points (po) of the polygon
            po = []
            for j in range(id_list.GetNumberOfIds()):
                po.append(data.GetPoints().GetPoint(id_list.GetId(j)))

            # Calculate the normal vector of the polygon
            # Normal vector is needed for better lighting
            # Calculate the coss product of vectors from point 0 to 1 and 0 to 2
            ab = (po[1][0] - po[0][0], po[1][1] - po[0][1],
                  po[1][2] - po[0][2])
            ac = (po[2][0] - po[0][0], po[2][1] - po[0][1],
                  po[2][2] - po[0][2])
            normal = numpy.cross(ab, ac)
            # Set the magnitude of the normal vector to 1
            normal = normal / numpy.linalg.norm(normal)
            # Create the polygon with the normal vector and the points
            viz.normal(normal[0], normal[1], normal[2])
            for position in po:
                viz.vertex(position[0], position[1], position[2])
            cell = polys.GetNextCell(id_list)

        # Finish the model
        model = viz.endLayer()
        # Enable lighting for the model (Shadows aren't needed)
        model.enable(viz.LIGHTING)
        model.disable(viz.SHADOW_CASTING)
        model.disable(viz.SHADOWS)
        # Set the center of the model to (0, 0, 0)
        model.setPosition(-(self._original_center[0]),
                          -(self._original_center[1]),
                          -(self._original_center[2]))
        # Create group to get a centered model with coordinates (0, 0, 0)
        group = viz.addGroup()
        model.setParent(group)
        return group
示例#13
0
 def getCornerCoords(cNode, quSpace):
 
     nBox = cNode.getBoundingBox(viz.ABS_LOCAL)
     
     cCrns      = [ (nBox.xmin, 0, nBox.zmin), (nBox.xmin, 0, nBox.zmax), (nBox.xmax, 0, nBox.zmax), (nBox.xmax, 0, nBox.zmin) ]
     globalCrns = []
     singleVertChildren = []
     
     for c in cNode.getChildren():
         if c.__class__ == viz.VizPrimitive:
             singleVertChildren.append( c )
     
     #print "nChildren: ", singleVertChildren
     i = 0
     for cC in cCrns:
         
         # add helper vertices if this node does not contain
         # four children -> heuristic
         if not len(singleVertChildren) == 4:
             # create vertex
             viz.startLayer(viz.POINTS)
             viz.vertexColor(1,0,0)
             viz.pointSize(30)
             viz.vertex(0,0,0)
             cV = viz.endLayer()
             
             # set obst as parent
             cV.setParent(cNode)
             
             # move to parent's corner
             x,y,z = cC
             cV.setPosition(x, y, z, viz.ABS_PARENT)
             
         else:
             cV = singleVertChildren[i]
                                    
         # set obst as parent
         cV.setParent(cNode)
         
         # move to parent's corner
         x,y,z = cC
         cV.setPosition(x, y, z, viz.ABS_PARENT)
         
         # get global coords
         x,y,z = cV.getPosition(viz.ABS_GLOBAL)
         
         # flip z axis to get from world to pedSim space
         if quSpace == 'ped':
             z=-z
             
         globalCrns.append( (x,y,z) )
                         
         # remove this vertex
         #cV.remove()
         
         i = i+1
         
     return globalCrns
 def drawContextBorders(bbCtx):
     crns = bbCtx.getCorners('world')
     viz.startLayer(viz.LINE_STRIP)
     viz.lineWidth(10)
     viz.vertexColor(1,0,0)
     
     for c in crns:
         viz.vertex(c[0], 1, c[1])            
     viz.endLayer()
示例#15
0
    def __init__(self):
        # must call constructor of EventClass first!!
        viz.EventClass.__init__(self)
        self.x = 20
        self.z = 20
        self.y = 0
        self.theta = 0
        self.angl = 0
        self.callback(viz.KEYDOWN_EVENT, self.onKeyDown)
        self.avatar = viz.add('vcc_female.cfg')
        self.avatar.disable(viz.INTERSECTION)

        print "Reading file greysriver.asc..."
        f = open('greysriver.asc', 'r')
        # first two lines are number of cols and rows
        cols = int(str.split(f.readline())[1])
        rows = int(str.split(f.readline())[1])

        # discard next 4 lines in file
        f.readline(), f.readline(), f.readline(), f.readline()

        # create 2D array of empty lists, one empty list for each row of data
        self.elevation = [[] for x in range(0, rows)]
        maxElevation = -50000
        minElevation = 50000
        # read in elevation data and keep track of max and min elevations
        for r in range(0, rows):
            for n in str.split(f.readline()):
                self.elevation[r].append(float(n))
                if (float(n) > maxElevation):
                    maxElevation = float(n)
                if (float(n) < minElevation):
                    minElevation = float(n)

        # create triangle mesh
        viz.startLayer(viz.TRIANGLES)
        for r in range(rows - 1):
            for c in range(cols - 1):
                # create first triangle
                color = self.getColor(self.elevation[r][c], maxElevation,
                                      minElevation)
                viz.vertexColor(color)
                viz.vertex(c, self.elevation[r][c], r)
                viz.vertex(c + 1, self.elevation[r + 1][c + 1], r + 1)
                viz.vertex(c, self.elevation[r + 1][c], r + 1)

                # create second triangle
                color = self.getColor(self.elevation[r][c + 1], maxElevation,
                                      minElevation)
                viz.vertexColor(color)
                viz.vertex(c, self.elevation[r][c], r)
                viz.vertex(c + 1, self.elevation[r][c + 1], r)
                viz.vertex(c + 1, self.elevation[r + 1][c + 1], r + 1)
        self.t = viz.endLayer()
        self.y = self.elevation[20][20] + 1
        self.transform()
示例#16
0
 def __init__(self, x, y):
     self.x = x
     self.y = y
     viz.startLayer(viz.QUADS)
     viz.vertexColor(1, 0, 1)
     viz.vertex(-1, -2)
     viz.vertex(-1, 2)
     viz.vertex(1, 2)
     viz.vertex(1, -2)
     self.vertices = viz.endLayer()
示例#17
0
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y

        viz.startLayer(viz.QUADS)
        #bullet
        viz.vertexColor(1, 1, 1)
        viz.vertex(.5, 0, 0)
        viz.vertex(-.5, 0, 0)
        viz.vertex(-.5, 2.9, 0)
        viz.vertex(.5, 2.9, 0)
        self.quad = viz.endLayer()
示例#18
0
    def __init__(self, x, y):
        self.x = x
        self.y = y

        viz.startLayer(viz.QUADS)
        viz.vertexColor(0, 0, 0)
        viz.pointSize(100)
        viz.vertex(-1, 0)
        viz.vertex(+1, 0)
        viz.vertex(+1, 2)
        viz.vertex(-1, 2)
        viz.endLayer()
示例#19
0
	def __init__(self, x, y):
		height = 10
		width = 10
		self.x = 0
		self.y = 0
		viz.startLayer(viz.QUADS)
		viz.vertexColor(1,1,0)
		viz.pointSize(1)
		viz.vertex(-5,10)
		viz.vertex(5,10)
		viz.vertex(5,-10)
		viz.vertex(-5,-10)
		viz.endLayer()
示例#20
0
    def __init__(self, x, y):
        self.x = x
        self.y = y
        viz.startLayer(viz.QUADS)

        #eye
        viz.vertexColor(1, 0, 0)
        viz.vertex(-5, 0)
        viz.vertex(0, 3)
        viz.vertex(5, 0)
        viz.vertex(0, -3)

        #body
        viz.vertexColor(0, 0.5, 0.5)
        viz.vertex(-10, -10)
        viz.vertex(-6, 6.2)
        viz.vertex(6, 6.2)
        viz.vertex(10, -10)

        #left ear
        viz.vertexColor(1, 0, 0)
        viz.vertex(-5.8, 6)
        viz.vertex(-5.8, 10)
        viz.vertex(-1.9, 10)
        viz.vertex(-1.9, 6)

        #right ear
        viz.vertexColor(1, 0, 0)
        viz.vertex(6, 6)
        viz.vertex(6, 10)
        viz.vertex(2, 10)
        viz.vertex(2, 6)
        self.vertices = viz.endLayer()
示例#21
0
    def __init__(self, radius, x, y):
        self.radius = radius
        self.x = x
        self.y = y

        viz.startLayer(viz.POLYGON)
        viz.vertexColor(1, 1, 1)

        for i in range(0, 360):
            temp = i * math.pi / 180
            viz.vertex(
                math.cos(temp) * self.radius,
                math.sin(temp) * self.radius)

        viz.endLayer()
示例#22
0
def wireframeCube(dimensions):
	"""
	Draw a wireframe rectangle. Currently comes in green only.
	"""
	edges = [[x,y,z] for x in [-1,0,1] for y in [-1,0,1] for z in [-1,0,1] if abs(x)+abs(y)+abs(z) == 2]
	for edge in edges:
		viz.startLayer(viz.LINES)
		viz.vertexColor(0,1,0)
		i = edge.index(0)
		edge[i] = 1
		viz.vertex(map(lambda a,b:a*b,edge,dimensions))
		edge[i] = -1
		viz.vertex(map(lambda a,b:a*b,edge,dimensions))
	cube = viz.endLayer()
	return cube
示例#23
0
    def generate_cloud(self, data, color_array_name):
        """
		Render the vtk data as a cloud, centered at origin and return the Vizard object.
		color_array_name defines the name of the CellData array (for example: "equivalent_stress" or "material")
		"""
        # Start creating the model
        viz.startLayer(viz.POINTS)
        viz.pointSize(self.cloud_point_size)
        # Use the range of the complete data set to ensure consitency
        minimum, maximum = self.vtk_data_local.GetCellData().GetArray(
            color_array_name).GetRange()

        # Generate cloud model by iterating over every cell
        num_of_cells = data.GetNumberOfCells()
        for i in range(num_of_cells):
            cell = data.GetCell(i)

            # Calculate the center of the cell
            x = 0.0
            y = 0.0
            z = 0.0
            num_of_points = cell.GetNumberOfPoints()
            for j in range(num_of_points):
                point = cell.GetPoints().GetPoint(j)
                x += point[0]
                y += point[1]
                z += point[2]
            x /= num_of_points
            y /= num_of_points
            z /= num_of_points

            # Get the value of the cell for color calculation
            value = data.GetCellData().GetArray(color_array_name).GetValue(i)
            color = Simulation_Data._get_color(minimum, maximum, value)
            viz.vertexColor(color[0], color[1], color[2])
            # Draw the point
            viz.vertex(x, y, z)

        # Finish the model
        model = viz.endLayer()
        # Set the center of the model to (0, 0, 0)
        model.setPosition(-(self._original_center[0]),
                          -(self._original_center[1]),
                          -(self._original_center[2]))
        # Create group to get a centered model with coordinates (0, 0, 0)
        group = viz.addGroup()
        model.setParent(group)
        return group
示例#24
0
def wireframeCube(dimensions):
    """
	Draw a wireframe rectangle. Currently comes in green only.
	"""
    edges = [[x, y, z] for x in [-1, 0, 1] for y in [-1, 0, 1]
             for z in [-1, 0, 1] if abs(x) + abs(y) + abs(z) == 2]
    for edge in edges:
        viz.startLayer(viz.LINES)
        viz.vertexColor(0, 1, 0)
        i = edge.index(0)
        edge[i] = 1
        viz.vertex(map(lambda a, b: a * b, edge, dimensions))
        edge[i] = -1
        viz.vertex(map(lambda a, b: a * b, edge, dimensions))
    cube = viz.endLayer()
    return cube
示例#25
0
    def createCircles(self, NUM_DOTS, RADIUS, POINTSIZE, VELOCITYDIRECTION):

        #Build sphere
        viz.startLayer(viz.POINTS)
        viz.vertexColor(viz.WHITE)
        viz.pointSize(self.POINTSIZE)

        for i in range(0, NUM_DOTS):
            x = RADIUS * math.cos((i * 2 * math.pi) / NUM_DOTS)
            y = RADIUS * math.sin((i * 2 * math.pi) / NUM_DOTS)
            viz.vertex([x, y, 0])

        sphere = viz.endLayer()
        sphere.setPosition([0, 1.8, 4])
        sphere.addAction(vizact.spin(0, 0, 1, VELOCITYDIRECTION))
        return sphere
示例#26
0
    def __init__(self, length, colors, x, y):
        self.length = length
        self.colors = colors
        self.x = x
        self.y = y

        viz.startLayer(viz.POLYGON)

        viz.vertexColor(colors[0], colors[1], colors[2])
        viz.pointSize(1)

        viz.vertex(0, 0)
        viz.vertex(length, 0)
        viz.vertex(length, length)

        viz.vertex(0, length)

        viz.endLayer()
示例#27
0
	def __init__(self, dimensions, center = [0,0,0], corner = False):
		edges = [[x,y,z] for x in [-1,0,1] for y in [-1,0,1] for z in [-1,0,1] if abs(x)+abs(y)+abs(z) == 2]
		for edge in edges:
			viz.startLayer(viz.LINES)
			viz.vertexColor(0,1,0)
			i = edge.index(0)
			edge[i] = 1
			viz.vertex(map(lambda a,b:a*b/2, edge, dimensions))
			edge[i] = -1
			viz.vertex(map(lambda a,b:a*b/2, edge, dimensions))
		self.cube = viz.endLayer()
		if corner:
			corner = [float(p[0])/2 + p[1] for p in zip(dimensions,center)]
			self.cube.setPosition(corner, viz.ABS_GLOBAL)
		else:
			self.cube.setPosition(center, viz.ABS_GLOBAL)
			
		super(WireFrameCube, self).__init__(self.cube.id)
示例#28
0
def setStage():

    global groundplane, groundtexture

    #	###should set this hope so it builds new tiles if you are reaching the boundary.
    #	fName = 'textures\strong_edge.bmp'
    #
    #	# add groundplane (wrap mode)
    #	groundtexture = viz.addTexture(fName)
    #	groundtexture.wrap(viz.WRAP_T, viz.REPEAT)
    #	groundtexture.wrap(viz.WRAP_S, viz.REPEAT)
    #
    #	groundplane = viz.addTexQuad() ##ground for right bends (tight)
    #	tilesize = 5000#300 #F***ING MASSIVE
    #	planesize = tilesize/5
    #	groundplane.setScale(tilesize, tilesize, tilesize)
    #	groundplane.setEuler((0, 90, 0),viz.REL_LOCAL)
    #	#groundplane.setPosition((0,0,1000),viz.REL_LOCAL) #move forward 1km so don't need to render as much.
    #	matrix = vizmat.Transform()
    #	matrix.setScale( planesize, planesize, planesize )
    #	groundplane.texmat( matrix )
    #	groundplane.texture(groundtexture)
    #	groundplane.visible(1)

    gsize = [1000, 1000]  #groundplane size, metres
    groundplane = vizshape.addPlane(size=(gsize[0], gsize[1]),
                                    axis=vizshape.AXIS_Y,
                                    cullFace=True)  ##make groundplane
    groundplane.texture(viz.add('black.bmp'))  #make groundplane black

    #Build dot plane to cover black groundplane
    ndots = 200000  #arbitrarily picked. perhaps we could match dot density to K & W, 2013?
    viz.startlayer(viz.POINTS)
    viz.vertexColor(viz.WHITE)
    viz.pointSize(2)
    for i in range(0, ndots):
        x = (random.random() - .5) * gsize[0]
        z = (random.random() - .5) * gsize[1]
        viz.vertex([x, 0, z])

    dots = viz.endLayer()
    dots.setPosition(0, 0, 0)
    dots.visible(1)
    groundplane.visible(1)
def CreateVisualObjects():

    global ball, Head, Hand, GazeLine, EyeBallLine;
    #creats a sphere(the ball) with radius of 5cm
    ball = vizshape.addSphere(radius = .05)
    #colors the ball red
    ball.color(viz.YELLOW)
    ball.visible(True)

    Origin = vizshape.addAxes()
    Origin.setPosition(0,0,0)
    #creats a sphere(the ball) with radius of 5cm
    #Head = vizshape.addCone( radius = 0.5, height = 0.8)
    Head = vizshape.addArrow(1, color = viz.YELLOW_ORANGE)
    #colors the ball red
    Head.color(viz.PURPLE)
    Head.visible(True)
    Head.setScale(.2,.2,.3)

    #creats a sphere(the hand) with radius of 10cm
    Hand = vizshape.addCylinder( height = 0.02, radius = 0.2)
    #colors the hand red
    Hand.color(viz.RED)
    Hand.visible(True)

    # Creating a Line to represent Gaze Vector
    viz.startLayer(viz.LINES)
    viz.vertex(0,0,0)
    viz.vertex(0,0,3)
    viz.vertexColor(viz.GREEN)
    GazeLine = viz.endLayer() # Object will contain both points and lines
    GazeLine.visible(True)
    GazeLine.setScale(5,5,5)


    # Creating a Line to represent Eye-Ball Vector
    viz.startLayer(viz.LINES)
    viz.vertex(0,0,0)
    viz.vertex(0,0,3)
    viz.vertexColor(viz.YELLOW)
    EyeBallLine = viz.endLayer() # Object will contain both points and lines
    EyeBallLine.visible(True)
    EyeBallLine.setScale(5,5,5)
示例#30
0
	def __init__(self, eyeTracker, eye, parentNode, renderToWindows = None,gazeVectorColor=viz.RED):
		
		self.eye = eye
		self.eyeTracker = eyeTracker
		self.renderToWindows = renderToWindows
		
		#Creating a line
		viz.startLayer(viz.LINES)
		viz.lineWidth(4)#Set the size of the lines. 
		viz.vertex(0,0,0)
		viz.vertex(0,0,3)
		viz.vertexColor(gazeVectorColor)
		self.gazeLine = viz.endLayer()
		self.gazeLine.visible(True)
		#self.gazeLine.setScale(1,1,1)

		if( self.renderToWindows ):
			self.gazeLine.renderOnlyToWindows(self.renderToWindows)
		self.gazeLine.setParent(parentNode)
示例#31
0
	def __init__(self, eyeTracker, eye, parentNode, renderToWindows = None,gazeVectorColor=viz.RED):
		
		self.eye = eye
		self.eyeTracker = eyeTracker
		self.renderToWindows = renderToWindows
		
		#Creating a line
		viz.startLayer(viz.LINES)
		viz.lineWidth(4)#Set the size of the lines. 
		viz.vertex(0,0,0)
		viz.vertex(0,0,3)
		viz.vertexColor(gazeVectorColor)
		self.gazeLine = viz.endLayer()
		self.gazeLine.visible(True)
		#self.gazeLine.setScale(1,1,1)

		if( self.renderToWindows ):
			self.gazeLine.renderOnlyToWindows(self.renderToWindows)
		self.gazeLine.setParent(parentNode)
示例#32
0
    def __init__(self, bldList):
        
        self.info       = PointInfo()
        self.buildings  = bldList
        self.trials     = []        
        self.cTrial     = None
        self.trialCtr   = -1         
        self.trgAngle   = None
        self.hideBuildings()
        self.trialData  = {}

        # add vertex to measure true target angel
        viz.startLayer(viz.POINTS)
        viz.vertexColor(1,0,0)
        viz.pointSize(30)
        viz.vertex(0,0,0)
        self.refVert = viz.endLayer()
        self.refVert.disable(viz.RENDERING)


        # add grid to orient subject during
        # pointing
        viz.startLayer(viz.LINES)
        viz.lineWidth(6)
        viz.vertexColor(0,0.6,0)
        viz.vertex(-100, 0.01,  0)
        viz.vertex( 100, 0.01,  0)
        viz.vertex(  0, 0.01,-100)
        viz.vertex(  0, 0.01, 100)
        self.cross90 = viz.endLayer()         
        self.cross90.visible(viz.OFF)        

        self.grid = vizshape.addGrid(size=[200,200], step=10.0, boldStep=None)
        self.grid.color([0,.6,0])
        self.grid.visible(viz.OFF)

        # add logger
        self.fields2log = {'trialNr' : 'i8', 'srcBuilding' : 'S10', 'trgBuilding' : 'S10', 'refAngle' : 'f4', 'measAngle' : 'f4', 'trueAngle' : 'f4', 'trialOnset' : 'f8', 'tChoiceMade' : 'f8', 'srcXZ' : [('x', 'f4'), ('z', 'f4')], 'trgXZ' : [('x', 'f4'), ('z', 'f4')], 'srcCtxt' : 'S1', 'trgCtxt' :'S1'}
        self.logHdl     = lg.LogData(self.fields2log)

        # handle exit
        vizact.onexit( self.saveOnExit )
示例#33
0
    def __init__(self, angle, length):
        self.angle = angle
        self.length = length

        self.angle *= math.pi / 180

        self.x = math.cos(angle) * length
        self.y = math.sin(angle) * length

        print("({}, {})".format(self.x, self.y))

        viz.startLayer(viz.LINES)

        viz.vertexColor(1, 0, 0)
        viz.lineWidth(10)

        viz.vertex(0, 0)
        viz.vertex(self.x, self.y)

        viz.endLayer()
	def __init__(self,**kw):
		group = viz.addGroup(**kw)
		viz.VizNode.__init__(self,group.id)

		self._quad = vizshape.addQuad([1,1],parent=self)
		self._quad.color(viz.RED)
		self._quad.polyMode(viz.POLY_WIRE)

		viz.startLayer(viz.LINES)
		viz.vertexColor(viz.RED)
		for x in range(8):
			viz.vertex([0,0,0])
		self._lines = viz.endLayer(parent=self)
		self._lines.dynamic()

		self.zoffset(-2)
		self.lineWidth(2)
		self.disable(viz.LIGHTING)

		self._wall = None
		self._tracker = None

		vizact.onupdate(viz.PRIORITY_LAST_UPDATE,self.updateFrustum)
示例#35
0
    def set_cloud_point_size(self, point_size=1):
        """
		Sets the current size of the point cloud points.
		This function also updates the point cloud model.
		"""
        self.cloud_point_size = point_size
        # update the models of the different materials
        for key in self.cloud_materials.keys():
            old_model = self.cloud_materials[key].getChildren()[0]
            # Create new model
            viz.startLayer(viz.POINTS)
            viz.pointSize(point_size)
            # Copy the old model with new point_size
            for point_id in range(old_model.getVertexCount()):
                viz.vertexColor(old_model.getVertexColor(point_id))
                viz.vertex(old_model.getVertex(point_id))
            model = viz.endLayer()
            # Replace the old model with the new one
            model.setParent(self.cloud_materials[key])
            model.setPosition(old_model.getPosition())
            model.setScale(old_model.getScale())
            model.setEuler(old_model.getEuler())
            old_model.remove()
示例#36
0
	def __init__(self, angle, length):
		# Instance variables
		self.angle = angle
		self.changeInAngle = 0
		self.length = length
		
		self.x = 0
		self.y = -100
		
		viz.startLayer(viz.LINES)
		
		viz.vertexColor(1, 0, 0)
		viz.lineWidth(5)
		
		# Define vertices
		viz.vertex(0, 0)
		viz.vertex(math.cos(math.radians(self.angle)) * self.length, math.sin(math.radians(self.angle)) * self.length)
		
		# Capture layer and set its transformation matrix
		self.vertices = viz.endLayer()
		m = viz.Matrix()
		m.postTrans(self.x, self.y)
		self.vertices.setMatrix(m)
    def createVisualObjects(self):

        #creats a sphere(the ball) with radius of 5cm
        self.ball = vizshape.addSphere(radius = .05)
        #colors the ball red
        self.ball.color(viz.YELLOW)
        self.ball.visible(True)

        self.Origin = vizshape.addAxes()
        self.Origin.setPosition(-5.5,0.1,8)
    #    #creats a sphere(the ball) with radius of 5cm
    #    #Head = vizshape.addCone( radius = 0.5, height = 0.8)
    #    Head = vizshape.addArrow(1, color = viz.YELLOW_ORANGE)
    #    #colors the ball red
    #    Head.color(viz.PURPLE)
    #    Head.visible(True)
    #    Head.setScale(.2,.2,.3)

        #creats a sphere(the hand) with radius of 10cm
        self.Hand = vizshape.addCylinder( height = 0.02, radius = 0.2, axis = vizshape.AXIS_Z)
        #colors the hand red
        self.Hand.color(viz.RED)
        self.Hand.visible(True)

        self.IOD = 0.06
        
        # create a node3D leftEyeNode
        self.cyclopEyeNode = vizshape.addSphere(0.015, color = viz.GREEN)
        #cyclopEyeNode.visible(viz.OFF)
        self.cyclopEyeNode.setPosition(*self.rawDataStruct['view_Pos_XYZ'][:,0])
        self.cyclopEyeNode.setQuat(*self.rawDataStruct['view_Quat_WXYZ'][:,0])

        # create a node3D rightEyeNode
        self.rightEyeNode = vizshape.addSphere(0.015, color = viz.RED)
        #rightEyeNode.visible(viz.OFF)
        self.rightEyeNode.setParent(self.cyclopEyeNode)
        self.rightEyeNode.setPosition(self.IOD/2, 0, 0.0,viz.ABS_PARENT)
    #    right_sphere = gazeSphere(eyeTracker,viz.RIGHT_EYE,rightEyeNode,[clientWindowID],sphereColor=viz.ORANGE)
    #    rightGazeVector = gazeVector(eyeTracker,viz.RIGHT_EYE,rightEyeNode,[clientWindowID],gazeVectorColor=viz.ORANGE)
    #    right_sphere.toggleUpdate()
    #    rightGazeVector.toggleUpdate()
    #    right_sphere.node3D.alpha(0.7)    


        # create a node3D leftEyeNode
        self.leftEyeNode = vizshape.addSphere(0.015, color = viz.BLUE)
        #leftEyeNode.visible(viz.OFF)
        self.leftEyeNode.setParent(self.cyclopEyeNode)
        self.leftEyeNode.setPosition(-self.IOD/2, 0, 0.0,viz.ABS_PARENT)
    #    left_sphere = gazeSphere(eyeTracker,viz.LEFT_EYE,leftEyeNode,[clientWindowID],sphereColor=viz.YELLOW)
    #    leftGazeVector = gazeVector(eyeTracker,viz.LEFT_EYE,leftEyeNode,[clientWindowID],gazeVectorColor=viz.YELLOW)
    #    left_sphere.toggleUpdate()
    #    leftGazeVector.toggleUpdate()
    #    left_sphere.node3D.alpha(0.7)

        # Creating a Line to represent Gaze Vector
        viz.startLayer(viz.LINES)
        viz.vertex(0,0,0)
        viz.vertex(0,0,3)
        viz.vertexColor(viz.GREEN)
        self.eyeGazeVector = viz.endLayer() # Object will contain both points and lines
        self.eyeGazeVector.visible(True)
        self.eyeGazeVector.setParent(self.cyclopEyeNode)
        self.eyeGazeVector.pointSize(10)
        #rightGazeVector.setScale(5,5,5)
        self.eyeGazeSphere = vizshape.addSphere(0.02, color = viz.GREEN)
        self.eyeGazeSphere.setParent(self.cyclopEyeNode)


        # Creating a Line to represent Gaze Vector
        viz.startLayer(viz.LINES)
        viz.vertex(0,0,0)
        viz.vertex(0,0,3)
        viz.vertexColor(viz.RED)
        self.rightGazeVector = viz.endLayer() # Object will contain both points and lines
        self.rightGazeVector.visible(True)
        #rightGazeVector.setParent(rightEyeNode)
        self.rightGazeVector.pointSize(10)
        #rightGazeVector.setScale(5,5,5)
        self.rightGazeSphere = vizshape.addSphere(0.02, color = viz.RED)
        self.rightGazeSphere.setParent(self.rightEyeNode)

        # Creating a Line to represent Gaze Vector
        viz.startLayer(viz.LINES)
        viz.vertex(0,0,0)
        viz.vertex(0,0,3)
        viz.vertexColor(viz.BLUE)
        self.leftGazeVector = viz.endLayer() # Object will contain both points and lines
        self.leftGazeVector.visible(True)
        #leftGazeVector.setParent(leftEyeNode)
        #leftGazeVector.setScale(5,5,5)
        self.leftGazeSphere = vizshape.addSphere(0.02, color = viz.BLUE)
        self.leftGazeSphere.setParent(self.leftEyeNode)


        # Creating a Line to represent Eye-Ball Vector
        viz.startLayer(viz.LINES)
        viz.vertex(0,0,0)
        viz.vertex(0,0,3)
        viz.vertexColor(viz.YELLOW)
        self.EyeBallLine = viz.endLayer() # Object will contain both points and lines
        self.EyeBallLine.visible(True)
	def __init__(self,use_keyboard = True, desktop_mode = False):
		"""Initialization function."""
		
		caveapp.CaveApplication.__init__(self,desktop_mode) #call constructor of super class, you have to do this explicitly in Python		
		viz.phys.enable()
		
		self.view = viz.MainView;
		
		self.backGroundMusic = viz.addAudio('Windmill hut.wav')
		self.backGroundMusic.volume(0.5)
		self.backGroundMusic.loop(viz.ON)
		self.backGroundMusic.play()
		self.gameMusic = viz.addAudio('Battle.wav')
		self.gameMusic.volume(0.7)
		
		headLight = viz.MainView.getHeadLight()
		headLight.intensity(100)
		headLight.disable()
		
		for i in range(3):
			light = viz.addLight()
			light.setPosition(0, 2, (i*10))
			light.position(0,0,0,1)
				
		self.use_keyboard = use_keyboard #store if we want to use the keyboard
		self.scaleValue = 0.03
		
		self.shootingRange = viz.addChild('ShootingRange.FBX')
		self.shootingRange.setScale(self.scaleValue, self.scaleValue,self.scaleValue )
		self.shootingRange.name = 'shootingRange'
		self.shootingRange.collideMesh()
		self.shootingRange.disable(viz.DYNAMICS)		
		
		self.target = viz.addChild('target.FBX')
		self.target.name = 'target'
		self.target.setScale(0.9, 0.9, 0.9)
		self.target.collideBox(density = 100)
		self.target.enable(viz.COLLIDE_NOTIFY)
		self.target.setPosition(0,0, 15)
				
		self.enemyGun = viz.addChild('Gun.FBX')
		self.enemyGun.name = 'enemyGun'
		self.enemyGun.setScale(self.scaleValue, self.scaleValue, self.scaleValue)
		self.enemyGun.setPosition(0, 1.8, 14)
		self.enemyGun.setEuler(180,0,0)						
				
		self.bullet = viz.add('Bullet.FBX')
		self.bullet.setPosition(0,1,2)
		self.bullet.setScale(self.scaleValue, self.scaleValue,self.scaleValue)
		self.bullet.name = 'bullet'
		self.bullet.collideCapsule(0.2, 0.1, density = 1, hardness = 1)
		self.bullet.enable(viz.COLLIDE_NOTIFY)
		self.nextShot = True
		
		self.enemyBullet = viz.add('Bullet.FBX')
		self.enemyBullet.setPosition(0,1,10)
		self.enemyBullet.setScale(0.05, 0.05, 0.05)
		self.enemyBullet.name = 'enemyBullet'
		
		self.enemyShot = False
		
		self.enemyShootTimer = vizact.ontimer(3, self.repositionEnemyGun)
		self.moveEnemyBulletTimer = vizact.ontimer(0, self.moveEnemyBullet)
		
		self.moveEnemyBulletTimer.setEnabled(False)
		self.enemyShootTimer.setEnabled(False)
		
		self.shootTimer = vizact.ontimer(1, self.schootClick)
		self.shootTimer.setEnabled(False)	
		
		self.rings = ['Ring10', 'Ring20', 'Ring30', 'Ring40', 'Ring50'] 
									
		self.currentScore = 0		
		self.scoreBaseText = 'Score: '
		self.firstLabelText = self.scoreBaseText + str(self.currentScore)
		self.scoreLabel = viz.addText3D(self.firstLabelText)
		self.scoreLabel.setBackdrop(viz.BACKDROP_RIGHT_BOTTOM)
		self.scoreLabel.setPosition(-1.7, 1, 0)
		self.scoreLabel.setEuler(-90,0,0)
		self.scoreLabel.color(viz.SKYBLUE)
		self.scoreLabel.setScale(0.3, 0.3, 0.3)
		self.scoreLabel.alignment(viz.ALIGN_CENTER_BOTTOM)
		
		self.currentHighScore = 0		
		self.highScoreBaseText = 'Highscore: '
		self.firstHighScoreLabelText = self.highScoreBaseText + str(self.currentHighScore)
		self.highScoreLabel = viz.addText3D(self.firstHighScoreLabelText)
		self.highScoreLabel.setPosition(-1.7, 1.5, 0)
		self.highScoreLabel.setEuler(-90,0,0)
		self.highScoreLabel.color(viz.BLUE)
		self.highScoreLabel.setScale(0.3, 0.3, 0.3)
		self.highScoreLabel.alignment(viz.ALIGN_CENTER_BOTTOM)
		
		self.newPointLabel = viz.addText3D('')
		self.newPointLabel.color(viz.GREEN)
		self.newPointLabel.setPosition(self.target.getPosition()[0], self.target.getPosition()[1] + 2, self.target.getPosition()[2])
		self.newPointLabel.alignment(viz.ALIGN_CENTER_BOTTOM)
		self.maxTimeNewPointVisible = 1
		
		self.newHitLabel = viz.addText3D('')
		self.newHitLabel.color(viz.RED)
		self.newHitLabel.setPosition(self.target.getPosition()[0], self.target.getPosition()[1] + 2.5, self.target.getPosition()[2])
		self.newHitLabel.alignment(viz.ALIGN_CENTER_BOTTOM)
		self.maxTimeHitVisible = 1
		
		self.newPointTimer = vizact.ontimer(self.maxTimeNewPointVisible, self.makeNewPointLabelInvisible)
		self.newPointTimer.setEnabled(False)	
		
		self.newHitPointTimer = vizact.ontimer(self.maxTimeHitVisible, self.makeNewHitLabelInvisible)
		self.newHitPointTimer.setEnabled(False)	
									
		self.goodSound = viz.addAudio('good.mp3')
		self.coinSound = viz.addAudio('coin.wav')	
		self.hitSound = viz.addAudio('hit.mp3')
			
		self.playTimer = vizact.ontimer(1, self.timerClick)
		self.playTimer.setEnabled(False)
		self.playTime = 35		
		self.currentTime = 0
		self.isPlaying = False
		
		self.timeBaseText = 'Time: '
		self.timeLabel = viz.addText3D(self.timeBaseText)
		self.timeLabel.setPosition(1.1, 1.3, 3)
		self.timeLabel.setEuler(50,0,0)
		self.timeLabel.setScale(0.3, 0.3, 0.3)
		self.timeLabel.alignment(viz.ALIGN_CENTER_BOTTOM)
		self.timeLabel.visible(False)
				
		self.scope = viz.addChild('Scope.FBX')
		
		viz.startLayer(viz.LINES)
		viz.vertexColor(viz.RED)
		viz.vertex(-0.2, 0,0)
		viz.vertex(0.2, 0, 0)
		self.topLine = viz.endLayer()
		
		viz.startLayer(viz.LINES)
		viz.vertexColor(viz.RED)
		viz.vertex(0, 0,0)
		viz.vertex(0, -0.3, 0)
		self.leftLine = viz.endLayer()
		
		viz.startLayer(viz.LINES)
		viz.vertexColor(viz.RED)
		viz.vertex(0, 0,0)
		viz.vertex(0, -0.3, 0)
		self.rightLine = viz.endLayer()
		
		self.time = 0.0 
				test_num = test_num + 1
				panel.setText(test_text[test_num])
				if(test_num == 2):
					background2.visible(viz.ON)

# Add controllers
for controller in steamvr.getControllerList():

	# Create model for controller
	controller.model = controller.addModel(parent=navigationNode)
	controller.model.disable(viz.INTERSECTION)
	viz.link(controller, controller.model)

	# Create pointer line for controller
	viz.startLayer(viz.LINES)
	viz.vertexColor(viz.WHITE)
	viz.vertex([0,0,0])
	viz.vertex([0,0,100])
	controller.line = viz.endLayer(parent=controller.model)
	controller.line.disable([viz.INTERSECTION, viz.SHADOW_CASTING])
	controller.line.visible(True)

	# Setup task for triggering jumps using controller
	viztask.schedule(JumpTask(controller))

# Add directions to canvas
canvas = viz.addGUICanvas(pos=[0, 3.0, 6.0])
canvas.setMouseStyle(0)
canvas.alignment(viz.ALIGN_CENTER)
canvas.setRenderWorld([400,400], [5.0,5.0])
    def createVisualObjects(self):

        self.IOD = 0.06
        
        # create a node3D leftEyeNode
        self.cyclopEyeNode = vizshape.addSphere(0.015, color = viz.GREEN)
        self.cyclopEyeNode.alpha(0.3)
        #cyclopEyeNode.visible(viz.OFF)
        self.cyclopEyeNode.setPosition(*self.rawDataStruct['view_Pos_XYZ'][:,0])
        self.cyclopEyeNode.setQuat(*self.rawDataStruct['view_Quat_WXYZ'][:,0])

        # create a node3D rightEyeNode
        self.rightEyeNode = vizshape.addSphere(0.015, color = viz.RED)
        #rightEyeNode.visible(viz.OFF)
        self.rightEyeNode.setParent(self.cyclopEyeNode)
        self.rightEyeNode.setPosition(self.IOD/2, 0, 0.0,viz.ABS_PARENT)
        self.rightEyeNode.alpha(0.3)
    #    right_sphere = gazeSphere(eyeTracker,viz.RIGHT_EYE,rightEyeNode,[clientWindowID],sphereColor=viz.ORANGE)
    #    rightGazeVector = gazeVector(eyeTracker,viz.RIGHT_EYE,rightEyeNode,[clientWindowID],gazeVectorColor=viz.ORANGE)
    #    right_sphere.toggleUpdate()
    #    rightGazeVector.toggleUpdate()
    #    right_sphere.node3D.alpha(0.7)    


        # create a node3D leftEyeNode
        self.leftEyeNode = vizshape.addSphere(0.015, color = viz.BLUE)
        #leftEyeNode.visible(viz.OFF)
        self.leftEyeNode.setParent(self.cyclopEyeNode)
        self.leftEyeNode.setPosition(-self.IOD/2, 0, 0.0,viz.ABS_PARENT)
        self.leftEyeNode.alpha(0.3)
    #    left_sphere = gazeSphere(eyeTracker,viz.LEFT_EYE,leftEyeNode,[clientWindowID],sphereColor=viz.YELLOW)
    #    leftGazeVector = gazeVector(eyeTracker,viz.LEFT_EYE,leftEyeNode,[clientWindowID],gazeVectorColor=viz.YELLOW)
    #    left_sphere.toggleUpdate()
    #    leftGazeVector.toggleUpdate()
    #    left_sphere.node3D.alpha(0.7)
        self.hmdDisplay = vizshape.addPlane([0.126, 0.071], axis = -vizshape.AXIS_Z, color = viz.GRAY)
        self.hmdDisplay.alpha(0.3)
        self.hmdDisplay.setParent(self.cyclopEyeNode)
        self.hmdDisplay.setPosition([0,0,0.0725], viz.ABS_PARENT) # 0.0725

        self.pixelatedBall = vizshape.addCircle(0.001, axis = -vizshape.AXIS_Z, color = viz.WHITE)
        self.pixelatedBall.setParent(self.hmdDisplay)
        self.pixelatedBall.setPosition([0,0,0])
        self.pixelatedBall.alpha(1)
        
        self.eyePOR = vizshape.addCircle(0.001, axis = -vizshape.AXIS_Z, color = viz.GREEN)
        self.eyePOR.setParent(self.hmdDisplay)
        self.eyePOR.setPosition([0,0,0])
        self.eyePOR.alpha(1)

        self.rightPOR = vizshape.addCircle(0.001, axis = -vizshape.AXIS_Z, color = viz.RED)
        self.rightPOR.setParent(self.hmdDisplay)
        self.rightPOR.setPosition([0,0,0])
        self.rightPOR.alpha(1)

        self.leftPOR = vizshape.addCircle(0.001, axis = -vizshape.AXIS_Z, color = viz.BLUE)
        self.leftPOR.setParent(self.hmdDisplay)
        self.leftPOR.setPosition([0,0,0])
        self.leftPOR.alpha(1)



        #creats a sphere(the ball) with radius of 5cm
        self.ball = vizshape.addSphere(radius = .08)
        #colors the ball red
        self.ball.color(viz.YELLOW)
        self.ball.visible(True)
        self.ball.setParent(self.cyclopEyeNode)

        self.Origin = vizshape.addAxes()
        self.Origin.setPosition(-5.5,0.1,8)
    #    #creats a sphere(the ball) with radius of 5cm
    #    #Head = vizshape.addCone( radius = 0.5, height = 0.8)
    #    Head = vizshape.addArrow(1, color = viz.YELLOW_ORANGE)
    #    #colors the ball red
    #    Head.color(viz.PURPLE)
    #    Head.visible(True)
    #    Head.setScale(.2,.2,.3)

        #creats a sphere(the hand) with radius of 10cm
        self.Hand = vizshape.addCylinder( height = 0.02, radius = 0.2, axis = vizshape.AXIS_Z)
        #colors the hand red
        self.Hand.color(viz.RED)
        self.Hand.visible(True)

        # Creating a Line to represent Cyclopean Eye Gaze Vector
        viz.startLayer(viz.LINES)
        viz.vertex(0,0,0)
        viz.vertex(0,0,3)
        viz.vertexColor(viz.GREEN)
        self.eyeGazeVector = viz.endLayer() # Object will contain both points and lines
        self.eyeGazeVector.visible(True)
        self.eyeGazeVector.setParent(self.cyclopEyeNode)
        self.eyeGazeVector.pointSize(10)
        #rightGazeVector.setScale(5,5,5)
        self.eyeGazeSphere = vizshape.addSphere(0.02, color = viz.GREEN)
        self.eyeGazeSphere.setParent(self.cyclopEyeNode)


        # Creating a Line to represent Right Eye Gaze Vector
        viz.startLayer(viz.LINES)
        viz.vertex(0,0,0)
        viz.vertex(0,0,3)
        viz.vertexColor(viz.RED)
        self.rightGazeVector = viz.endLayer() # Object will contain both points and lines
        self.rightGazeVector.visible(True)
        #rightGazeVector.setParent(rightEyeNode)
        self.rightGazeVector.pointSize(10)
        #rightGazeVector.setScale(5,5,5)
        self.rightGazeSphere = vizshape.addSphere(0.02, color = viz.RED)
        self.rightGazeSphere.setParent(self.rightEyeNode)
        self.rightGazeSphere.visible(False)

        # Creating a Line to represent Left Eye Gaze Vector
        viz.startLayer(viz.LINES)
        viz.vertex(0,0,0)
        viz.vertex(0,0,3)
        viz.vertexColor(viz.BLUE)
        self.leftGazeVector = viz.endLayer() # Object will contain both points and lines
        self.leftGazeVector.visible(True)
        #leftGazeVector.setParent(leftEyeNode)
        #leftGazeVector.setScale(5,5,5)
        self.leftGazeSphere = vizshape.addSphere(0.02, color = viz.BLUE)
        self.leftGazeSphere.setParent(self.leftEyeNode)
        self.leftGazeSphere.visible(False)


        # Creating a Line to represent Eye-Ball Vector
        viz.startLayer(viz.LINES)
        viz.vertex(0,0,0)
        viz.vertex(0,0,3)
        viz.vertexColor(viz.YELLOW)
        self.EyeBallLine = viz.endLayer() # Object will contain both points and lines
        self.EyeBallLine.visible(False)
        #EyeBallLine.setScale(5,5,5)

        self.male = viz.add('ktex.obj') 
        #male.state(1) #looping idle animation
        #self.headBone = self.male.getBone('Bip01 Head')
        #self.headBone.lock()
        self.male.setParent(self.cyclopEyeNode)
示例#41
0
cityModel = CityModel()

#Sounds to play on building collisions
CRASH_SOUND = viz.playSound('BuildingCrashSound.wav', viz.SOUND_PRELOAD)

BirdEyeWindow = viz.addWindow()
BirdEyeWindow.fov(60)
BirdEyeWindow.visible(0,viz.SCREEN)
BirdEyeView = viz.addView()
BirdEyeWindow.setView(BirdEyeView)
BirdEyeWindow.setPosition([0,25,0])
BirdEyeView.setEuler([0,90,0])

###User tracking with lines###
viz.startLayer(viz.LINE_STRIP)
viz.vertexColor(viz.YELLOW)
lines = viz.endLayer(parent=viz.ORTHO,scene=BirdEyeWindow)

lines.dynamic()

def UpdatePath():

    # Get main view position in bird eye window pixel coordinates
    x,y,z = BirdEyeWindow.worldToScreen(viz.MainView.getPosition(),mode=viz.WINDOW_PIXELS)

    # Get position of last line vertex
    lx,ly,lz = lines.getVertex(-1)

    # Add new vertex if current position is different from last position
    if x != lx or y != ly:
        lines.addVertex([x,y,0.0])