Commit 38bf7742 authored by Scott Duensing's avatar Scott Duensing

Initial commit. Before switching to stretchy_buffer from utarray.

parents
*.user
*.~
# Blender3D v249 OBJ File: untitled.blend
# www.blender3d.org
mtllib cube.mtl
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
vt 0.748573 0.750412
vt 0.749279 0.501284
vt 0.999110 0.501077
vt 0.999455 0.750380
vt 0.250471 0.500702
vt 0.249682 0.749677
vt 0.001085 0.750380
vt 0.001517 0.499994
vt 0.499422 0.500239
vt 0.500149 0.750166
vt 0.748355 0.998230
vt 0.500193 0.998728
vt 0.498993 0.250415
vt 0.748953 0.250920
vn 0.000000 0.000000 -1.000000
vn -1.000000 -0.000000 -0.000000
vn -0.000000 -0.000000 1.000000
vn -0.000001 0.000000 1.000000
vn 1.000000 -0.000000 0.000000
vn 1.000000 0.000000 0.000001
vn 0.000000 1.000000 -0.000000
vn -0.000000 -1.000000 0.000000
usemtl Material_ray.png
s off
f 5/1/1 1/2/1 4/3/1
f 5/1/1 4/3/1 8/4/1
f 3/5/2 7/6/2 8/7/2
f 3/5/2 8/7/2 4/8/2
f 2/9/3 6/10/3 3/5/3
f 6/10/4 7/6/4 3/5/4
f 1/2/5 5/1/5 2/9/5
f 5/1/6 6/10/6 2/9/6
f 5/1/7 8/11/7 6/10/7
f 8/11/7 7/12/7 6/10/7
f 1/2/8 2/9/8 3/13/8
f 1/2/8 3/13/8 4/14/8
JOEY = /home/scott/joey
include($$JOEY/dist/joey.pri)
HEADERS += \
utarray.h
SOURCES += \
main.c
OTHER_FILES += \
postlink.sh \
notes.txt \
cube.obj
linux:QMAKE_POST_LINK = $$PWD/postlink.sh "$$PWD" "$$JOEY"
#include <stdio.h>
#include <math.h>
#include "utarray.h"
#define JOEY_MAIN
#include "joey.h"
#ifdef JOEY_IIGS
segment "j3d";
#endif
#pragma GCC diagnostic push
//#pragma GCC diagnostic ignored "-Wcast-align"
typedef struct {
float x;
float y;
float z;
} j3VertexT;
typedef struct {
j3VertexT local[3];
j3VertexT world[3];
j3VertexT camera[3];
} j3TriangleT;
typedef struct {
UT_array *verticies;
UT_array *triangles;
} j3ObjectT;
typedef struct {
UT_array *objects;
} j3WorldT;
static UT_icd j3VertexT_icd = { sizeof(j3VertexT), NULL, NULL, NULL };
static UT_icd j3TriangleT_icd = { sizeof(j3TriangleT), NULL, NULL, NULL };
static UT_icd j3WorldT_icd = { sizeof(j3WorldT), NULL, NULL, NULL };
bool j3WorldLoad(char *file, j3WorldT *world);
bool j3WorldLoad(char *file, j3WorldT *world) {
int r;
int x;
char token[1024];
char *c;
FILE *in;
j3VertexT *vp;
j3VertexT v;
j3ObjectT o;
j3TriangleT t;
in = fopen(jlUtilMakePathname(file, "obj"), "rt");
// Did we find the file?
if (in == NULL) {
// Nope.
return false;
}
// Initialize object array inside world object
utarray_new(world->objects, &j3WorldT_icd);
// Create an initial object to read data into (***TODO*** support multiple objects)
utarray_new(o.verticies, &j3VertexT_icd);
utarray_new(o.triangles, &j3TriangleT_icd);
while (true) {
// Read next token
r = fscanf(in, "%s", token);
//printf("fscanf s = %d [%s]\n", r, token);
// End of file?
if (r == EOF) {
break;
}
// Vertex?
if (strcmp(token, "v" ) == 0) {
r = fscanf(in, "%f %f %f\n", &v.x, &v.y, &v.z);
//printf("fscanf f f f = %d [%s]\n", r, token);
//printf("Vertex: %f %f %f\n", v.x, v.y, v.z);
utarray_push_back(o.verticies, &v);
}
// Face?
if (strcmp(token, "f" ) == 0) {
//printf("Triangle:\n");
for (x=0; x<3; x++) {
// Fetch 'x'th vertex index
r = fscanf(in, "%s", token);
//printf("fscanf s = %d [%s]\n", r, token);
c = strstr(token, "/");
if (c) c[0] = 0;
r = atoi(token);
//printf("atoi = %d\n", r);
vp = (j3VertexT *)utarray_eltptr(o.verticies, (unsigned int)r - 1);
t.local[x] = *vp;
//printf(" Face Index: %s Vertex: %f %f %f\n", token, vp->x, vp->y, vp->z);
}
fscanf(in, "\n");
utarray_push_back(o.triangles, &t);
}
}
// Finished! Clean up.
fclose(in);
return true;
}
int main(void) {
j3WorldT world;
j3ObjectT *object;
jlUtilStartup("JoeyLib 3D");
j3WorldLoad("cube", &world);
printf("Made it here\n");
object = (j3ObjectT *)utarray_front(world.objects);
printf("Verticies: %d\n", utarray_len(object->verticies));
printf("Triangles: %d\n", utarray_len(object->triangles));
jlKeyWaitForAny();
jlUtilShutdown();
}
#pragma GCC diagnostic pop
#!/bin/bash
GAME=$1
export JOEY=$2
mkdir -p data
cp -f "${GAME}"/*.obj data/.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment