Esempio n. 1
0
def StraightMaker(x,
                  start_z,
                  end_z,
                  colour=[.8, .8, .8],
                  primitive=viz.QUAD_STRIP,
                  width=None):
    """returns a straight, given some starting coords and length"""
    viz.startlayer(primitive)
    if width is None:
        if primitive == viz.QUAD_STRIP:
            width = .05
        elif primitive == viz.LINE_STRIP:
            width = 2
            viz.linewidth(width)
            width = 0

    viz.vertex(x - width, .1, start_z)
    viz.vertexcolor(colour)
    viz.vertex(x + width, .1, start_z)
    viz.vertexcolor(colour)
    viz.vertex(x - width, .1, end_z)
    viz.vertexcolor(colour)
    viz.vertex(x + width, .1, end_z)

    straightedge = viz.endlayer()

    return straightedge
    def EdgeMaker(self, startpos, bearing, primitive_width):
        """function returns a bend edge"""
        """function returns a bend edge"""
        
        viz.startlayer(self.primitive) 	
        
        for ins, out in zip(inside,outside):

            viz.vertex(ins[0], ABOVEGROUND, ins[1])
            viz.vertexcolor(self.colour)
            viz.vertex(out[0], ABOVEGROUND, out[1])
            viz.vertexcolor(self.colour)

        """
        while i < self.Edge_Pts:			
            x1 = ((bearing - primitive_width)*np.cos(self.RoadArray[i])) + startpos[0]
            z1 = self.Zdirection*((bearing - primitive_width)*np.sin(self.RoadArray[i])) + startpos[2]

            #print (z1[i])			
            viz.vertex(x1, ABOVEGROUND, z1)				
            viz.vertexcolor(self.colour)

            if self.primitive == viz.QUAD_STRIP:
                x2 = ((rads + primitive_width)*np.cos(self.RoadArray[i])) + startpos[0]
                z2 = self.Zdirection*((rads + primitive_width)*np.sin(self.RoadArray[i])) + startpos[2]
                viz.vertex(x2, ABOVEGROUND, z2)				
                viz.vertexcolor(self.colour)

            i += 1

        """

        Bend = viz.endlayer()

        return Bend
Esempio n. 3
0
def placeMirror():
	
	mirrorPos = [0, 1.5, -2];
	
	global wall, mirrorRight, mirrorLeft, mirrorPlane
	wall = viz.addTexQuad()
	wall.setPosition(0, 0, mirrorPos[2] - 0.02)
	wall.setScale(20, 20, 1)
	# Apply nice repeating brick texture
	wallmatrix = vizmat.Transform()
	wallmatrix.setScale(20, 20, 1)
	wall.texmat( wallmatrix )
	bricks = viz.addTexture('brick.jpg')
	bricks.wrap(viz.WRAP_T, viz.REPEAT)
	bricks.wrap(viz.WRAP_S, viz.REPEAT)
	wall.texture(bricks)
	
	mirrorPlane = vizshape.addPlane()
	mirrorPlane.setPosition(mirrorPos, viz.ABS_GLOBAL)
	mirrorPlane.setEuler(0, 90, 0)
	mirrorPlane.setScale(0.09, 1, 0.05)

	windowBox = mirrorPlane.getBoundingBox(mode = viz.ABS_GLOBAL)
	x0 = windowBox.xmin
	x1 = windowBox.xmax
	y0 = windowBox.ymin
	y1 = windowBox.ymax
	z = windowBox.zmax

	viz.startlayer(viz.QUADS)
	viz.texcoord(0,0)
	viz.vertex( x0  , y0 , z )
	viz.texcoord(0,1)
	viz.vertex( x0  , y1, z )
	viz.texcoord(1,1)
	viz.vertex( x1  , y1, z)
	viz.texcoord(1,0)
	viz.vertex( x1  , y0 , z)

	mirrorRight = viz.endlayer( )
	mirrorLeft = mirrorRight.copy()	

	#specify the matrix
	m = viz.Matrix()
	#Try moving the mirror
	#print "z: " + str(z);
	m.setPosition([0, 0, z])
	m.setEuler(0, 0, 0)

	#Apply mirror settings to mirror object
	mirrorPlane.alpha(0.0)
	addMirror(mirrorRight,m,viz.RIGHT_EYE)
	addMirror(mirrorLeft,m,viz.LEFT_EYE)
	
	# Add collision
	mirrorPlane.collideBox()
	
	wall.visible(viz.OFF)
	mirrorRight.visible(viz.OFF)
	mirrorLeft.visible(viz.OFF)
