setup examples and clean codebase

This commit is contained in:
PedroEdiaz
2024-12-03 22:18:48 -06:00
parent f8eb20c0cf
commit f514fc7ffe
9 changed files with 516 additions and 438 deletions

View File

@@ -2,29 +2,43 @@
#include <stdio.h>
int create_surface_klein( unsigned char * path, struct surface * surface )
/*
KLEIN Format:
5 bytes with KLEIN
1 byte empty for scaling
1 byte with the dimention of the surface
8 bytes interprated as a long with the number of vertex
n bytes with the vertex data of the surface
n bytes with the normal data of the surface
where n is the size of the vertex and normal data that could be
calculated as the dimention of the surface time the number of vertes
time the size of a 16 bytes float.
*/
int create_surface_klein(unsigned char *path, struct surface *surface)
{
unsigned long size;
char buffer[5];
FILE * file = fopen(path, "rb" );
if( !file )
FILE *file = fopen(path, "rb");
if (!file)
return 1;
fread(buffer, 1, 5, file );
fread(buffer, 1, 5, file);
if( strncmp(buffer, "KLEIN", 5 ) )
if (strncmp(buffer, "KLEIN", 5))
return 1;
fread(buffer, 1, 1, file );
fread(buffer, 1, 1, file);
fread(&surface->dim, 1, 1, file);
fread(&surface->vertex, 8, 1, file);
size = surface->dim * surface->vertex;
surface->data=malloc(16*size );
fread(surface->data, 16,size, file);
surface->data = malloc(16 * size);
fread(surface->data, 16, size, file);
surface->norm=malloc(16*size );
surface->norm = malloc(16 * size);
fread(surface->norm, 16, size, file);
return 0;
}