Rectification d'un bug d'affichage et remise en forme de certaines
parties des fichiers. Mise à jour du Makefile pour compiler le projet entier.
This commit is contained in:
parent
b155dc8fc8
commit
5fc8659d9b
16
Makefile
16
Makefile
|
@ -4,23 +4,19 @@ CCWARN=-Wall -Wextra -Werror
|
||||||
CFLAGS=-O3 $(CCWARN)
|
CFLAGS=-O3 $(CCWARN)
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: simple-terrain display roam
|
all: display
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: all
|
test: all
|
||||||
./simple-terrain | display
|
# ./simple-terrain | display
|
||||||
./display
|
./display
|
||||||
./roam
|
|
||||||
|
|
||||||
simple-terrain: simple-terrain.c Makefile
|
simple-terrain: simple-terrain.c
|
||||||
$(CC) $< -o $@
|
$(CC) $< -o $@
|
||||||
|
|
||||||
display: display.c Makefile
|
display: display.o roam.o
|
||||||
$(CC) -lGLEW -lSDL -lGLU $< $(CFLAGS) -o $@
|
$(CC) -lGLEW -lSDL -lGLU $^ -o $@
|
||||||
|
|
||||||
roam: roam.c Makefile
|
|
||||||
$(CC) $< $(CFLAGS) -o $@
|
|
||||||
|
|
||||||
# Create objects from C source code
|
# Create objects from C source code
|
||||||
%.o: %.c
|
%.o: %.c Makefile
|
||||||
$(CC) -c $< $(CFLAGS) -o $@
|
$(CC) -c $< $(CFLAGS) -o $@
|
||||||
|
|
13
display.c
13
display.c
|
@ -1,7 +1,7 @@
|
||||||
#include <SDL/SDL.h>
|
#include <SDL/SDL.h>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
#include "roam.c"
|
#include "roam.h"
|
||||||
|
|
||||||
int initWindow();
|
int initWindow();
|
||||||
int mainLoop();
|
int mainLoop();
|
||||||
|
@ -67,7 +67,7 @@ void drawAxes() {
|
||||||
void renderScene() {
|
void renderScene() {
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt(500,500,800,500,500,0,0,1,0);
|
gluLookAt(1024,512,1356,1024,512,0,0,1,0);
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
|
||||||
drawAxes();
|
drawAxes();
|
||||||
|
@ -81,9 +81,9 @@ void displayTree(Triangle *t) {
|
||||||
if(t->tLeftChild == NULL) {
|
if(t->tLeftChild == NULL) {
|
||||||
glBegin(GL_LINE_LOOP);
|
glBegin(GL_LINE_LOOP);
|
||||||
glColor3ub(255,255,255);
|
glColor3ub(255,255,255);
|
||||||
glVertex3d(t->vLeft->x,t->vLeft->y,20);
|
glVertex3d(t->vLeft->x,t->vLeft->y,1);
|
||||||
glVertex3d(t->vApex->x,t->vApex->y,1);
|
glVertex3d(t->vApex->x,t->vApex->y,1);
|
||||||
glVertex3d(t->vRight->x,t->vRight->y,0);
|
glVertex3d(t->vRight->x,t->vRight->y,1);
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -96,11 +96,6 @@ int main() {
|
||||||
initWindow();
|
initWindow();
|
||||||
t = initDefaultExample();
|
t = initDefaultExample();
|
||||||
|
|
||||||
triangle_split(t);
|
|
||||||
triangle_split(t->tLeftChild);
|
|
||||||
triangle_split(t->tLeftChild->tLeftChild);
|
|
||||||
triangle_split(t->tLeftChild->tRightChild);
|
|
||||||
|
|
||||||
mainLoop();
|
mainLoop();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
71
roam.c
71
roam.c
|
@ -1,3 +1,4 @@
|
||||||
|
#include "roam.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
/* Implémentation de ROAM
|
/* Implémentation de ROAM
|
||||||
|
@ -34,25 +35,6 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct Vertex {
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int z;
|
|
||||||
/* Ajouter des champs ici. */
|
|
||||||
} Vertex;
|
|
||||||
|
|
||||||
typedef struct Triangle {
|
|
||||||
Vertex* vApex;
|
|
||||||
Vertex* vLeft;
|
|
||||||
Vertex* vRight;
|
|
||||||
struct Triangle* tLeftChild;
|
|
||||||
struct Triangle* tRightChild;
|
|
||||||
struct Triangle* tBaseNeighbor;
|
|
||||||
struct Triangle* tLeftNeighbor;
|
|
||||||
struct Triangle* tRightNeighbor;
|
|
||||||
struct Triangle* tParent;
|
|
||||||
} Triangle;
|
|
||||||
|
|
||||||
int get_z(int x, int y) {
|
int get_z(int x, int y) {
|
||||||
x = x; /* Unused */
|
x = x; /* Unused */
|
||||||
y = y; /* Unused */
|
y = y; /* Unused */
|
||||||
|
@ -60,6 +42,7 @@ int get_z(int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void triangle_split(Triangle* t) {
|
void triangle_split(Triangle* t) {
|
||||||
|
printf("split (%d,%d) (%d,%d) (%d,%d)\n", t->vLeft->x, t->vLeft->y, t->vRight->x, t->vRight->y, t->vApex->x, t->vApex->y);
|
||||||
Triangle* b; /* base neighbor */
|
Triangle* b; /* base neighbor */
|
||||||
Vertex* c; /* center vertex */
|
Vertex* c; /* center vertex */
|
||||||
Triangle* subTLeft;
|
Triangle* subTLeft;
|
||||||
|
@ -72,6 +55,7 @@ void triangle_split(Triangle* t) {
|
||||||
if (b->tBaseNeighbor != t)
|
if (b->tBaseNeighbor != t)
|
||||||
/* T and its base neighbor aren't of the same LOD. */
|
/* T and its base neighbor aren't of the same LOD. */
|
||||||
triangle_split(b);
|
triangle_split(b);
|
||||||
|
b = t->tBaseNeighbor;
|
||||||
|
|
||||||
c = (Vertex*)malloc(sizeof(Vertex));
|
c = (Vertex*)malloc(sizeof(Vertex));
|
||||||
c->x = (t->vLeft->x + t->vRight->x) / 2;
|
c->x = (t->vLeft->x + t->vRight->x) / 2;
|
||||||
|
@ -97,12 +81,20 @@ void triangle_split(Triangle* t) {
|
||||||
/* Children */
|
/* Children */
|
||||||
subTLeft->tLeftChild = NULL;
|
subTLeft->tLeftChild = NULL;
|
||||||
subTLeft->tRightChild = NULL;
|
subTLeft->tRightChild = NULL;
|
||||||
/* Neighbors */
|
/* To neighbors */
|
||||||
subTLeft->tBaseNeighbor = t->tLeftNeighbor;
|
subTLeft->tBaseNeighbor = t->tLeftNeighbor;
|
||||||
subTLeft->tLeftNeighbor = subTRight;
|
subTLeft->tLeftNeighbor = subTRight;
|
||||||
subTLeft->tRightNeighbor = subBRight;
|
subTLeft->tRightNeighbor = subBRight;
|
||||||
/* Parent */
|
/* Parent */
|
||||||
subTLeft->tParent = t;
|
subTLeft->tParent = t;
|
||||||
|
/* From neighbors */
|
||||||
|
if (t->tLeftNeighbor != NULL) {
|
||||||
|
if (t->tLeftNeighbor->tBaseNeighbor == t) {
|
||||||
|
t->tLeftNeighbor->tBaseNeighbor = subTLeft;
|
||||||
|
} else {
|
||||||
|
t->tLeftNeighbor->tRightNeighbor = subTLeft;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* subTRight */
|
/* subTRight */
|
||||||
{
|
{
|
||||||
|
@ -113,12 +105,20 @@ void triangle_split(Triangle* t) {
|
||||||
/* Children */
|
/* Children */
|
||||||
subTRight->tLeftChild = NULL;
|
subTRight->tLeftChild = NULL;
|
||||||
subTRight->tRightChild = NULL;
|
subTRight->tRightChild = NULL;
|
||||||
/* Neighbors */
|
/* To neighbors */
|
||||||
subTRight->tBaseNeighbor = t->tRightNeighbor;
|
subTRight->tBaseNeighbor = t->tRightNeighbor;
|
||||||
subTRight->tLeftNeighbor = subBLeft;
|
subTRight->tLeftNeighbor = subBLeft;
|
||||||
subTRight->tRightNeighbor = subTLeft;
|
subTRight->tRightNeighbor = subTLeft;
|
||||||
/* Parent */
|
/* Parent */
|
||||||
subTRight->tParent = t;
|
subTRight->tParent = t;
|
||||||
|
/* From neighbors */
|
||||||
|
if (t->tRightNeighbor != NULL) {
|
||||||
|
if (t->tRightNeighbor->tBaseNeighbor == t) {
|
||||||
|
t->tRightNeighbor->tBaseNeighbor = subTRight;
|
||||||
|
} else {
|
||||||
|
t->tRightNeighbor->tLeftNeighbor = subTRight;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* subBLeft */
|
/* subBLeft */
|
||||||
if (b != NULL) {
|
if (b != NULL) {
|
||||||
|
@ -129,12 +129,20 @@ void triangle_split(Triangle* t) {
|
||||||
/* Children */
|
/* Children */
|
||||||
subBLeft->tLeftChild = NULL;
|
subBLeft->tLeftChild = NULL;
|
||||||
subBLeft->tRightChild = NULL;
|
subBLeft->tRightChild = NULL;
|
||||||
/* Neighbors */
|
/* To neighbors */
|
||||||
subBLeft->tBaseNeighbor = b->tLeftNeighbor;
|
subBLeft->tBaseNeighbor = b->tLeftNeighbor;
|
||||||
subBLeft->tLeftNeighbor = subBRight;
|
subBLeft->tLeftNeighbor = subBRight;
|
||||||
subBLeft->tRightNeighbor = subTRight;
|
subBLeft->tRightNeighbor = subTRight;
|
||||||
/* Parent */
|
/* Parent */
|
||||||
subBLeft->tParent = t;
|
subBLeft->tParent = t;
|
||||||
|
/* From neighbors */
|
||||||
|
if (b->tLeftNeighbor != NULL) {
|
||||||
|
if (b->tLeftNeighbor->tBaseNeighbor == b) {
|
||||||
|
b->tLeftNeighbor->tBaseNeighbor = subBLeft;
|
||||||
|
} else {
|
||||||
|
b->tLeftNeighbor->tRightNeighbor = subBLeft;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* subBRight */
|
/* subBRight */
|
||||||
if (b != NULL) {
|
if (b != NULL) {
|
||||||
|
@ -145,12 +153,20 @@ void triangle_split(Triangle* t) {
|
||||||
/* Children */
|
/* Children */
|
||||||
subBRight->tLeftChild = NULL;
|
subBRight->tLeftChild = NULL;
|
||||||
subBRight->tRightChild = NULL;
|
subBRight->tRightChild = NULL;
|
||||||
/* Neighbors */
|
/* To neighbors */
|
||||||
subBRight->tBaseNeighbor = b->tRightNeighbor;
|
subBRight->tBaseNeighbor = b->tRightNeighbor;
|
||||||
subBRight->tLeftNeighbor = subTLeft;
|
subBRight->tLeftNeighbor = subTLeft;
|
||||||
subBRight->tRightNeighbor = subBLeft;
|
subBRight->tRightNeighbor = subBLeft;
|
||||||
/* Parent */
|
/* Parent */
|
||||||
subBRight->tParent = t;
|
subBRight->tParent = t;
|
||||||
|
/* From neighbors */
|
||||||
|
if (b->tRightNeighbor != NULL) {
|
||||||
|
if (b->tRightNeighbor->tBaseNeighbor == b) {
|
||||||
|
b->tRightNeighbor->tBaseNeighbor = subBRight;
|
||||||
|
} else {
|
||||||
|
b->tRightNeighbor->tLeftNeighbor = subBRight;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
t->tLeftChild = subTLeft;
|
t->tLeftChild = subTLeft;
|
||||||
t->tRightChild = subTRight;
|
t->tRightChild = subTRight;
|
||||||
|
@ -240,9 +256,10 @@ Triangle* initDefaultExample() {
|
||||||
t->tRightNeighbor = NULL;
|
t->tRightNeighbor = NULL;
|
||||||
t->tParent = NULL;
|
t->tParent = NULL;
|
||||||
|
|
||||||
|
triangle_split(t);
|
||||||
|
triangle_split(t->tLeftChild);
|
||||||
|
triangle_split(t->tLeftChild->tLeftChild);
|
||||||
|
triangle_split(t->tLeftChild->tRightChild);
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main2() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user