Esempio n. 4
0
def setARfov( val ):
	global node, ARfov_vert, hmdview	
	ARfov_vert = val
	#ARfov_vert = HMDfov_vert
	#ARfov_vert = 20
	ARheight = (int) (HMDheight / HMDfov_vert * ARfov_vert)
	ARwidth = ARheight * HMDaspect
	
	#recalculate ARfov_vert
	#ARfov_vert = (ARheight / HMDheight) * HMDfov_vert
	
	ARx = (HMDwidth - ARwidth)/2
	ARy = (HMDheight - ARheight)/2
	#print "AR view dimensions:",ARwidth,ARheight,ARx,ARy,ARfov_vert
	node.setSize( ARwidth,ARheight,ARx,ARy )
	node.setFov( ARfov_vert, HMDaspect, HMDnear, HMDfar )
	#return
	
	if(hmdview != 0):
		hmdview.remove()
	viz.startlayer(viz.QUADS)
	viz.vertex([ARx,ARy,0])
	viz.vertex([ARx + ARwidth, ARy,0])
	viz.vertex([ARx + ARwidth,ARy + ARheight,0])
	viz.vertex([ARx,ARy + ARheight,0])
	hmdview = viz.endlayer(viz.WORLD,viz.Scene3)
	hmdview.alpha(0.15)
    def BendMaker(self, t, yawrate, transition_duration, rw, speed, sp, x_dir):
        """function returns a bend edge"""
        """function returns a bend edge"""

        x, y, bearing = cc.clothoid_curve(t, speed, yawrate,
                                          transition_duration)

        if x_dir < 0:
            bearing[:] = [(2 * (np.pi) - b) for b in bearing[:]]

        midline = np.array([((x * x_dir) + sp[0]), (y + sp[1])]).T

        outside = np.array(cc.add_edge((x * x_dir), y, (rw / 2), sp)).T
        inside = np.array(cc.add_edge((x * x_dir), y, -(rw / 2), sp)).T

        #print(outside.shape)
        #print(inside.shape)

        viz.startlayer(self.Primitive)

        for ins, out in zip(inside, outside):

            #print(ins)
            #print(ins.shape)
            viz.vertex(ins[0], ABOVEGROUND, ins[1])
            viz.vertexcolor(self.Colour)
            #print(ins[0], ins[1])
            viz.vertex(out[0], ABOVEGROUND, out[1])
            viz.vertexcolor(self.Colour)
            #print(out[0], out[1])

        Bend = viz.endlayer()

        return ([Bend, midline, inside, outside, bearing])
Esempio n. 6
0
def createQuad(left_bot, left_top, right_bot, right_top):
    viz.startlayer(viz.QUADS)
    viz.vertexcolor(0, 0, 0)
    viz.vertex(left_bot)
    viz.vertex(left_top)
    viz.vertex(right_top)
    viz.vertex(right_bot)
    return viz.endlayer()
Esempio n. 7
0
    def StraightMaker(self, startpos, bearing, length, primitive_width):

        endpos = [(startpos[0] + (length * (np.sin(bearing)))),
                  (startpos[1] + (length * (np.cos(bearing))))]

        viz.startlayer(self.Primitive)

        #print ("Startpos: ", startpos)
        # print ("Endpos: ", endpos)

        start_left = ([
            (startpos[0] + (primitive_width * (np.sin(bearing - np.pi / 2)))),
            ABOVEGROUND,
            (startpos[1] + (primitive_width * (np.cos(bearing - np.pi / 2))))
        ])
        #print('1L', start_left)
        viz.vertex(start_left)
        viz.vertexcolor(self.Colour)

        # start rightside
        start_right = ([
            (startpos[0] + (primitive_width * (np.sin(bearing + np.pi / 2)))),
            ABOVEGROUND,
            (startpos[1] + (primitive_width * (np.cos(bearing + np.pi / 2))))
        ])
        #print('1R', start_right)
        viz.vertex(start_right)
        viz.vertexcolor(self.Colour)

        # end leftside:
        end_left = ([
            (endpos[0] + (primitive_width * (np.sin(bearing - np.pi / 2)))),
            ABOVEGROUND,
            (endpos[1] + (primitive_width * (np.cos(bearing - np.pi / 2))))
        ])
        #print('2L', end_left)
        viz.vertex(end_left)
        viz.vertexcolor(self.Colour)

        # end rightside:
        end_right = ([
            (endpos[0] + (primitive_width * (np.sin(bearing + np.pi / 2)))),
            ABOVEGROUND,
            (endpos[1] + (primitive_width * (np.cos(bearing + np.pi / 2))))
        ])
        #print('2R', end_right)
        viz.vertex(end_right)
        viz.vertexcolor(self.Colour)

        straight = viz.endlayer()

        return (straight, endpos)
Esempio n. 8
0
    def StraightEdgeMaker(self, startpos, endpos, primitive_width):
        """function returns a bend edge"""
        i = 0
        viz.startlayer(self.primitive)

        #print ("Startpos: ", startpos)
        #print ("Endpos: ", endpos)

        viz.vertex([startpos[0] - primitive_width, startpos[1], startpos[2]])
        viz.vertexcolor(self.colour)
        viz.vertex([startpos[0] + primitive_width, startpos[1], startpos[2]])
        viz.vertexcolor(self.colour)
        viz.vertex([endpos[0] - primitive_width, endpos[1], endpos[2]])
        viz.vertexcolor(self.colour)
        viz.vertex([endpos[0] + primitive_width, endpos[1], endpos[2]])
        viz.vertexcolor(self.colour)

        straightedge = viz.endlayer()

        return (straightedge)
