Exemplo n.º 1
0
def drawPathsPrep(nodeDict, distanceDict):
	"""Make the lists we'll need for drawing everything."""
	
	lines = []
	points = []

#	i = 5

	keyList = distanceDict.keys()
	keyList.sort()

	for key in keyList:
#		i = i - 1
#		if i == 0:
#			break
		nodeA = key[0:6]
		nodeB = key[6:12]
		tupleA = map_to_points.getCoords(nodeA, nodeDict)
		tupleB = map_to_points.getCoords(nodeB, nodeDict)

		(x, y) = tupleA
		(x2, y2) = tupleB

#		print "%s: (%f, %f) and (%f, %f, %f, %f)" % (key, x, y, x, y, x2, y2)

		points.extend([x, y, x2, y2])

		lines.extend([x, y, x2, y2])

	return (points, lines)
Exemplo n.º 2
0
def drawPathsPrep(nodeDict, distanceDict):
    """Make the lists we'll need for drawing everything."""

    lines = []
    points = []

    #	i = 5

    keyList = distanceDict.keys()
    keyList.sort()

    for key in keyList:
        #		i = i - 1
        #		if i == 0:
        #			break
        nodeA = key[0:6]
        nodeB = key[6:12]
        tupleA = map_to_points.getCoords(nodeA, nodeDict)
        tupleB = map_to_points.getCoords(nodeB, nodeDict)

        (x, y) = tupleA
        (x2, y2) = tupleB

        #		print "%s: (%f, %f) and (%f, %f, %f, %f)" % (key, x, y, x, y, x2, y2)

        points.extend([x, y, x2, y2])

        lines.extend([x, y, x2, y2])

    return (points, lines)
Exemplo n.º 3
0
    def recalcVelocity(self):
        """Move the car."""

        nodeDict = self.simulationHandle.getMap().getNodeDict()

        # First we get ourselves a goal

        if self.currentNode == self.goalNode:
            self.getNextTarget()

        currentX, currentY = map_to_points.getCoords(self.currentTarget,
                                                     nodeDict)

        xDiff = currentX - self.xPosition
        yDiff = currentY - self.yPosition

        dist = math.sqrt(math.pow(xDiff, 2) + math.pow(yDiff, 2))

        angleToTarget = math.atan2(yDiff, xDiff)
        angleToTarget = math.degrees(angleToTarget)

        self.idealAngle = angleToTarget
        self.angle = angleToTarget

        if dist < 0.2:
            #			print "\tArrived at target node '%s'." % (self.currentTarget)
            self.currentNode = self.currentTarget
            self.getNextTarget()
Exemplo n.º 4
0
def drawPathsPrep(nodeDict, distanceDict):
    """Make the lists we'll need for drawing everything."""

    lines = []
    points = []

    keyList = distanceDict.keys()
    keyList.sort()

    for key in keyList:
        nodeA = key[0:6]
        nodeB = key[6:12]
        tupleA = map_to_points.getCoords(nodeA, nodeDict)
        tupleB = map_to_points.getCoords(nodeB, nodeDict)

        (x, y) = tupleA
        (x2, y2) = tupleB

        points.extend([x, y, x2, y2])

        lines.extend([x, y, x2, y2])

    return (points, lines)
Exemplo n.º 5
0
def drawSpecialPath(path, nodeDict, height, lineWidth, pointRadius):
    """Make the lists we'll need for drawing everything."""

    points = []

    for i in range(len(path)):
        point = path[i]
        (x, y) = map_to_points.getCoords(point, nodeDict)
        points.extend([x, y])

    glLineWidth(lineWidth)
    glPointSize(pointRadius)

    glColor4f(0.882, 0.0, 0.376, 1.0)
    glNormal3f(0.0, 0.0, 1.0)

    glDisable(GL_TEXTURE_2D)

    glLoadIdentity()

    glBegin(GL_LINES)

    for i in range(len(path) - 1):
        glVertex3f(points[i * 2], height - points[i * 2 + 1], 0.2)
        glVertex3f(points[(i + 1) * 2], height - points[(i + 1) * 2 + 1], 0.2)

    glEnd()

    glBegin(GL_POINTS)

    for i in range(len(path)):
        glVertex3f(points[i * 2], height - points[i * 2 + 1], 0.21)

    glEnd()

    glEnable(GL_TEXTURE_2D)
Exemplo n.º 6
0
class Car(SimulationObject):
	"""Our little car class."""

	accelerationPercent = 0.0
	accelerationMax = 2.0
	brakePercent = 0.0
	brakeMax = 1.0
	currentNode = ""
	goalNode = ""
	pathToGoal = ""
	currentTarget = ""

	def __init__(self):
		"""Initialize everything."""

		textureFile = "Objects/Car/car_texture.png"

		SimulationObject.__init__(self) # Initialize base class stuff

		self.className = "Vehicles"
		self.subclassName = "Car"
		self.moveable = True

		self.drawableHandle = car_video.makeDisplayList()

		tempHandle = VideoRoutines.getTexture(textureFile)

		if tempHandle:
			self.textureHandle = tempHandle
		else:
			self.textureHandle = VideoRoutines.loadTexture(textureFile, False)

		self.currentNode = ""
		self.goalNode = ""
		self.pathToGoal = []
		self.currentTarget = ""

	def getGoalNode(self):
		"""Get the current goal node."""
		return self.goalNode

	def setGoalNode(self, newGoal):
		"""Set a new goal node."""
		self.goalNode = newGoal

	def getCurrentTarget(self):
		"""Get the current target of this object."""
		return self.currentTarget

	def getCurrentNode(self):
		"""Get the current node (the one we're closest to)."""
		return self.currentNode

	def calculateNewPath(self):
		"""Get a new path for us to follow."""

		nodeDict = self.simulationHandle.getMap().getNodeDict()
		distDict = self.simulationHandle.getMap().getDistDict()

		self.path = pathfinder.findPath(self.currentNode, self.goalNode, nodeDict, distDict)

	def getNextTarget(self):
		"""Set the current target to the next node along the path."""

		if self.path == []:
			self.decideOnGoal()
			self.calculateNewPath()
	
		self.currentTarget = self.path.pop(0)		

	def draw(self):
		"""Draw this object."""

		car_video.drawMe(self)

	def decideOnGoal(self):
		"""Decided on what our next goal will be."""

		self.goalNode = self.simulationHandle.getMap().getRandomNode()

	def moveObject(self, time):
		"""Move the car."""

		nodeDict = self.simulationHandle.getMap().getNodeDict()

		# First we get ourselves a goal

		if self.currentNode = self.goalNode:
			self.getNextTarget()

		currentX, currentY = map_to_points.getCoords(self.currentTarget, nodeDict)

		xDiff = currentX - self.xPosition
		yDiff = currentY - self.yPosition

		dist = math.sqrt(math.pow(xDiff, 2) + math.pow(yDiff, 2))

		angleToTarget = math.atan2(yDiff, xDiff)
		angleToTarget = math.degrees(angleToTarget)

		self.idealAngle = angleToTarget

		if dist < 0.2:
			self.currentNode = self.currentTarget
			self.getNextTarget()

		# Then we let the default moveObject move us

		SimulationObject.moveObject(self, time)