AIGUY

02-23-2012, 01:29 PM

Hi,

I am writing a traffic simulation with path finding based on the A* algorithm. The A* algorithm returns a vector list of a struct Vector3 (made up of 3 float values - X,Y,Z), the first of the list being the starting node(position), and the last element of the list being the end node(goal position).

I have a class car which takes a vector3 as an argument, and initializes the position. The car class has a method draw car, which translates to the car position and draws a glutsolidcube. this method is called continuously within my renderscene method which is the argument of the glutDisplayFunc.

I'm wondering what is the best way to update the position iteratively to each position returned by the algorithm.

class Car

{

public:

Vector3 position;

Vector3 velocity;

double size;

float maxSpeed;

Graph graph;

vector<Connection> currentPath;

bool finishedPath;

Car(Vector3 initialPos, Graph g)

{

finishedPath = false;

graph = g;

size = 5;

position = initialPos;

currentPath = PathFindAStar(graph,0,4,Heuristic(4));

}

void DrawCar()

{

int time = glutGet(GLUT_ELAPSED_TIME);

glTranslatef(position.X, position.Y, position.Z);

glutSolidCube(size);

Update(time, nodePositions[currentPath.at(0).GetToNode()]);

}

void Update(int time, Vector3 nextTarget)

{

}

};

Thank you

I am writing a traffic simulation with path finding based on the A* algorithm. The A* algorithm returns a vector list of a struct Vector3 (made up of 3 float values - X,Y,Z), the first of the list being the starting node(position), and the last element of the list being the end node(goal position).

I have a class car which takes a vector3 as an argument, and initializes the position. The car class has a method draw car, which translates to the car position and draws a glutsolidcube. this method is called continuously within my renderscene method which is the argument of the glutDisplayFunc.

I'm wondering what is the best way to update the position iteratively to each position returned by the algorithm.

class Car

{

public:

Vector3 position;

Vector3 velocity;

double size;

float maxSpeed;

Graph graph;

vector<Connection> currentPath;

bool finishedPath;

Car(Vector3 initialPos, Graph g)

{

finishedPath = false;

graph = g;

size = 5;

position = initialPos;

currentPath = PathFindAStar(graph,0,4,Heuristic(4));

}

void DrawCar()

{

int time = glutGet(GLUT_ELAPSED_TIME);

glTranslatef(position.X, position.Y, position.Z);

glutSolidCube(size);

Update(time, nodePositions[currentPath.at(0).GetToNode()]);

}

void Update(int time, Vector3 nextTarget)

{

}

};

Thank you