def setARfov( val ):
	global HMDheight, HMDwidth, HMDfov_vert, HMDaspect, HMDnear, HMDfar
	global node, ARfov_vert, ARgraybox
	
	print "********* val is ",val
	ARfov_vert = val
	ARheight = (int) (HMDheight / HMDfov_vert * ARfov_vert)
	ARwidth = ARheight * HMDaspect
	
	ARx = (HMDwidth - ARwidth)/2
	ARy = (HMDheight - ARheight)/2
	node.setSize( ARwidth,ARheight,ARx,ARy )
	node.setFov( ARfov_vert, HMDaspect, HMDnear, HMDfar )
	
	if(ARgraybox != 0):
		ARgraybox.remove()
	viz.startlayer(viz.QUADS)
	viz.vertex([ARx,ARy,0])
	viz.vertex([ARx + ARwidth, ARy,0])
	viz.vertex([ARx + ARwidth,ARy + ARheight,0])
	viz.vertex([ARx,ARy + ARheight,0])
	ARgraybox = viz.endlayer(viz.WORLD,viz.Scene3)
	ARgraybox.alpha(0.15)
Esempio n. 10
0
def placeMirror():
	global m
	windowBox = mirrorPlane.getBoundingBox(mode = viz.ABS_GLOBAL)
	x0 = windowBox.xmin
	x1 = windowBox.xmax
	y0 = windowBox.ymin
	y1 = windowBox.ymax
	z = windowBox.zmax

	viz.startlayer(viz.QUADS)
	viz.texcoord(0,0)
	viz.vertex( x0  , y0 , z )
	viz.texcoord(0,1)
	viz.vertex( x0  , y1, z )
	viz.texcoord(1,1)
	viz.vertex( x1  , y1, z)
	viz.texcoord(1,0)
	viz.vertex( x1  , y0 , z)

	mirrorRight = viz.endlayer( )
	mirrorLeft = mirrorRight.copy()

	#specify the matrix
	m = viz.Matrix()
	#Try moving the mirror
	#m.setPosition([ 0.5*(x0+x1), 0.5*(y0+y1), z])
	m.setPosition([0,0,z])
	m.setEuler(180, 0, 0)
	
	# Adjust these! #
	#m.setPosition([0,0,z-1.50]) #this makes the mirror not reflect the space of the 4th row
	#m.setScale(2, 2, 2)

	#Apply mirror settings to mirror object
	mirrorPlane.alpha(0.0)
	addMirror(mirrorRight,m,viz.RIGHT_EYE)
	addMirror(mirrorLeft,m,viz.LEFT_EYE)
Esempio n. 11
0
    def EdgeMaker(self, startpos, rads, primitive_width):
        """function returns a bend edge"""
        i = 0
        viz.startlayer(self.primitive) 	
        
        while i < self.Edge_Pts:			
            x1 = ((rads-primitive_width)*np.cos(self.RoadArray[i])) + startpos[0]
            z1 = self.Z_direction*((rads-primitive_width)*np.sin(self.RoadArray[i])) + startpos[2]

            #print (z1[i])			
            viz.vertex(x1, ABOVEGROUND, z1)				
            viz.vertexcolor(self.colour)

            if self.primitive == viz.QUAD_STRIP:
                x2 = ((rads+primitive_width)*np.cos(self.RoadArray[i])) + startpos[0]
                z2 = self.Z_direction*((rads+primitive_width)*np.sin(self.RoadArray[i])) + startpos[2]
                viz.vertex(x2, ABOVEGROUND, z2)				
                viz.vertexcolor(self.colour)

            i += 1

        Bend = viz.endlayer()

        return Bend
Esempio n. 12
0
	def __init__( self ,  av_type = 0):
		self.in_quad = 0
		if av_type == 0:
			type = random.randrange(0,4)
			if type == 0:
				self.avatar = viz.add('male.cfg',viz.WORLD,scene=viz.MainScene)
			elif type == 1:
				self.avatar = viz.add('vcc_male.cfg',viz.WORLD,scene=viz.MainScene)
			elif type == 2:
				self.avatar = viz.add('female.cfg',viz.WORLD,scene=viz.MainScene)
			else:
				self.avatar = viz.add('vcc_female.cfg',viz.WORLD,scene=viz.MainScene)
		else:
			self.avatar = viz.add('vcc_male.cfg',viz.WORLD,scene=viz.MainScene)
			#Add the hat model
			self.hat = viz.add('tophat.3ds')
			self.hat.setScale([1,5,1])

			#Get the head bone of the avatar
			head = self.avatar.getBone('Bip01 Head')

			#Link the hat to the head
			HatLink = viz.link(head,self.hat)

			#Tweek the hat link so it fits snuggly on the head
			
			HatLink.preTrans( [0,0.1,-0.0] )
			HatLink.preEuler( [0,-10,0] )
			#HatLink.([0,5,0])
			
		self.avatar.setPosition(get_random_point())
		self.next_point = get_quadrant(self.avatar.getPosition()).get_random_walk()
		self.coll = 0
		self.avatar.collideMesh()
		self.avatar.enable(viz.COLLIDE_NOTIFY)
		
		#setup the AR
		viz.startlayer(viz.QUADS)
		viz.vertexcolor(1,0,0)
		#viz.pointsize(20)
		viz.linewidth(20)
		pos = self.avatar.getPosition()
		#viz.vertex(pos[0], -20, pos[2])
		#viz.vertex(pos[0], 20, pos[2])
		#rx = 0.5
		#ry = 1
		#viz.vertex(-rx, 0, 0)
		#viz.vertex(-rx, r, 0)
		#viz.vertex(r, r, 0)
		#viz.vertex(r, -r, 0)
		
		#viz.vertex(0,0,0)
		#viz.vertex(0,2,0)
		viz.vertex(-0.3,0,0)
		viz.vertex(0.3,0,0)
		viz.vertex(0.3,2,0)
		viz.vertex(-0.3,2,0)
		self.pointAR = viz.endlayer(viz.WORLD, viz.Scene2)
		self.set_AR(True)
		#self.pointAR.alpha(0.3)
		
		
		self.arev = vizact.ontimer(.01,self.move_AR)
Esempio n. 13
0
def BendMaker(radlist):

    #make left and right road edges for for a given radii and return them in a list.

    #needs to work with an array of radii

    rdsize = 1000  # Hz size for curve length

    #left_array= np.arange(0.0, np.pi*1000)/1000
    left_array = np.linspace(0.0, np.pi, rdsize)
    #right_array = np.arange(np.pi*1000, 0.0, -1)/1000  ##arange(start,stop,step). Array with 3142(/1000) numbers
    right_array = np.linspace(
        np.pi, 0.0,
        rdsize)  ##arange(start,stop,step). Array with 3142(/1000) numbers

    leftbendlist = []
    rightbendlist = []
    grey = [.8, .8, .8]
    for r in radlist:
        x1 = np.zeros(rdsize)
        z1 = np.zeros(rdsize)
        x2 = np.zeros(rdsize)
        z2 = np.zeros(rdsize)

        i = 0
        viz.startlayer(viz.LINE_STRIP)
        #viz.linewidth(5)
        viz.linewidth(3)
        viz.vertexColor(grey)
        viz.vertex(0, .1, 0)  #START AT ORIGIN

        if r > 0:  #r=-1 means it is a straight.
            while i < rdsize:
                x1[i] = (r * np.cos(right_array[i])) + r
                z1[i] = (r * np.sin(right_array[i]))
                #print (z1[i])
                viz.vertexColor(grey)
                viz.vertex(x1[i], .1, z1[i])

                i += 1
        else:
            viz.vertex(0, .1, 100.0)  #100m straight

        rightbend = viz.endlayer()
        rightbend.visible(0)
        rightbend.dynamic()

        # left bend of a given radii
        viz.startlayer(viz.LINE_STRIP)
        #viz.linewidth(5)
        viz.linewidth(3)
        viz.vertexColor(grey)
        viz.vertex(0, .1, 0)  #START AT ORIGIN
        i = 0
        if r > 0:  #r=-1 means it is a straight.
            while i < rdsize:
                x1[i] = (r * np.cos(left_array[i])) - r
                z1[i] = (r * np.sin(left_array[i]))
                viz.vertexColor(grey)
                viz.vertex(x1[i], .1, z1[i])
                i += 1
        else:
            viz.vertex(0, .1, 100.0)  #100m straight
        leftbend = viz.endlayer()
        leftbend.visible(0)
        leftbend.dynamic()

        leftbendlist.append(leftbend)
        rightbendlist.append(rightbend)

    return leftbendlist, rightbendlist
Esempio n. 14
0
	def __init__( self , speedMultiplier = 1.0, av_type = 0 ):
		print "Creating a person"
		self.speedMultiplier = speedMultiplier
		self.save_path = path.Path()
		self.in_quad = 0
		if av_type == 0:
			type = random.randrange(0,4)
			if type == 0:
				self.avatar = viz.add('male.cfg',viz.WORLD,scene=viz.MainScene)
			elif type == 1:
				self.avatar = viz.add('vcc_male.cfg',viz.WORLD,scene=viz.MainScene)
			elif type == 2:
				self.avatar = viz.add('female.cfg',viz.WORLD,scene=viz.MainScene)
			else:
				self.avatar = viz.add('vcc_female.cfg',viz.WORLD,scene=viz.MainScene)
		else:
			self.avatar = viz.add('vcc_male.cfg',viz.WORLD,scene=viz.MainScene)
			#Add the hat model
			self.hat = viz.add('tophat.3ds')
			self.hat.setScale([1,5,1])

			#Get the head bone of the avatar
			head = self.avatar.getBone('Bip01 Head')

			#Link the hat to the head
			HatLink = viz.link(head,self.hat)

			#Tweek the hat link so it fits snuggly on the head
			
			HatLink.preTrans( [0,0.1,-0.0] )
			HatLink.preEuler( [0,-10,0] )
			
		self.avatar.setPosition(quadSet.get_random_point())
		#self.save_path.setStart(self.avatar.getPosition())
		self.save_path.addPoint(self.avatar.getPosition(), 0)
		self.next_point = quadSet.get_quadrant(self.avatar.getPosition())[0].get_random_walk()
		self.next_speed = get_next_speed()
		self.save_path.addPoint(self.next_point, self.next_speed)
		self.coll = 0
		self.avatar.collideMesh()
		self.avatar.enable(viz.COLLIDE_NOTIFY)
		
		#setup the AR
		viz.startlayer(viz.QUADS)
		if av_type == 0:
			viz.vertexcolor(1,0,0)
		else:
			viz.vertexcolor(1,0,0)
		viz.linewidth(20)
		pos = self.avatar.getPosition()
		viz.vertex(-0.3,0,0)
		viz.vertex(0.3,0,0)
		viz.vertex(0.3,2,0)
		viz.vertex(-0.3,2,0)
		self.pointAR = viz.endlayer(viz.WORLD, viz.Scene2)
		self.pointAR.alpha(0.3)
		
		self.tracking_error = []
		self.arev = vizact.ontimer(.01,self.move_AR)
		
		self.myquadrants = [False,False,False,False,False,False,False,False]
		self.lastTime = 0
		self.timeNotVisible = 0
Esempio n. 15
0
def createSolidBox(min, max):
    viz.startlayer(viz.QUADS, "top")
    viz.vertexcolor(1.0, 0.5, 0.0)

    # top
    # viz.vertexcolor(0.0,1.0,0.0)
    viz.normal(0, 1, 0)
    viz.vertex(max[0], max[1], min[2])
    viz.vertex(min[0], max[1], min[2])
    viz.vertex(min[0], max[1], max[2])
    viz.vertex(max[0], max[1], max[2])

    viz.startlayer(viz.QUADS, "bottom")
    viz.vertexcolor(0.5, 0.5, 0.0)
    viz.linewidth(2.0)

    # bottom
    # viz.vertexcolor(1.0,0.5,0.0)
    viz.normal(0, -1, 0)
    viz.vertex(max[0], min[1], max[2])
    viz.vertex(min[0], min[1], max[2])
    viz.vertex(min[0], min[1], min[2])
    viz.vertex(max[0], min[1], min[2])

    viz.startlayer(viz.QUADS, "front")
    viz.vertexcolor(0.5, 0.5, 0.0)
    viz.linewidth(2.0)

    # front
    # viz.vertexcolor(1.0,0.0,0.0)
    viz.normal(0, 0, 1)
    viz.vertex(max[0], max[1], max[2])
    viz.vertex(min[0], max[1], max[2])
    viz.vertex(min[0], min[1], max[2])
    viz.vertex(max[0], min[1], max[2])

    viz.startlayer(viz.QUADS, "back")
    viz.vertexcolor(0.5, 0.5, 0.0)
    viz.linewidth(2.0)

    # back
    # viz.vertexcolor(1.0,1.0,0.0)
    viz.normal(0, 0, -1)
    viz.vertex(max[0], min[1], min[2])
    viz.vertex(min[0], min[1], min[2])
    viz.vertex(min[0], max[1], min[2])
    viz.vertex(max[0], max[1], min[2])

    viz.startlayer(viz.QUADS, "left")
    viz.vertexcolor(0.5, 0.5, 0.0)
    viz.linewidth(2.0)

    # left
    # viz.vertexcolor(0.0,0.0,1.0)
    viz.normal(-1, 0, 0)
    viz.vertex(min[0], max[1], max[2])
    viz.vertex(min[0], max[1], min[2])
    viz.vertex(min[0], min[1], min[2])
    viz.vertex(min[0], min[1], max[2])

    viz.startlayer(viz.QUADS, "right")
    viz.vertexcolor(0.5, 0.5, 0.0)
    viz.linewidth(2.0)

    # right
    # viz.vertexcolor(1.0,0.0,1.0)
    viz.normal(1, 0, 0)
    viz.vertex(max[0], max[1], min[2])
    viz.vertex(max[0], max[1], max[2])
    viz.vertex(max[0], min[1], max[2])
    viz.vertex(max[0], min[1], min[2])

    return viz.endlayer()
def BendMaker(radlist):
    """makes left and right road edges for for a given radii and return them in a list"""

    #needs to work with an array of radii

    rdsize = 500  # Hz size for curve length

    #left_array= np.arange(0.0, np.pi*1000)/1000 # arange(start,stop,step). Array with 3142(/1000) numbers.
    left_array = np.linspace(
        0.0, np.pi, rdsize
    )  #### creates evenly spaced 500 steps from 0 to pi for left radius turn to be made
    #right_array = np.arange(np.pi*1000, 0.0, -1)/1000  ##arange(start,stop,step). Array with 3142(/1000) numbers
    right_array = np.linspace(
        np.pi, 0.0,
        rdsize)  #### From pi to 0 in 500 steps (opposite for opposite corner)

    #### Above code creates gradual turns for the bends of varying radii.
    #### I would need less gradual spacing - spacing would have to be the same so all 500 points would in a straight line

    # left_array = np.linspace(0.0, 5000, rdsize)
    # right_array = np.linspace(5000, 0.0, rdsize)

    #### Code above did not create 2 straight lines
    #### However is did remove the curved bends and create random zig zags within the environment
    #### Clearly not what is needed but I now know that this parameter can manipulate the line bend
    #### At certain intervals, a one remaining straight line appear which was clearly the -1 in the radii pool
    #### Perhaps incorporating the the straight lines vertices in these left/right_array parameters mights create the staright lines I need?

    # left_array = viz.vertex(0+width,.1,100.0)
    # right_array = viz.vertex(0+width,.1,100.0)

    leftbendlist = []
    rightbendlist = []
    grey = [.8, .8, .8]
    for r in radlist:
        x1 = np.zeros(rdsize)
        z1 = np.zeros(rdsize)
        x2 = np.zeros(rdsize)
        z2 = np.zeros(rdsize)

        i = 0

        ##try using quad-strip for roads.
        viz.startLayer(viz.QUAD_STRIP)  # Investigate quad strips on google
        width = .1  #road width/2
        if r > 0:  #r=-1 means it is a straight.
            while i < rdsize:

                ######### COURTNEY EDITS BELOW #############

                #### I'm trying to place a straight road angled at each of the radii rather than the bends that are currently there.
                #### i.e. if the radii is greater than 0 and while i is smaller than the rdsize, plot vertices to create straight roads.
                #### The road will be created at an angle to create the radii that are being looped through.
                #### However, rdsize refers to the points on the curve, so without changing this I could have 500 small straight roads?
                #### Also would it more likely be that I'd have to specify angle for this to work? What is the relationship between angle and radii?
                #### rdsize creates the small squares that are put together to create the bend of the radius chosen, with x and z being their coordinates.
                ####

                # x1[i] = viz.vertex(0+width,.1,0)
                # z1[i] = viz.vertex(0-width,.1,0)
                # x2[i] = viz.vertex(0+width,.1,100.0) * right_array[i] #100m straight
                # z2[i] = viz.vertex(0-width,.1,100.0) * right_array[i] #100m straight
                # viz.vertexColor(grey)
                # i + = 1

                # I need to somehow incorporate the left and right arrary variables as these dictate which direction the straight bend should go
                # Perhaps multilping by the right array alongside indexing from the loop? Not sure how or why this could work
                # Might use np.tan() function? This creates a straight line that touches but does intersect a curve
                # Potential to use this to create a straight line that is at the tangent of the radii of the original bend?

                # One option could be to keep the origianl code all the same and just use the np.tan() function
                # In the hope that instead of creating a bend, it would create a straight line at a tangent of the bend

                # Or could use it with the edits I have a suggested above
                # i.e. I still might need to create a straight line with the left and right array variables (see below).

                # x1[i] = viz.vertex(0+width,.1,0)
                # z1[i] = viz.vertex(0-width,.1,0)
                # x2[i] = viz.vertex(0+width,.1,100.0) * np.tan(right_array[i]) #100m straight
                # z2[i] = viz.vertex(0-width,.1,100.0) * np.tan(right_array[i]) #100m straight
                # viz.vertexColor(grey)
                # i + = 1

                ####### np.tan() did not work. All bends were removed from the environment

                ######### COURTNEY EDITS ABOVE ############

                #need two vertices at each point to form quad vertices
                #inside edge
                x1[i] = ((r - width) * np.cos(right_array[i])) + r
                z1[i] = ((r - width) * np.sin(right_array[i]))
                #print (z1[i])
                viz.vertexColor(grey)
                viz.vertex(x1[i], .1, z1[i])

                #outside edge. #does it matter if it's overwritten?
                x1[i] = ((r + width) * np.cos(right_array[i])) + r
                z1[i] = ((r + width) * np.sin(right_array[i]))
                #print (z1[i])
                viz.vertexColor(grey)
                viz.vertex(x1[i], .1, z1[i])
                i += 1
        else:
            viz.vertexColor(grey)
            viz.vertex(0 + width, .1, 0)
            viz.vertex(0 - width, .1, 0)
            viz.vertex(0 + width, .1, 100.0)  #100m straight
            viz.vertex(0 - width, .1, 100.0)  #100m straight

        rightbend = viz.endlayer()
        rightbend.visible(0)
        rightbend.dynamic()

        ### Above codes for the bends towards the right handside.
        ### The X and Z coordinates help map the quad strips onto the environment.
        ### The else statement means that if r is less than zero, a straight is created.
        ### rdsize = 500 represents the curve length, however I do not want a curve anymore.
        ### This needs to be edited so quad strips can be connected at angles to created straight curves.
        ### Try altering the rdsize and running code to see how that affects the shape of the bend.

        i = 0
        viz.startLayer(viz.QUAD_STRIP)
        width = .1  #road width/2
        if r > 0:  #r=-1 means it is a straight.
            while i < rdsize:
                #need two vertices at each point to form quad vertices
                #inside edge
                x2[i] = ((r - width) * np.cos(left_array[i])) - r
                z2[i] = ((r - width) * np.sin(left_array[i]))
                #print (z1[i])
                viz.vertexColor(grey)
                viz.vertex(x2[i], .1, z2[i])

                #outside edge. #does it matter if it's overwritten?
                x1[2] = ((r + width) * np.cos(left_array[i])) - r
                z1[2] = ((r + width) * np.sin(left_array[i]))
                #print (z1[i])
                viz.vertexColor(grey)
                viz.vertex(x1[2], .1, z2[i])
                i += 1
        else:
            viz.vertexColor(grey)
            viz.vertex(0 + width, .1, 0)
            viz.vertex(0 - width, .1, 0)
            viz.vertex(0 + width, .1, 100.0)  #100m straight
            viz.vertex(0 - width, .1, 100.0)  #100m straight

        leftbend = viz.endlayer()
        leftbend.visible(0)
        leftbend.dynamic()

        ### Above codes for the left hand bends

        leftbendlist.append(leftbend)
        rightbendlist.append(rightbend)

    return leftbendlist, rightbendlist
