added a bunch of features, preparing to read from obj files for display
This commit is contained in:
parent
6b04973314
commit
34e70de2f9
11 changed files with 567 additions and 377 deletions
60
reader.c
Normal file
60
reader.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
#include "c3dtypes.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int TestFunc(int x) {
|
||||
x = x + 1;
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
Object ReadObjectFromFile() {
|
||||
Object out;
|
||||
out.VertexArray = malloc(10000*sizeof(Vector3));
|
||||
out.VertexArrayLength = 0;
|
||||
|
||||
TriArray tarr;
|
||||
tarr.arr = malloc(10000*sizeof(Tri));
|
||||
tarr.length = 0;
|
||||
|
||||
|
||||
out.triangles = &tarr;
|
||||
|
||||
strncpy(out.name, "cube.obj", 100);
|
||||
|
||||
|
||||
FILE * f = fopen("cube.obj", "r");
|
||||
|
||||
while (true) {
|
||||
char t[500];
|
||||
char * fgetres = fgets(t, 500, f);
|
||||
if (fgetres == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
char objtype[10];
|
||||
double v1;
|
||||
double v2;
|
||||
double v3;
|
||||
sscanf(t, "%s %lf %lf %lf", objtype, &v1,&v2,&v3);
|
||||
if ( strcmp(t, "v")) {
|
||||
out.VertexArray[out.VertexArrayLength].x = v1;
|
||||
out.VertexArray[out.VertexArrayLength].x = v2;
|
||||
out.VertexArray[out.VertexArrayLength].x = v3;
|
||||
out.VertexArrayLength = out.VertexArrayLength + 1;
|
||||
}
|
||||
if ( strcmp(t, "f")) {
|
||||
//TODO: append face to triarry
|
||||
}
|
||||
//need to bring in triarray functions into their own file
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//TODO: use file object and read each line
|
||||
// add verticies to the vertex list, +1 ing the length value each time
|
||||
// just fucking parse the obj file its not that hard
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue