示例#1
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)
示例#2
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()
    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()
			def createRod():
				viz.startLayer(viz.POINTS)
				viz.pointSize(4)
				viz.vertex(0,1.65,1)
				viz.vertex(0,1.70,1)
				viz.vertex(0,1.75,1)
				viz.vertex(0,1.80,1)
				viz.vertex(0,1.85,1)
				viz.vertex(0,1.90,1)
				viz.vertex(0,1.95,1)
				line = viz.endLayer()
				line.visible(viz.OFF)
				line.center(0,1.8,1)
				initLinePos = 0 + 20 * random.uniform(-1,1)
				line.setEuler([0,0,initLinePos])
				class LineRotation(viz.EventClass):
					def __init__(self):
						viz.EventClass.__init__(self)

						self.callback(viz.KEYDOWN_EVENT, self.keyboardAction)

					def keyboardAction(self,key):
						currentPosition = line.getEuler()
						currentRoll = currentPosition[2]
						if viz.key.isDown(viz.KEY_LEFT):
							line.setEuler([0,0,currentRoll + 1])
						elif viz.key.isDown(viz.KEY_RIGHT): 
							line.setEuler([0,0,currentRoll -1])
				LineRotation()
				return line, initLinePos
示例#5
0
    def rotateRigid(self, rotateByDegs_XYZ):

        # create a temp vizard 3d object
        # rotate, use vertices to redefine rigid object
        # maybe that phasespace coordinate system does not match vizard coordinate system

        viz.startLayer(viz.POINTS)
        for idx in range(len(self.markerPos_midx_localXYZ)):
            viz.vertex(self.markerPos_midx_localXYZ[idx][0],
                       self.markerPos_midx_localXYZ[idx][1],
                       self.markerPos_midx_localXYZ[idx][2])

        tempRigidObject = viz.endLayer()
        tempRigidObject.visible(viz.OFF)  #Make the object invisible.

        # Update rigid body definition on the owl server
        #tempRigidObject.setEuler( rotateByDegs_XYZ,viz.RELATIVE ) #,viz.RELATIVE)

        tempRigidObject.setQuat(rotateByDegs_XYZ, viz.ABS_GLOBAL)

        owlTracker(self.trackerIdx, OWL_DISABLE)

        count = 0
        for i in xrange(len(self.markerID_midx)):
            owlMarkerfv(MARKER(self.trackerIdx, i), OWL_SET_POSITION,
                        tempRigidObject.getVertex(i, viz.RELATIVE))
            self.markerPos_midx_localXYZ[count] = tempRigidObject.getVertex(
                i, viz.RELATIVE)
            count += 1

        owlTracker(self.trackerIdx, OWL_ENABLE)

        tempRigidObject.remove()  #Remove the object.
示例#6
0
	def rotateRigid(self,rotateByDegs_XYZ):

		# create a temp vizard 3d object 
		# rotate, use vertices to redefine rigid object
		# maybe that phasespace coordinate system does not match vizard coordinate system
		
		viz.startLayer(viz.POINTS)
		for idx in range(len(self.markerPos_midx_localXYZ)):
			viz.vertex(self.markerPos_midx_localXYZ[idx][0],self.markerPos_midx_localXYZ[idx][1],self.markerPos_midx_localXYZ[idx][2])
		
		tempRigidObject = viz.endLayer()
		tempRigidObject.visible( viz.OFF ) #Make the object invisible.
		
		# Update rigid body definition on the owl server
		#tempRigidObject.setEuler( rotateByDegs_XYZ,viz.RELATIVE ) #,viz.RELATIVE)		
		
		tempRigidObject.setQuat(rotateByDegs_XYZ,viz.ABS_GLOBAL)
		
		owlTracker(self.trackerIdx,OWL_DISABLE)

		count = 0
		for i in xrange(len(self.markerID_midx)):
			owlMarkerfv(MARKER(self.trackerIdx, i), OWL_SET_POSITION, tempRigidObject.getVertex(i,viz.RELATIVE))
			self.markerPos_midx_localXYZ[count] = tempRigidObject.getVertex(i,viz.RELATIVE)
			count +=1
			
		owlTracker(self.trackerIdx, OWL_ENABLE);
		
		tempRigidObject.remove() #Remove the object.
			def createFrame(direction):

				viz.startLayer(viz.LINES)
				viz.vertex(-.2,1.6,1)
				viz.vertex(-.2,2,1)

				viz.vertex(.2,1.6,1)
				viz.vertex(.2,2,1)

				viz.vertex(-.2,1.6,1)
				viz.vertex(.2,1.6,1)

				viz.vertex(-.2,2,1)
				viz.vertex(.2,2,1)

				poly = viz.endLayer()
				poly.visible(viz.OFF)
				poly.center(0,1.8,1)
				if direction == 'left':
					poly.setEuler([0,0,20])
				elif direction == 'right':
					poly.setEuler([0,0,-20])
				elif direction == 'none':
					poly.remove()
				return poly
