コード例 #1
0
ファイル: maze.py プロジェクト: Niklaren/scripting---dynamics
def get_separation_heading(agent_name, neighbours):
	# initialise the heading vector that will hold the separation heading
	separation_heading_vector = [0, 0, 0]
	heading_vector = [0, 0, 0]

	# get the number of neighbouring agents in the neighbours list [find the length of the list]
	number_of_neighbours = len(neighbours)
	# IF we have 1 or more agents in the neighbours list
	if number_of_neighbours > 0:
		# get the position of the agent called agent_name
		agent_pos = agent_name.get_agent_position()
		# FOR every neighbour in the neighbours list
		for neighbour in neighbours:
			# get the position of the neighbour
			neighbour_pos = neighbour.get_agent_position()
			# calculate the heading vector from the neighbours position to the position of our agent
			heading_vector = vectorMath.get_vector_between_points(neighbour_pos, agent_pos)
			# normalise the heading vector to give it a size of 1 [needed so averaging the vector will work as expected
			heading_vector = vectorMath.vector_normalise(heading_vector)
			# add this heading vector to the separation_heading_vector
			separation_heading_vector = vectorMath.vector_add(separation_heading_vector, heading_vector)
		# calculate the averaged separation_heading_vector
		separation_heading_vector[0] = separation_heading_vector[0] / number_of_neighbours
		separation_heading_vector[1] = separation_heading_vector[1] / number_of_neighbours
		separation_heading_vector[2] = separation_heading_vector[2] / number_of_neighbours
		# normalise the separation_heading_vector
		separation_heading_vector = vectorMath.vector_normalise(separation_heading_vector)
	
	return separation_heading_vector
コード例 #2
0
def get_separation_heading(agent_name, neighbours):
    # initialise the heading vector that will hold the separation heading
    separation_heading_vector = [0, 0, 0]
    heading_vector = [0, 0, 0]

    # get the number of neighbouring agents in the neighbours list [find the length of the list]
    number_of_neighbours = len(neighbours)
    # IF we have 1 or more agents in the neighbours list
    if number_of_neighbours > 0:
        # get the position of the agent called agent_name
        agent_pos = agent_name.get_agent_position()
        # FOR every neighbour in the neighbours list
        for neighbour in neighbours:
            # get the position of the neighbour
            neighbour_pos = neighbour.get_agent_position()
            # calculate the heading vector from the neighbours position to the position of our agent
            heading_vector = vectorMath.get_vector_between_points(
                neighbour_pos, agent_pos)
            # normalise the heading vector to give it a size of 1 [needed so averaging the vector will work as expected
            heading_vector = vectorMath.vector_normalise(heading_vector)
            # add this heading vector to the separation_heading_vector
            separation_heading_vector = vectorMath.vector_add(
                separation_heading_vector, heading_vector)
        # calculate the averaged separation_heading_vector
        separation_heading_vector[
            0] = separation_heading_vector[0] / number_of_neighbours
        separation_heading_vector[
            1] = separation_heading_vector[1] / number_of_neighbours
        separation_heading_vector[
            2] = separation_heading_vector[2] / number_of_neighbours
        # normalise the separation_heading_vector
        separation_heading_vector = vectorMath.vector_normalise(
            separation_heading_vector)

    return separation_heading_vector
コード例 #3
0
def get_cohesion_heading(agent_name, neighbours):
    # initialise the heading vector that will hold the separation heading
    cohesion_heading_vector = [0, 0, 0]

    # get the number of neighbouring agents in the neighbours list [find the length of the list]
    number_of_neighbours = len(neighbours)
    # IF we have 1 or more agents in the neighbours list
    if number_of_neighbours > 0:
        # get the position of the agent called agent_name
        agent_pos = agent_name.get_agent_position()
        # initialise a a vector to hold the average of all the neighbours positions to [0, 0, 0]
        neighbours_average_vector = [0, 0, 0]
        #FOR every neighbour in the neighbours list
        for neighbour in neighbours:
            # get the neighbours position
            neighbour_pos = neighbour.get_agent_position()
            # add it to the vector to hold the average positions
            neighbours_average_vector = vectorMath.vector_add(
                neighbours_average_vector, neighbour_pos)
        # calculate the averaged neighbours position
        neighbours_average_vector[
            0] = neighbours_average_vector[0] / number_of_neighbours
        neighbours_average_vector[
            1] = neighbours_average_vector[1] / number_of_neighbours
        neighbours_average_vector[
            2] = neighbours_average_vector[2] / number_of_neighbours
        # calculate the cohesion_heading_vector from the position of the agent called agent_name to the averaged neighbours position
        cohesion_heading_vector = vectorMath.get_vector_between_points(
            agent_pos, neighbours_average_vector)
        # normalise the cohesion_heading_vector
        cohesion_heading_vector = vectorMath.vector_normalise(
            cohesion_heading_vector)
    return cohesion_heading_vector
コード例 #4
0
def get_alignment_heading(neighbours):
    # initialise the heading vector that will hold the alignment heading
    alignment_heading_vector = [0, 0, 0]
    neighbour_vector = [0, 0, 0]
    # get the number of neighbouring agents in the neighbours list [find the length of the list]
    number_of_neighbours = len(neighbours)
    # IF we have 1 or more agents in the neighbours list
    if number_of_neighbours > 0:
        # FOR every neighbour in the neighbours list
        for neighbour in neighbours:
            # get the heading of the neighbour as a vector
            neighbour_vector = neighbour.get_agent_heading_vector()
            # add this heading to the alignment_heading_vector
            alignment_heading_vector = vectorMath.vector_add(
                alignment_heading_vector, neighbour_vector)
        # calculate the averaged alignment_heading_vector
        alignment_heading_vector[
            0] = alignment_heading_vector[0] / number_of_neighbours
        alignment_heading_vector[
            1] = alignment_heading_vector[1] / number_of_neighbours
        alignment_heading_vector[
            2] = alignment_heading_vector[2] / number_of_neighbours
        # normalise alignment vector
        alignment_heading_vector = vectorMath.vector_normalise(
            alignment_heading_vector)

    return alignment_heading_vector
コード例 #5
0
ファイル: maze.py プロジェクト: Niklaren/scripting---dynamics
def get_cohesion_heading(agent_name, neighbours):
	# initialise the heading vector that will hold the separation heading
	cohesion_heading_vector = [0, 0, 0]

	# get the number of neighbouring agents in the neighbours list [find the length of the list]
	number_of_neighbours = len(neighbours)
	# IF we have 1 or more agents in the neighbours list
	if number_of_neighbours > 0:
		# get the position of the agent called agent_name
		agent_pos = agent_name.get_agent_position()
		# initialise a a vector to hold the average of all the neighbours positions to [0, 0, 0]
		neighbours_average_vector = [0, 0, 0]
		#FOR every neighbour in the neighbours list
		for neighbour in neighbours:
			# get the neighbours position
			neighbour_pos = neighbour.get_agent_position()
			# add it to the vector to hold the average positions
			neighbours_average_vector = vectorMath.vector_add(neighbours_average_vector, neighbour_pos)
		# calculate the averaged neighbours position
		neighbours_average_vector[0] = neighbours_average_vector[0] / number_of_neighbours
		neighbours_average_vector[1] = neighbours_average_vector[1] / number_of_neighbours
		neighbours_average_vector[2] = neighbours_average_vector[2] / number_of_neighbours
		# calculate the cohesion_heading_vector from the position of the agent called agent_name to the averaged neighbours position
		cohesion_heading_vector = vectorMath.get_vector_between_points(agent_pos, neighbours_average_vector)
		# normalise the cohesion_heading_vector
		cohesion_heading_vector = vectorMath.vector_normalise(cohesion_heading_vector)
	return cohesion_heading_vector
コード例 #6
0
ファイル: maze.py プロジェクト: Niklaren/scripting---dynamics
def get_goal_heading(agent):
	# initialise the heading vector that will hold the  goal heading
	goal_heading_vector = [0, 0, 0]
	
	# if we have reached the end of the path or otherwise require a new goal do it here
	if(pathfinding.need_new_goal(agent.get_goal(),agent.get_rounded_pos())):
		agent.new_goal()
	
	# check if we need to start heading towards the next step in the path
	agent.check_step()
	
	#get goal vector from our current position and the next spot in our path
	goal_heading_vector = vectorMath.get_vector_between_points(agent.get_agent_position(),agent.get_current_step())
	
	# normalise goal vector
	goal_heading_vector = vectorMath.vector_normalise(goal_heading_vector)
	
	return goal_heading_vector
コード例 #7
0
def get_goal_heading(agent):
    # initialise the heading vector that will hold the  goal heading
    goal_heading_vector = [0, 0, 0]

    # if we have reached the end of the path or otherwise require a new goal do it here
    if (pathfinding.need_new_goal(agent.get_goal(), agent.get_rounded_pos())):
        agent.new_goal()

    # check if we need to start heading towards the next step in the path
    agent.check_step()

    #get goal vector from our current position and the next spot in our path
    goal_heading_vector = vectorMath.get_vector_between_points(
        agent.get_agent_position(), agent.get_current_step())

    # normalise goal vector
    goal_heading_vector = vectorMath.vector_normalise(goal_heading_vector)

    return goal_heading_vector
コード例 #8
0
ファイル: maze.py プロジェクト: Niklaren/scripting---dynamics
def get_alignment_heading(neighbours):
	# initialise the heading vector that will hold the alignment heading
	alignment_heading_vector = [0, 0, 0]
	neighbour_vector = [0, 0, 0]
	# get the number of neighbouring agents in the neighbours list [find the length of the list]
	number_of_neighbours = len(neighbours)
	# IF we have 1 or more agents in the neighbours list
	if number_of_neighbours > 0:
		# FOR every neighbour in the neighbours list
		for neighbour in neighbours:
			# get the heading of the neighbour as a vector
			neighbour_vector = neighbour.get_agent_heading_vector()
			# add this heading to the alignment_heading_vector
			alignment_heading_vector = vectorMath.vector_add(alignment_heading_vector, neighbour_vector)
		# calculate the averaged alignment_heading_vector
		alignment_heading_vector[0] = alignment_heading_vector[0] / number_of_neighbours
		alignment_heading_vector[1] = alignment_heading_vector[1] / number_of_neighbours
		alignment_heading_vector[2] = alignment_heading_vector[2] / number_of_neighbours
		# normalise alignment vector
		alignment_heading_vector = vectorMath.vector_normalise(alignment_heading_vector)
	
	return alignment_heading_vector