def roadEdges():
	global inside_edge, outside_edge, trialtype_signed, rdsize, edge, trialtype
	
	if edge == 1: #if already drawn
		inside_edge.remove()
		outside_edge.remove()
	
	road_x = 0
	roadWidth = 3.0
	r = 60	
	x1 = np.zeros(rdsize)
	z1 = np.zeros(rdsize)
	x2 = np.zeros(rdsize)
	z2 = np.zeros(rdsize)	
	
	#normal edges
	if trialtype_signed > 0: #right curve
		##Outside Edge - Right
		# outside edge drawing of straight line
		i = 0
		viz.startlayer(viz.LINE_STRIP) 
		viz.linewidth(1)
		viz.vertex((road_x-(roadWidth/2)), .1, 0)
		viz.vertex((road_x-(roadWidth/2)), .1, straight_road)

		# outside edge drawing of right curve
		while i < rdsize:
			x1[i] = (r+(roadWidth/2))*np.cos(right_array[i]) + r
			z1[i] = (r+(roadWidth/2))*np.sin(right_array[i]) + straight_road				
			viz.vertex(x1[i], .1, z1[i] )				
			i += 1
		outside_edge = viz.endlayer()
		
		outside_edge.alpha(1)
		
		# inside edge drawing of straight line
		i = 0			
		viz.startlayer(viz.LINE_STRIP)
		viz.linewidth(1)
		viz.vertex(road_x-(roadWidth/2), 0.1, 0)
		viz.vertex(road_x-(roadWidth/2), 0.1, straight_road)

		# inside edge drawing of right curve
		while i < rdsize:
			x2[i] = (r-(roadWidth/2))*np.cos(right_array[i]) + r
			z2[i] = (r-(roadWidth/2))*np.sin(right_array[i]) + straight_road
			viz.vertex(x2[i], 0.1, z2[i])
			i += 1				
		inside_edge = viz.endlayer()
		
		inside_edge.alpha(1)
		
	elif trialtype_signed < 0: # left curve
		# outside edge drawing of straight line
		viz.startlayer(viz.LINE_STRIP)
		viz.linewidth(1)
		viz.vertex(road_x+(roadWidth/2), .1, 0)
		viz.vertex(road_x+(roadWidth/2), .1, straight_road)
		i = 0

		# outside edge drawing of left curve
		while i < rdsize:
			x1[i] = (r+(roadWidth/2))*np.cos(left_array[i]) - r
			z1[i] = (r+(roadWidth/2))*np.sin(left_array[i]) + straight_road
			viz.vertex(x1[i], .1, z1[i])				
			i += 1
		outside_edge = viz.endlayer()				
		
		outside_edge.alpha(1)
		
		# inside edge drawing of straight line
		viz.startlayer(viz.LINE_STRIP)
		viz.linewidth(1)			
		viz.vertex(road_x-(roadWidth/2), .1, 0)
		viz.vertex(road_x-(roadWidth/2), .1, straight_road)

		# inside edge drawing of left curve
		i = 0				
		while i < rdsize:
			x2[i] = (r-(roadWidth/2))*np.cos(left_array[i]) - r
			z2[i] = (r-(roadWidth/2))*np.sin(left_array[i]) + straight_road
			viz.vertex(x2[i], 0.1, z2[i])				
			i += 1
		inside_edge = viz.endlayer()
		
		inside_edge.alpha(1)
	edge = 1	
Esempio n. 18
0
	def __init__(self, texFile, **kw):
		
		viz.startlayer(viz.QUADS)
		self.node = viz.endlayer(**kw)
		
		vert = """
		uniform int light;
		uniform float osg_FrameTime;
		uniform mat4 osg_ViewMatrixInverse;
		
		void main(void)
		{
			/* Parameters are encoded in vertex color
			   r - Animation time offset
			   g - Animation speed
			   b - Particle Size
			*/
			
			//Compute alpha based on time
			float time = (osg_FrameTime+gl_Color.r)*gl_Color.g;
			
			//Animate vertex
			//gl_Vertex.xyz += gl_Normal*sin(time)*0.2;
			gl_Vertex.x += gl_Normal.x*sin(time)*0.2;
			gl_Vertex.z += gl_Normal.z*sin(time)*0.2;
			
			//Convert to eye space
			gl_Vertex.xyz = gl_ModelViewMatrix * gl_Vertex;
			
			//Extrude point
			gl_Vertex.x += (gl_MultiTexCoord0.x*2.0-1.0)*gl_Color.b;
			gl_Vertex.y += (gl_MultiTexCoord0.y*2.0-1.0)*gl_Color.b;
			
			//Save clip vertex in eye space
			gl_ClipVertex = gl_Vertex;
			
			//Convert to screen coordinates
			gl_Position = gl_ProjectionMatrix * gl_Vertex;
			gl_FogFragCoord = abs(gl_ClipVertex.z);
			gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;
		}
		"""

		frag = """
		uniform float fog;
		uniform sampler2D tex;
		void main(void)
		{
			gl_FragColor = texture2D(tex,gl_TexCoord[0].xy);
			float alpha = gl_FragColor.a;
			
			if(fog != 0.0) {
				float f = exp2(fog * gl_FogFragCoord);
				f = clamp(f, 0.0, 1.0);
				gl_FragColor = mix(gl_Fog.color, gl_FragColor, f);
			}

			gl_FragColor.a = alpha;
		}
		"""
		
		tex = viz.add(texFile)
		texUniform = viz.addUniformInt('tex',0)
		shader = viz.addShader(vert=vert,frag=frag)
		self.node.apply(shader)
		self.node.apply(texUniform)
