Пример #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
Пример #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()
Пример #3
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
Пример #4
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 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	
Пример #6
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()
Пример #7
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)
    def __init__(self, startpos, bearing, clothoid_midline, road_width = 3.0, colour = viz.WHITE, primitive = viz.QUAD_STRIP, primitive_width=None, midline_step_size = .005, edge_step_size = .5, x_dir = 1, z_dir = 1, texturefile = None):

    #make sign -1 if you want a left bend.
        #improve to have a flag if it's a quad, and the quad width.
        print ("Creating a Bend")        

        self.RoadStart = startpos #2 dim xz array 
       
        self.Bearing = bearing
        
        self.RoadWidth = road_width		
        if self.RoadWidth == 0:
            self.HalfRoadWidth = 0
        else:
            self.HalfRoadWidth = road_width/2.0	
        
        self.Colour = colour
        
        self.Primitive = primitive
       
        self.PrimitiveWidth = primitive_width
        if primitive_width is None:
            if primitive == viz.QUAD_STRIP:
                primitive_width = .05
                self.primitive_width = primitive_width 

            elif primitive == viz.LINE_STRIP:
                self.primitive_width = 2
                viz.linewidth(self.primitive_width)
                primitive_width = 0 #so I can use the same code below for both primitive types.	
        
        
        self.BendLength = clothoid_midline ### need help!!!
        #### TODO!!!!!!
        self.MidlineStepSize = midline_step_size
        self.Midline_Points = int(round(self.BendLength / self.MidlineStepSize))
        
        self.EdgeStepSize = edge_step_size
        self.EdgePoints = int(round(self.BendLength / self.EdgeStepSize))

        self.Xdirection = x_dir

        """
        This needs updating for clothoid curve!!!

        if self.Xdirection > 0:
            
            self.RoadArray = np.linspace(np.pi, (np.pi - self.arc_angle), self.Edge_Pts) 
            self.MidlineArray = np.linspace(np.pi, (np.pi - self.arc_angle), self.Midline_Pts)  #right bend
        else:
            self.RoadArray = np.linspace(0.0, self.arc_angle, self.Edge_Pts)  #left bend
            self.MidlineArray = np.linspace(0.0, self.arc_angle, self.Midline_Pts)  
        """
        self.Zdirection = z_dir #[1, -1] 

        if self.RoadWidth == 0:
            self.MidlineEdge = self.EdgeMaker([self.RoadStart[0], ABOVEGROUND, self.RoadStart[1]], self.Bearing, primitive_width)
            self.InsideEdge = None
            self.OutsideEdge = None
        else:
            self.InsideEdgeClothoid = self.ClothoidMidline - (self.HalfRoadWidth)
            self.InsideEdgeStart = [self.RoadStart[0] - self.HalfRoadWidth, ABOVEGROUND, self.RoadStart[1]] 

            self.OutsideEdgeClothoid = self.ClothoidMidline + (self.RoadWidth/2.0)
            self.OutsideEdgeStart = [self.RoadStart[0]  +self.HalfRoadWidth, ABOVEGROUND, self.RoadStart[1]]

            self.InsideEdge = self.EdgeMaker(self.InsideEdge_Start, self.InsideEdge_Rads, primitive_width)
            self.OutsideEdge = self.EdgeMaker(self.OutsideEdge_Start, self.OutsideEdge_Rads, primitive_width)

            #make it so both edges have the same center. The setCenter is in local coordinates
            self.InsideEdge.setCenter([-self.HalfRoadWidth, 0, 0])
            self.OutsideEdge.setCenter([+self.HalfRoadWidth, 0, 0])		

            self.MidlineEdge = None

        self.midline = self.MidlineMaker()
        self.midline = np.add(self.midline, self.RoadStart)

        #CurveOrigin always starts at zero. We need to make it so curve origin equals the following.
        translate = self.Bearing * self.Xdirection
        self.CurveOrigin = np.add(self.RoadStart, [translate,0])
        print ("CurveOrigin: ", self.CurveOrigin)

        #this requires translating the bend position and the midline by the radius, in the opposite direction of X_direction.
        if self.RoadWidth == 0:
            self.MidlineEdge.setPosition([translate, 0, 0], mode = viz.REL_LOCAL)    
        else:
            self.InsideEdge.setPosition([translate, 0, 0], mode = viz.REL_LOCAL)
            self.OutsideEdge.setPosition([translate, 0, 0], mode = viz.REL_LOCAL)

        self.midline[:,0] = np.add(self.midline[:,0], translate)

        #ensure all bends start invisible.
        self.ToggleVisibility(viz.OFF)        
        
        self.Texturefile = texturefile
        if primitive == viz.QUAD_STRIP: 
            self.AddTexture()


        #add road end.
        self.RoadEnd = self.midline[-1,:]