示例#8
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)
示例#9
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
示例#10
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()
示例#11
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)
示例#12
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()
示例#13
0
	def rotateRigid(self,rotateByDegs_XYZ):

		# create a temp vizard 3d object 
		# rotate, use vertices to redefine rigid object
		
		viz.startLayer(viz.POINTS)
		for idx in range(len(self.markerPos_midx_localXYZ)):
			viz.vertex(self.markerPos_midx_localXYZ[idx][0],self.markerPos_midx_localXYZ[idx][1],self.markerPos_midx_localXYZ[idx][2])
		
		tempRigidObject = viz.endLayer()
		tempRigidObject.visible( viz.OFF ) #Make the object invisible.
		
		# Update rigid body definition on the owl server
		tempRigidObject.setEuler( rotateByDegs_XYZ,viz.RELATIVE)		
		
		owlTracker(self.trackerIdx,OWL_DISABLE)

		count = 0
		for i in xrange(len(self.markerID_midx)):
			owlMarkerfv(markerNumToID(self.trackerIdx, i), OWL_SET_POSITION, tempRigidObject.getVertex(i,viz.RELATIVE))
			self.markerPos_midx_localXYZ[count] = tempRigidObject.getVertex(i,viz.RELATIVE)
			count +=1
			
		owlTracker(self.trackerIdx, OWL_ENABLE);
		
		tempRigidObject.remove() #Remove the object.
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
示例#15
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()
示例#16
0
    def __init__(self, x, y):
        self.x = x
        self.y = y
        #main ship
        viz.startLayer(viz.QUADS)
        viz.vertexColor(0.27, 0.58, 0.16)
        viz.vertex(-15, -9)
        viz.vertexColor(0.5, 0.4, 0.3)
        viz.vertex(-15, 9)
        viz.vertexColor(0.1, 0, 0.8)
        viz.vertex(15, 9)
        viz.vertexColor(0.5, 0.4, 0.3)
        viz.vertex(15, -9)

        #cannon
        viz.vertexColor(0.27, 0.58, 0.16)
        viz.vertex(4.5, 9)
        viz.vertex(-4.5, 9)
        viz.vertex(-4.5, 14)
        viz.vertexColor(0.2, 0, 0.5)
        viz.vertex(4.5, 14)

        #top
        viz.vertexColor(0.27, 0.58, 0.16)
        viz.vertex(1.5, 14)
        viz.vertex(-1.5, 14)
        viz.vertex(-1.5, 18)
        viz.vertex(1.5, 18)
        self.vertices = viz.endLayer()
示例#17
0
def groundCreator():
	viz.startLayer(viz.QUADS)
	viz.texCoord(0,0) 
	viz.vertex(100, 0, -100)
	viz.texCoord(1,0) 
	viz.vertex(100, 0, 100)
	viz.texCoord(1,1) 
	viz.vertex(-100, 0, 100)
	viz.texCoord(0,1)  
	viz.vertex(-100, 0, -100)
	ground = viz.endLayer()

	AreaScale_f = [16, 16 ,1]

	matrix_area_f = vizmat.Transform()
	matrix_area_f.setScale(AreaScale_f)
	
	ground.texmat(matrix_area_f)

	wallTex = viz.addTexture('wallTex.jpg')
	wallTex.wrap(viz.WRAP_T,viz.REPEAT)
	wallTex.wrap(viz.WRAP_S,viz.REPEAT)

	ground.texture(wallTex)

	return ground
示例#18
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
示例#19
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
示例#20
0
def flashingCloud(height, width, depth, offset, number, node):

	positions = np.random.uniform(low = -width/2, high = width/2, size = (number, 3))
	positions[:, 1] = positions[:, 1]/(width/height) 

	# Save the location of each dots into a .csv file
	record = open('Cloud_positions_' + str(number) + '.csv', 'a' ) 	

	for n in range(number):
		record.write(str(positions[n, 0]) + ',' + str(positions[n, 1]) + ',' + str(positions[n, 2]) + '\n')

	positions[:, 2] = positions[:, 2] - (depth/2 - offset) 

	clouds = []
	
	viz.startLayer(viz.POINTS)
	viz.pointSize(2)  # Set the size of the dots on the display

	# Draw each dot
	for i in range(number):
		viz.vertex(positions[i, 0], positions[i, 1], positions[i, 2])

	cloud = viz.endLayer()

	# Set a parent object for the cloud.
	# Therefore, once the location of the parent is determined, the location of the cloud as a whole is also determined.
	cloud.setParent(node) 

	return cloud
示例#21
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
示例#22
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
 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()
示例#24
0
def cross(eyeHeight):
    viz.startLayer(viz.LINES)
    viz.lineWidth(2)
    viz.vertex(-0.25, 0 + eyeHeight, 5)  #Vertices are split into pairs.
    viz.vertex(0.25, 0 + eyeHeight, 5)
    viz.vertex(0, -0.25 + eyeHeight, 5)
    viz.vertex(0, 0.25 + eyeHeight, 5)
    myCross = viz.endLayer()
    return myCross
示例#25
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()
示例#26
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()
示例#27
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()
示例#28
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()
示例#29
0
	def addCameraBounds(self):
		"""Create node for rendering tracking boundary of HMD camera"""
		if not self._sensor:
			return None

		if (self._sensor.getSrcMask() & viz.LINK_POS) == 0:
			return None

		left,right,bottom,top,near,far = self._sensor.getCameraFrustum()
		s = far / near
		fleft, fright, fbottom, ftop = left*s, right*s, bottom*s, top*s

		viz.startLayer(viz.LINES)

		# Boundary lines
		viz.vertex([0,0,0])
		viz.vertex([fleft,ftop,far])
		viz.vertex([0,0,0])
		viz.vertex([fright,ftop,far])
		viz.vertex([0,0,0])
		viz.vertex([fleft,fbottom,far])
		viz.vertex([0,0,0])
		viz.vertex([fright,fbottom,far])

		# Near plane
		viz.vertex([left,top,near])
		viz.vertex([right,top,near])
		viz.vertex([right,top,near])
		viz.vertex([right,bottom,near])
		viz.vertex([right,bottom,near])
		viz.vertex([left,bottom,near])
		viz.vertex([left,bottom,near])
		viz.vertex([left,top,near])

		# Far plane
		viz.vertex([fleft,ftop,far])
		viz.vertex([fright,ftop,far])
		viz.vertex([fright,ftop,far])
		viz.vertex([fright,fbottom,far])
		viz.vertex([fright,fbottom,far])
		viz.vertex([fleft,fbottom,far])
		viz.vertex([fleft,fbottom,far])
		viz.vertex([fleft,ftop,far])

		lines = viz.endLayer(color=viz.GREEN)
		lines.drawOrder(100)
		lines.disable([viz.LIGHTING,viz.DEPTH_TEST,viz.SHADOW_CASTING,viz.INTERSECTION,viz.PICKING])
		lines.setReferenceFrame(viz.RF_VIEW)
		link = viz.link(self._sensor, lines, srcFlag=ORI_CAMERA)
		link.postMultInverseLinkable(self._sensor)

		return lines
示例#30
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()
示例#31
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
示例#32
0
def door_line(high, wide, pixel):
    door = viz.addGroup()

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

    viz.startLayer(viz.LINE_LOOP)
    viz.lineWidth(pixel)
    for i in range(4):
        viz.vertex(pos[i, :].tolist())

    line = viz.endLayer()
    line.setParent(door)

    return door
示例#33
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()
示例#34
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
示例#35
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
示例#36
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
示例#37
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)
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)
示例#39
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)
	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)
	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 
    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 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)
import viz
import threading
import Queue
import time
import json
import vizact
import math
import cProfile

viz.splashScreen('C:\Users\Gelsey Torres-Oviedo\Desktop\VizardFolderVRServer\Logo_final.jpg')
viz.go(
viz.FULLSCREEN
)
time.sleep(2)#show off a litle bit...

viz.startLayer(viz.LINES) 
viz.vertex(-1,-0.25,-0.0001) #Vertices are split into pairs. 
viz.vertex(1,-0.25,-0.0001) 
myLines = viz.endLayer() 
#indicate flag for post-catch targets, which last for the first 12 steps
global catchflag
catchflag = 1
global stridecounter
stridecounter = 0

#set target tolerance for stride length
global targetL
targetL = 0.25
global targetR
targetR = 0.25
global targettol
 def draw(self, vertices):
     viz.startLayer(viz.LINE_LOOP)
     viz.lineWidth(10)
     for v in vertices:
         viz.vertex(*v)
     return viz.endLayer()
示例#46
0
# City Model: see CityModel.py for reference
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:
示例#47
0
import viz
import vizact
viz.go()

#Example for creating a fan of triangles: 
viz.startLayer(viz.TRIANGLE_FAN)  
viz.vertex(0,1,5) #All the triangles have the first vertex as a point. 
viz.vertex(-1.5,1.35,10) #The other points are taken in pairs. 
viz.vertex(-.25,1.5,10) 
viz.vertex(0,.8,10) 
viz.vertex(.25,1.5,10) 
viz.vertex(1.5,1.35,10) 
myTrianglefan = viz.endLayer()  

#Notify Vizard that the layer will be modified frequently. 
myTrianglefan.dynamic() 

#Grab a vertex. 
tip = myTrianglefan.Vertex( 0 ) 
fadeInAndOut = vizact.sequence( [vizact.fadeTo(viz.RED,time=1),vizact.fadeTo(viz.WHITE,time=1)], viz.PERPETUAL ) 
#Apply an action to the vertex. 
tip.addAction( fadeInAndOut )