Split semble fonctionner (pas vérifié les valeurs).
This commit is contained in:
parent
d853595738
commit
e710b49e77
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
simple-terrain
|
simple-terrain
|
||||||
display
|
display
|
||||||
|
roam
|
||||||
|
|
28
Makefile
28
Makefile
|
@ -1,8 +1,26 @@
|
||||||
all: simple-terrain
|
CC=gcc
|
||||||
|
# -ansi -pedantic -Wconversion
|
||||||
|
CCWARN=-Wall -Wextra -Werror
|
||||||
|
CFLAGS=-O3 $(CCWARN)
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
all: simple-terrain display roam
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test: all
|
||||||
./simple-terrain | display
|
./simple-terrain | display
|
||||||
|
./display
|
||||||
|
./roam
|
||||||
|
|
||||||
simple-terrain: simple-terrain.c
|
simple-terrain: simple-terrain.c Makefile
|
||||||
gcc simple-terrain.c -o simple-terrain
|
$(CC) $< -o $@
|
||||||
|
|
||||||
display: display.c
|
display: display.c Makefile
|
||||||
gcc -lGL -lSDL display.c -o display
|
$(CC) -lGL -lSDL $< $(CFLAGS) -o $@
|
||||||
|
|
||||||
|
roam: roam.c Makefile
|
||||||
|
$(CC) $< $(CFLAGS) -o $@
|
||||||
|
|
||||||
|
# Create objects from C source code
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) -c $< $(CFLAGS) -o $@
|
||||||
|
|
|
@ -3,13 +3,16 @@
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
short continuer;
|
||||||
|
SDL_Event event;
|
||||||
|
|
||||||
|
argc = argc; /* Unused */
|
||||||
|
argv = argv; /* Unused */
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
SDL_WM_SetCaption("Mon premier programme OpenGL !",NULL);
|
SDL_WM_SetCaption("Mon premier programme OpenGL !",NULL);
|
||||||
SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
|
SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
|
||||||
|
|
||||||
short continuer = 1;
|
continuer = 1;
|
||||||
SDL_Event event;
|
|
||||||
|
|
||||||
while (continuer) {
|
while (continuer) {
|
||||||
SDL_WaitEvent(&event);
|
SDL_WaitEvent(&event);
|
||||||
|
|
||||||
|
|
187
roam.c
187
roam.c
|
@ -1,3 +1,5 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
/* Implémentation de ROAM
|
/* Implémentation de ROAM
|
||||||
* http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.22.1811&rep=rep1&type=pdf
|
* http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.22.1811&rep=rep1&type=pdf
|
||||||
*
|
*
|
||||||
|
@ -36,7 +38,7 @@ typedef struct Vertex {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int z;
|
int z;
|
||||||
// Ajouter des champs ici.
|
/* Ajouter des champs ici. */
|
||||||
} Vertex;
|
} Vertex;
|
||||||
|
|
||||||
typedef struct Triangle {
|
typedef struct Triangle {
|
||||||
|
@ -51,84 +53,141 @@ typedef struct Triangle {
|
||||||
struct Triangle* tParent;
|
struct Triangle* tParent;
|
||||||
} Triangle;
|
} Triangle;
|
||||||
|
|
||||||
int get_z(x,y) {
|
int get_z(int x, int y) {
|
||||||
|
x = x; /* Unused */
|
||||||
|
y = y; /* Unused */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void triangle_split(Triangle* t) {
|
void triangle_split(Triangle* t) {
|
||||||
if (t->baseNeighbor != NULL)
|
Triangle* b; /* base neighbor */
|
||||||
// T and its base neighbor aren't of the same LOD.
|
Vertex* c; /* center vertex */
|
||||||
if (t->baseNeighbor->baseNeighbor != t)
|
Triangle* subTLeft;
|
||||||
triangle_split(t->baseNeighbor);
|
Triangle* subTRight;
|
||||||
Vertex* c = (Vertex*)malloc(sizeof(Vertex));
|
Triangle* subBLeft;
|
||||||
|
Triangle* subBRight;
|
||||||
|
|
||||||
|
b = t->tBaseNeighbor;
|
||||||
|
if (b != NULL)
|
||||||
|
if (b->tBaseNeighbor != t)
|
||||||
|
/* T and its base neighbor aren't of the same LOD. */
|
||||||
|
triangle_split(b);
|
||||||
|
|
||||||
|
c = (Vertex*)malloc(sizeof(Vertex));
|
||||||
c->x = (t->vLeft->x + t->vRight->x) / 2;
|
c->x = (t->vLeft->x + t->vRight->x) / 2;
|
||||||
c->y = (t->vLeft->y + t->vRight->y) / 2;
|
c->y = (t->vLeft->y + t->vRight->y) / 2;
|
||||||
c->z = get_z(c->x, c->y);
|
c->z = get_z(c->x, c->y);
|
||||||
|
|
||||||
Triangle* t1 = (Triangle*)malloc(sizeof(Triangle));
|
subTLeft = (Triangle*)malloc(sizeof(Triangle));
|
||||||
t1->vApex = c;
|
subTRight = (Triangle*)malloc(sizeof(Triangle));
|
||||||
t1->vLeft = t->vApex;
|
if (b != NULL) {
|
||||||
t1->vRight = t->vLeft;
|
subBLeft = (Triangle*)malloc(sizeof(Triangle));
|
||||||
t1->tLeftChild = NULL;
|
subBRight = (Triangle*)malloc(sizeof(Triangle));
|
||||||
t1->tRightChild = NULL;
|
|
||||||
// v-- Left or right, doesn't matter.
|
|
||||||
if (t->tParent == NULL) {
|
|
||||||
t1->tBaseNeighbor = NULL;
|
|
||||||
} else {
|
} else {
|
||||||
if (t->tParent->tRightChild->tRightChild == NULL) {
|
subBLeft = NULL;
|
||||||
t1->tBaseNeighbor = t->tParent->tRightChild;
|
subBRight = NULL;
|
||||||
} else {
|
|
||||||
t1->tBaseNeighbor = t->tParent->tRightChild->tRightChild;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Triangle* t2 = malloc(sizeof(Triangle));
|
/* subTLeft */
|
||||||
t2->vApex = c;
|
{
|
||||||
t2->vLeft = t->vRight;
|
/* Vertices */
|
||||||
t2->vRight = t->vApex;
|
subTLeft->vApex = c;
|
||||||
t2->tLeftChild = NULL;
|
subTLeft->vLeft = t->vApex;
|
||||||
t2->tRightChild = NULL;
|
subTLeft->vRight = t->vLeft;
|
||||||
// v-- Left or right, doesn't matter.
|
/* Children */
|
||||||
if (t->tParent->tLeftChild->tLeftChild == NULL) {
|
subTLeft->tLeftChild = NULL;
|
||||||
t2->tBaseNeighbor = t->tParent->tLeftChild;
|
subTLeft->tRightChild = NULL;
|
||||||
} else {
|
/* Neighbors */
|
||||||
t2->tBaseNeighbor = t->tParent->tLeftChild->tLeftChild;
|
subTLeft->tBaseNeighbor = t->tLeftNeighbor;
|
||||||
|
subTLeft->tLeftNeighbor = subTRight;
|
||||||
|
subTLeft->tRightNeighbor = subBRight;
|
||||||
|
/* Parent */
|
||||||
|
subTLeft->tParent = t;
|
||||||
}
|
}
|
||||||
t->tLeftChild = t1;
|
/* subTRight */
|
||||||
t->tRightChild = t2;
|
{
|
||||||
|
/* Vertices */
|
||||||
// Split tBaseNeighbor
|
subTRight->vApex = c;
|
||||||
Triangle* tb = t->tBaseNeighbor;
|
subTRight->vLeft = t->vRight;
|
||||||
if (tb == NULL) return;
|
subTRight->vRight = t->vApex;
|
||||||
|
/* Children */
|
||||||
Triangle* t1 = malloc(sizeof(Triangle));
|
subTRight->tLeftChild = NULL;
|
||||||
t1->vApex = c;
|
subTRight->tRightChild = NULL;
|
||||||
t1->vLeft = tb->vApex;
|
/* Neighbors */
|
||||||
t1->vRight = tb->vLeft;
|
subTRight->tBaseNeighbor = t->tRightNeighbor;
|
||||||
t1->tLeftChild = NULL;
|
subTRight->tLeftNeighbor = subBLeft;
|
||||||
t1->tRightChild = NULL;
|
subTRight->tRightNeighbor = subTLeft;
|
||||||
// v-- Left or right, doesn't matter.
|
/* Parent */
|
||||||
if (tb->tParent->tRightChild->tRightChild == NULL) {
|
subTRight->tParent = t;
|
||||||
t1->tBaseNeighbor = tb->tParent->tRightChild;
|
|
||||||
} else {
|
|
||||||
t1->tBaseNeighbor = tb->tParent->tRightChild->tRightChild;
|
|
||||||
}
|
}
|
||||||
|
/* subBLeft */
|
||||||
Triangle* t2 = malloc(sizeof(Triangle));
|
if (b != NULL) {
|
||||||
t2->vApex = c;
|
/* Vertices */
|
||||||
t2->vLeft = tb->vRight;
|
subBLeft->vApex = c;
|
||||||
t2->vRight = tb->vApex;
|
subBLeft->vLeft = b->vApex;
|
||||||
t2->tLeftChild = NULL;
|
subBLeft->vRight = t->vRight; /* == b->vLeft, mais a plus de chances d'être dans le cache, non ? */
|
||||||
t2->tRightChild = NULL;
|
/* Children */
|
||||||
// v-- Left or right, doesn't matter.
|
subBLeft->tLeftChild = NULL;
|
||||||
if (tb->tParent->tLeftChild->tLeftChild == NULL) {
|
subBLeft->tRightChild = NULL;
|
||||||
t2->tBaseNeighbor = tb->tParent->tLeftChild;
|
/* Neighbors */
|
||||||
} else {
|
subBLeft->tBaseNeighbor = b->tLeftNeighbor;
|
||||||
t2->tBaseNeighbor = tb->tParent->tLeftChild->tLeftChild;
|
subBLeft->tLeftNeighbor = subBRight;
|
||||||
|
subBLeft->tRightNeighbor = subTRight;
|
||||||
|
/* Parent */
|
||||||
|
subBLeft->tParent = t;
|
||||||
|
}
|
||||||
|
/* subBRight */
|
||||||
|
if (b != NULL) {
|
||||||
|
/* Vertices */
|
||||||
|
subBRight->vApex = c;
|
||||||
|
subBRight->vLeft = t->vLeft; /* == b->vRight, mais a plus de chances d'être dans le cache, non ? */
|
||||||
|
subBRight->vRight = b->vApex;
|
||||||
|
/* Children */
|
||||||
|
subBRight->tLeftChild = NULL;
|
||||||
|
subBRight->tRightChild = NULL;
|
||||||
|
/* Neighbors */
|
||||||
|
subBRight->tBaseNeighbor = b->tRightNeighbor;
|
||||||
|
subBRight->tLeftNeighbor = subTLeft;
|
||||||
|
subBRight->tRightNeighbor = subBLeft;
|
||||||
|
/* Parent */
|
||||||
|
subBRight->tParent = t;
|
||||||
|
}
|
||||||
|
t->tLeftChild = subTLeft;
|
||||||
|
t->tRightChild = subTRight;
|
||||||
|
if (b != NULL) {
|
||||||
|
b->tLeftChild = subBLeft;
|
||||||
|
b->tRightChild = subBRight;
|
||||||
}
|
}
|
||||||
tb->tLeftChild = t1;
|
|
||||||
tb->tRightChild = t2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void triangle_merge(Triangle* T) {
|
void triangle_merge(Triangle* T) {
|
||||||
|
T = T;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Triangle* t = (Triangle*)malloc(sizeof(Triangle));
|
||||||
|
Vertex* vApex = (Vertex*)malloc(sizeof(Vertex));
|
||||||
|
Vertex* vLeft = (Vertex*)malloc(sizeof(Vertex));
|
||||||
|
Vertex* vRight = (Vertex*)malloc(sizeof(Vertex));
|
||||||
|
|
||||||
|
vApex->x = 1024; vApex->y = 1024; vApex->z = 0;
|
||||||
|
vLeft->x = 0; vLeft->y = 0; vLeft->z = 0;
|
||||||
|
vRight->x = 2048; vRight->y = 0; vRight->z = 0;
|
||||||
|
|
||||||
|
t->vApex = vApex;
|
||||||
|
t->vLeft = vLeft;
|
||||||
|
t->vRight = vRight;
|
||||||
|
t->tLeftChild = NULL;
|
||||||
|
t->tRightChild = NULL;
|
||||||
|
t->tBaseNeighbor = NULL;
|
||||||
|
t->tLeftNeighbor = NULL;
|
||||||
|
t->tRightNeighbor = NULL;
|
||||||
|
t->tParent = NULL;
|
||||||
|
|
||||||
|
triangle_split(t);
|
||||||
|
triangle_split(t->tLeftChild);
|
||||||
|
triangle_split(t->tLeftChild->tLeftChild);
|
||||||
|
triangle_split(t->tLeftChild->tRightChild);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user