Пример #9
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
Пример #10
0
    def __init__(self,
                 startpos,
                 length=50,
                 size=500,
                 z_dir=1,
                 colour=viz.WHITE,
                 primitive=viz.QUAD_STRIP,
                 primitive_width=None,
                 road_width=3.0,
                 texturefile=None,
                 midline_step_size=.005):
        """ultimately this class should inherit a super class called road section. But for now let's just make a straight"""
        """returns a straight, given some starting coords and length"""

        print('Creating vizStraight')

        self.RoadLength = length

        self.RoadStart = startpos  #2 dimensional x, z array.
        self.RoadEnd = [
            startpos[0], startpos[1] + (length * z_dir)
        ]  #currently only if it's north or south orientation. #2dim xz array
        self.midline_step_size = midline_step_size

        self.Midline_Pts = int(round(self.RoadLength / self.midline_step_size))

        #self.RoadSize_Pts = size
        self.RoadWidth = road_width
        if self.RoadWidth == 0:
            self.HalfRoadWidth = 0
        else:
            self.HalfRoadWidth = road_width / 2.0

        self.Z_direction = z_dir  #[1, -1]
        self.colour = colour
        self.primitive = primitive
        self.primitive_width = primitive_width

        if primitive_width is None:
            if primitive == viz.QUAD_STRIP:
                primitive_width = .05
                self.primitive_width = primitive_width

            elif primitive == viz.LINE_STRIP:
                self.primitive_width = 2
                viz.linewidth(self.primitive_width)
                primitive_width = 0  #so I can use the same code below for both primitive types.

        if self.RoadWidth == 0:
            self.MidlineEdge = self.StraightEdgeMaker(
                [self.RoadStart[0], ABOVEGROUND, self.RoadStart[1]],
                [self.RoadEnd[0], ABOVEGROUND, self.RoadEnd[1]],
                primitive_width)
            self.InsideEdge = None
            self.OutsideEdge = None
        else:
            self.InsideEdge_Start = [
                self.RoadStart[0] - self.HalfRoadWidth, ABOVEGROUND,
                self.RoadStart[1]
            ]
            self.InsideEdge_End = [
                self.RoadEnd[0] - self.HalfRoadWidth, ABOVEGROUND,
                self.RoadEnd[1]
            ]
            self.OutsideEdge_Start = [
                self.RoadStart[0] + self.HalfRoadWidth, ABOVEGROUND,
                self.RoadStart[1]
            ]
            self.OutsideEdge_End = [
                self.RoadEnd[0] + self.HalfRoadWidth, ABOVEGROUND,
                self.RoadEnd[1]
            ]

            self.InsideEdge = self.StraightEdgeMaker(self.InsideEdge_Start,
                                                     self.InsideEdge_End,
                                                     primitive_width)
            self.OutsideEdge = self.StraightEdgeMaker(self.OutsideEdge_Start,
                                                      self.OutsideEdge_End,
                                                      primitive_width)

            #make it so both edges have the same center. The setCenter is in local coordinates
            self.InsideEdge.setCenter([-self.HalfRoadWidth, 0, 0])
            self.OutsideEdge.setCenter([+self.HalfRoadWidth, 0, 0])

            self.MidlineEdge = None

        self.midline = self.StraightMidlineMaker()

        #ensure all bends start invisible.
        self.ToggleVisibility(viz.OFF)

        self.Texturefile = texturefile
        if primitive == viz.QUAD_STRIP:
            self.AddTexture()
Пример #11
0
    def __init__(self, startpos, rads, size = 500,  x_dir = 1, z_dir = 1, colour = viz.WHITE, primitive = viz.QUAD_STRIP, primitive_width=None, road_width = 3.0, texturefile = None, arc_angle = np.pi, midline_step_size = .005, edge_step_size = .5):
        """Returns a  bend of a specific road width, with functions to set the visibility, position, or Euler of both edges at once. Put road_width to 0 for single edge"""	

        """
        arc_angle is the length of the arc in radians. 
        step_size is the granulation of the midline road arrays, in metres
        size is the edge array size, doesn't need to be as granulated.
        """

        #make sign -1 if you want a left bend.
        #improve to have a flag if it's a quad, and the quad width.
        print ("Creating a Bend")        

        self.RoadStart = startpos #2 dim xz array 

        self.RoadWidth = road_width		
        if self.RoadWidth == 0:
            self.HalfRoadWidth = 0
        else:
            self.HalfRoadWidth = road_width/2.0		
        
        self.Rads = rads
        
        self.arc_angle = arc_angle
        
        circumference = 2 * np.pi * rads
        
        self.bend_length = (arc_angle / (2*np.pi)) * circumference
        print ("Bend_length:",self.bend_length)
        
        self.midline_step_size = midline_step_size
        
        self.edge_step_size = edge_step_size
        
        self.Edge_Pts = int(round(self.bend_length / self.edge_step_size))
        print ("Edge_Pts: ", self.Edge_Pts)
        
        self.Midline_Pts = int(round(self.bend_length / self.midline_step_size))
        print ("Midline_Pts: ", self.Midline_Pts)
        
        self.X_direction = x_dir

        if self.X_direction > 0:
            
            self.RoadArray = np.linspace(np.pi, (np.pi - self.arc_angle), self.Edge_Pts) 
            self.MidlineArray = np.linspace(np.pi, (np.pi - self.arc_angle), self.Midline_Pts)  #right bend
        else:
            self.RoadArray = np.linspace(0.0, self.arc_angle, self.Edge_Pts)  #left bend
            self.MidlineArray = np.linspace(0.0, self.arc_angle, self.Midline_Pts)  

        self.Z_direction = z_dir #[1, -1] 
        self.colour = colour
        self.primitive = primitive
        self.primitive_width = primitive_width
        
        if primitive_width is None:
            if primitive == viz.QUAD_STRIP:
                primitive_width = .05
                self.primitive_width = primitive_width 

            elif primitive == viz.LINE_STRIP:
                self.primitive_width = 2
                viz.linewidth(self.primitive_width)
                primitive_width = 0 #so I can use the same code below for both primitive types.		


        if self.RoadWidth == 0:
            self.MidlineEdge = self.EdgeMaker([self.RoadStart[0],ABOVEGROUND,self.RoadStart[1]], self.Rads, primitive_width)
            self.InsideEdge = None
            self.OutsideEdge = None
        else:
            self.InsideEdge_Rads = self.Rads-(self.HalfRoadWidth)
            self.InsideEdge_Start = [self.RoadStart[0]-self.HalfRoadWidth,ABOVEGROUND, self.RoadStart[1]] 

            self.OutsideEdge_Rads = self.Rads+(self.RoadWidth/2.0)
            self.OutsideEdge_Start = [self.RoadStart[0]+self.HalfRoadWidth,ABOVEGROUND, self.RoadStart[1]]

            self.InsideEdge = self.EdgeMaker(self.InsideEdge_Start, self.InsideEdge_Rads, primitive_width)
            self.OutsideEdge = self.EdgeMaker(self.OutsideEdge_Start, self.OutsideEdge_Rads, primitive_width)

            #make it so both edges have the same center. The setCenter is in local coordinates
            self.InsideEdge.setCenter([-self.HalfRoadWidth, 0, 0])
            self.OutsideEdge.setCenter([+self.HalfRoadWidth, 0, 0])		

            self.MidlineEdge = None
        
        self.midline = self.MidlineMaker()
        self.midline = np.add(self.midline, self.RoadStart)
        
        #CurveOrigin always starts at zero. We need to make it so curve origin equals the following.
        translate = self.Rads * self.X_direction
        self.CurveOrigin = np.add(self.RoadStart, [translate,0])
        print ("CurveOrigin: ", self.CurveOrigin)

        #this requires translating the bend position and the midline by the radius, in the opposite direction of X_direction.
        if self.RoadWidth == 0:
            self.MidlineEdge.setPosition([translate, 0, 0], mode = viz.REL_LOCAL)    
        else:
            self.InsideEdge.setPosition([translate, 0, 0], mode = viz.REL_LOCAL)
            self.OutsideEdge.setPosition([translate, 0, 0], mode = viz.REL_LOCAL)

        self.midline[:,0] = np.add(self.midline[:,0], translate)
        
        #ensure all bends start invisible.
        self.ToggleVisibility(viz.OFF)        
        
        self.Texturefile = texturefile
        if primitive == viz.QUAD_STRIP: 
            self.AddTexture()


        #add road end.
        self.RoadEnd = self.midline[-1,:]