#		self.node.apply(_fogUniform)
		self.node.disable(viz.CULLING)
		self.node.texture(tex)
		
		self.node.enable(viz.SAMPLE_ALPHA_TO_COVERAGE)
		self.node.disable(viz.BLEND)
		
		#Initialize remove list
		self.removeList = []
		self.removeList.append(shader)
		self.removeList.append(self.node)
		self.removeList.append(tex)
		self.removeList.append(texUniform)
Esempio n. 19
0
def createSolidBox(min,max):
	viz.startlayer(viz.QUADS, 'top') 
	viz.vertexcolor(1.0,0.5,0.0)
	
	#top
	#viz.vertexcolor(0.0,1.0,0.0)
	viz.normal(0,1,0)
	viz.vertex( max[0], max[1], min[2])
	viz.vertex( min[0], max[1], min[2])
	viz.vertex( min[0], max[1], max[2])
	viz.vertex( max[0], max[1], max[2])

	viz.startlayer(viz.QUADS,'bottom') 
	viz.vertexcolor(.5,.5,0.0)
	viz.linewidth(2.0)
	
	#bottom
	#viz.vertexcolor(1.0,0.5,0.0)
	viz.normal(0,-1,0)
	viz.vertex( max[0], min[1], max[2])
	viz.vertex( min[0], min[1], max[2])
	viz.vertex( min[0], min[1], min[2])
	viz.vertex( max[0], min[1], min[2])

	viz.startlayer(viz.QUADS,'front') 
	viz.vertexcolor(.5,.5,0.0)
	viz.linewidth(2.0)
	
	#front
	#viz.vertexcolor(1.0,0.0,0.0)
	viz.normal(0,0,1)
	viz.vertex( max[0], max[1], max[2])
	viz.vertex( min[0], max[1], max[2])
	viz.vertex( min[0], min[1], max[2])
	viz.vertex( max[0], min[1], max[2])

	viz.startlayer(viz.QUADS,'back') 
	viz.vertexcolor(.5,.5,0.0)
	viz.linewidth(2.0)
	
	#back
	#viz.vertexcolor(1.0,1.0,0.0)
	viz.normal(0,0,-1)
	viz.vertex( max[0], min[1], min[2])
	viz.vertex( min[0], min[1], min[2])
	viz.vertex( min[0], max[1], min[2])
	viz.vertex( max[0], max[1], min[2])

	viz.startlayer(viz.QUADS,'left') 
	viz.vertexcolor(.5,.5,0.0)
	viz.linewidth(2.0)
	
	#left
	#viz.vertexcolor(0.0,0.0,1.0)		
	viz.normal(-1,0,0)
	viz.vertex( min[0], max[1], max[2])	
	viz.vertex( min[0], max[1], min[2])	
	viz.vertex( min[0], min[1], min[2])	
	viz.vertex( min[0], min[1], max[2])	

	viz.startlayer(viz.QUADS,'right') 
	viz.vertexcolor(.5,.5,0.0)
	viz.linewidth(2.0)
	
	#right
	#viz.vertexcolor(1.0,0.0,1.0)
	viz.normal(1,0,0)
	viz.vertex( max[0], max[1], min[2])	
	viz.vertex( max[0], max[1], max[2])	
	viz.vertex( max[0], min[1], max[2])	
	viz.vertex( max[0], min[1], min[2])	
	
	return viz.endlayer()
Esempio n. 20
0
node2D.setProjectionMatrix(viz.Matrix.ortho2D(0,HMDwidth,0,HMDheight))
node2D.setClearMask(0)
node2D.disable(viz.DEPTH_TEST)
#viz.startlayer(viz.LINES)
#viz.vertex([HMDwidth/2,0,0])
#viz.vertex([HMDwidth/2,HMDheight,0])
#viz.endlayer(viz.WORLD,viz.Scene3)

viz.startlayer(viz.LINES)
viz.vertexcolor([1,0,0])
viz.vertex([HMDwidth/2-10,HMDheight/2,0])
viz.vertex([HMDwidth/2+10,HMDheight/2,0])
viz.vertex([HMDwidth/2,HMDheight/2-10,0])
viz.vertex([HMDwidth/2,HMDheight/2+10,0])
viz.vertexcolor([1,1,1])
viz.endlayer(viz.WORLD,viz.Scene3)








ringbuffer_len = 20
yaw_ringbuffer = range(ringbuffer_len)
pitch_ringbuffer = range(ringbuffer_len)
roll_ringbuffer = range(ringbuffer_len)
for i in range(ringbuffer_len):
	yaw_ringbuffer[i] = 0
	pitch_ringbuffer[i] = 0