Définition d'une structure de route plus avancée. Test de génération
d'une route avec cette structure et affichage de la route en la parcourant.
This commit is contained in:
parent
2829a36da4
commit
aad21c89e8
76
roads.c
76
roads.c
|
@ -28,27 +28,30 @@ void roads(Polygon* quartier) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fonctions de Yoann suffixée par "Y" */
|
/* Fonctions de Yoann suffixée par "Y" */
|
||||||
/* Cette structure définie un noad de route. Les champs next et previous permettent d'avancer
|
/* Cette structure définie un nœd de route. Le nœd contient la liste de toute les intersections.
|
||||||
* ou de reculler sur la route tant que l'on ne rencontre pas d'intersections avec une ou
|
|
||||||
* plusieurs autre routes. Dans ce dernier cas next er previous se retrouvent à NULL.
|
|
||||||
*/
|
*/
|
||||||
typedef struct roadNodeY {
|
typedef struct roadNodeY {
|
||||||
Vertex *v;
|
Vertex *v;
|
||||||
struct roadNodeY *next;
|
|
||||||
struct roadNodeY *previous;
|
|
||||||
short nbIntersec;
|
short nbIntersec;
|
||||||
struct intersection *intersec;
|
struct intersectionY *intersec;
|
||||||
} roadNodeY;
|
} roadNodeY;
|
||||||
|
|
||||||
/* Définition d'une intersection. Permet de savoir quelle route est concernée par cette intersection.
|
/* Définition d'une intersection. Permet de savoir quelle route est concernée par cette intersection.
|
||||||
* Elle permet également de changer la navigation por parcourir une nouvelle route.
|
* Elle permet également de changer la navigation por parcourir une nouvelle route.
|
||||||
* */
|
* */
|
||||||
typedef struct intersection {
|
typedef struct intersectionY {
|
||||||
roadNodeY roadId; // Premier nœd de la route qui lui sert d'identifiant.
|
roadNodeY roadId; // Premier nœd de la route qui lui sert d'identifiant.
|
||||||
roadNodeY *next; // Nœd de la route juste après l'intersection.
|
roadNodeY *next; // Nœd de la route juste après l'intersection.
|
||||||
roadNodeY *previous; // Nœd de la route juste avant l'intersection.
|
roadNodeY *previous; // Nœd de la route juste avant l'intersection.
|
||||||
int zIndex; // Index sur l'axe z de la route.
|
int zIndex; // Index sur l'axe z de la route.
|
||||||
} intersection;
|
} intersectionY;
|
||||||
|
|
||||||
|
typedef struct roadPointY {
|
||||||
|
struct roadPointY *first;
|
||||||
|
struct roadPointY *next;
|
||||||
|
struct roadPointY *previous;
|
||||||
|
roadNodeY *rn;
|
||||||
|
} roadPointY;
|
||||||
|
|
||||||
const int maxSubDivision = 6; // Nombre de subdivisions max en hauteur et largeur.
|
const int maxSubDivision = 6; // Nombre de subdivisions max en hauteur et largeur.
|
||||||
|
|
||||||
|
@ -63,6 +66,21 @@ int toY(int y) {
|
||||||
return y/maxSubDivision;
|
return y/maxSubDivision;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addRoadNode(roadPointY *rp, roadNodeY *rn) {
|
||||||
|
if(rp->rn == NULL) {
|
||||||
|
rp->next = NULL;
|
||||||
|
rp->rn = rn;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while(rp->next != NULL)
|
||||||
|
rp = rp->next;
|
||||||
|
|
||||||
|
roadPointY *rpp = (roadPointY*) malloc(sizeof(roadPointY));
|
||||||
|
rpp->next = NULL;
|
||||||
|
rpp->rn = rn;
|
||||||
|
rp->next = rpp;
|
||||||
|
}
|
||||||
|
|
||||||
void carreY() {
|
void carreY() {
|
||||||
roadNodeY ***nodesGrid = (roadNodeY***) malloc(sizeof(roadNodeY**)*maxSubDivision);
|
roadNodeY ***nodesGrid = (roadNodeY***) malloc(sizeof(roadNodeY**)*maxSubDivision);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -71,32 +89,32 @@ void carreY() {
|
||||||
for(i=0;i<maxSubDivision;i++) {
|
for(i=0;i<maxSubDivision;i++) {
|
||||||
nodesGrid[i] = (roadNodeY**) malloc(sizeof(roadNodeY*)*maxSubDivision);
|
nodesGrid[i] = (roadNodeY**) malloc(sizeof(roadNodeY*)*maxSubDivision);
|
||||||
for(j=0;j<maxSubDivision;j++) {
|
for(j=0;j<maxSubDivision;j++) {
|
||||||
roadNodeY *rn = (roadNodeY*) malloc(sizeof(roadNodeY));
|
nodesGrid[i][j] = NULL;
|
||||||
rn->v = (Vertex*) malloc(sizeof(Vertex));
|
|
||||||
rn->v->x = i*size/maxSubDivision;
|
|
||||||
rn->v->y = j*size/maxSubDivision;
|
|
||||||
rn->next = NULL;
|
|
||||||
rn->previous = NULL;
|
|
||||||
nodesGrid[i][j] = rn;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int a,b;
|
roadPointY *roada = (roadPointY*) malloc(sizeof(roadPointY));
|
||||||
for(i=0;i<maxSubDivision;i++) {
|
roadNodeY *rn;
|
||||||
for(j=0;j<maxSubDivision;j++) {
|
Vertex *v;
|
||||||
roadNodeY *rn = nodesGrid[i][j];
|
|
||||||
while(rn != NULL) {
|
for(i=0;i<30;i++) {
|
||||||
for(a=i-1;a<=i+1;a++) {
|
rn = (roadNodeY*)malloc(sizeof(roadNodeY));
|
||||||
for(b=j-1;b<=j+1;b++) {
|
v = (Vertex*) malloc(sizeof(Vertex));
|
||||||
if(a >= 0 && a < maxSubDivision && b >= 0 && b < maxSubDivision) {
|
|
||||||
svg_line(rn->v,nodesGrid[a][b]->v);
|
v->x = (i+1)*16;
|
||||||
}
|
v->y = ((i+1)%3)*(61%(i+1))+100;
|
||||||
}
|
rn->v = v;
|
||||||
}
|
addRoadNode(roada,rn);
|
||||||
rn = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
roadPointY *rd = roada;
|
||||||
|
while(rd->next != NULL) {
|
||||||
|
svg_line(rd->rn->v,rd->next->rn->v);
|
||||||
|
|
||||||
|
rd = rd->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size=size;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user