Commit 06cc056b authored by Scott Duensing's avatar Scott Duensing

Basic wireframe rendering on PC. IIgs not working yet.

parent 38bf7742
font.xcf filter=lfs diff=lfs merge=lfs -text
*.user
*.~
*.user
*.sta
*.dis
*.lnk
*.map
*.sym
#!/bin/bash -e
PROJECT=j3d
GAME=${JOEY}/j3d/j3d
DATA=(${GAME}/cube.obj ${GAME}/font.sta)
#SOURCE=(*.c *.h)
SOURCE=()
pushd "${GAME}"
find . -type f -name "*.xcf" -exec ${JOEY}/utils/xcf2sta.sh {} \;
popd
#. ${JOEY}/dist/IIgs/build-IIgs.helper.sh
. ${JOEY}/joeylib/scripts/build-IIgs.helper.sh
. ${JOEY}/joeylib/scripts/build-PC.helper.sh
if [[ "$1x" == "x" ]]; then
#buildLinux32
buildLinux64
#buildWindows32
buildWindows64
fi
buildIIgs $1
File added
This diff is collapsed.
/*
* JoeyLib 3D
* Copyright (C) 2019 Scott Duensing <scott@kangaroopunch.com>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef H_J3D_
#define H_J3D_
#include "joey.h"
typedef float j3Matrix4x4T[4][4];
typedef struct {
float x;
float y;
float z;
} j3VertexT;
typedef struct {
j3VertexT local; // Original vertex positions
j3VertexT world; // After rotation, scale, translation (in that order)
j3VertexT camera; // Camera space
} j3CoordinatesT;
typedef struct {
int index[3]; // We do this instead of just a typedef so it works with stretch_buffer
} j3TriangleT;
typedef struct {
int vertexCount; // How many verticies are in the list
int triangleCount; // How many triangles are in the list
j3CoordinatesT *verticies; // List of verticies as loaded from disk (more v1, v2, v3 than x, y, z)
j3TriangleT *triangles; // Triangles built from vertex list
j3VertexT position; // Position of object in world
j3VertexT rotation; // Rotation of object in world
j3VertexT scale; // Scale of object in world
} j3ObjectT;
typedef struct {
j3ObjectT *objects;
} j3WorldT;
#define jtCameraSetClippingBounds(x1, y1, x2, y2) \
clipMinX = (x1); j3MathCheckBounds(clipMinX, 0, 319); \
clipMinY = (y1); j3MathCheckBounds(clipMiny, 0, 199); \
clipMaxX = (x2); j3MathCheckBounds(clipMaxX, 0, 319); \
clipMaxY = (y2); j3MathCheckBounds(clipMaxy, 0, 199)
#define j3MathCheckBounds(value, min, max) \
if (value < (min)) value = (min); \
if (value > (max)) value = (max)
#define j3MathWrapBounds(value, min, max) \
if (value < (min)) value += (max); \
if (value > (max)) value -= (max)
#define j3ObjectMove(ob, px, py, pz) \
ob.position.x += (px); \
ob.position.y += (py); \
ob.position.z += (pz)
#define j3ObjectMoveTo(ob, px, py, pz) \
ob.position.x = (px); \
ob.position.y = (py); \
ob.position.z = (pz)
#define j3ObjectRotate(ob, px, py, pz) \
ob.rotation.x += (px); j3MathWrapBounds(ob.rotation.x, 0, 360); \
ob.rotation.y += (py); j3MathWrapBounds(ob.rotation.y, 0, 360); \
ob.rotation.z += (pz); j3MathWrapBounds(ob.rotation.z, 0, 360)
#define j3ObjectRotateTo(ob, px, py, pz) \
ob.rotation.x = (px); j3MathWrapBounds(ob.rotation.x, 0, 360); \
ob.rotation.y = (py); j3MathWrapBounds(ob.rotation.y, 0, 360); \
ob.rotation.z = (pz); j3MathWrapBounds(ob.rotation.z, 0, 360)
#define j3ObjectScale(ob, px, py, pz) \
ob.scale.x += (px); \
ob.scale.y += (py); \
ob.scale.z += (pz)
#define j3ObjectScaleTo(ob, px, py, pz) \
ob.scale.x = (px); \
ob.scale.y = (py); \
ob.scale.z = (pz)
// Syntatic sugar
#define j3DrawWireframe(o) _j3DrawWireframe(&(o))
#define j3ObjectReset(o) _j3ObjectReset(&(o))
#define j3ObjectUpdate(o) _j3ObjectUpdate(&(o))
#define j3WorldFree(w) _j3WorldFree((j3WorldT **)&(w))
#define j3WorldLoad(w, f) _j3WorldLoad((j3WorldT **)&(w), (f))
// Prototypes
void j3MathMatrix4x4Identity(j3Matrix4x4T result);
void j3MathMatrix4x4Mult(j3Matrix4x4T a, j3Matrix4x4T b, j3Matrix4x4T result);
void j3UtilShutdown(void);
void j3UtilStartup(void);
// Private Prototypes
void _j3DrawWireframePair(j3ObjectT *o, int v1, int v2);
void _j3DrawWireframe(j3ObjectT *o);
void _j3ObjectReset(j3ObjectT *o);
void _j3ObjectUpdate(j3ObjectT *o);
bool _j3UtilClipLine(int *x1, int *y1, int *x2, int *y2);
void _j3WorldFree(j3WorldT **world);
bool _j3WorldLoad(j3WorldT **world, char *file);
#endif // H_J3D_
......@@ -2,12 +2,15 @@ JOEY = /home/scott/joey
include($$JOEY/dist/joey.pri)
HEADERS += \
utarray.h
stretchy_buffer.h \
j3d.h
SOURCES += \
main.c
main.c \
j3d.c
OTHER_FILES += \
build-All.sh \
postlink.sh \
notes.txt \
cube.obj
......
#include <stdio.h>
#include <math.h>
/*
* JoeyLib 3D
* Copyright (C) 2019 Scott Duensing <scott@kangaroopunch.com>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#include "utarray.h"
#include <stdio.h>
#include <string.h>
#define JOEY_MAIN
#include "joey.h"
#ifdef JOEY_IIGS
segment "j3d";
segment "j3dTest";
#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 };
#include "j3d.h"
bool j3WorldLoad(char *file, j3WorldT *world);
void printAt(jlStaT *font, jint16 x, jint16 y, char *string) {
juint16 i;
byte c;
jint16 sx = x;
jint16 tx;
jint16 ty;
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;
for (i=0; i<strlen(string); i++) {
c = (byte)string[i];
tx = c % 40;
ty = c / 40;
jlDrawBlit8x8(font, tx, ty, sx++, y);
}
}
// 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);
int main(void) {
jlStaT *font = NULL;
j3WorldT *world = NULL;
bool r;
return true;
}
jlUtilStartup("JoeyLib 3D");
jlStaLoad(font, "font");
printAt(font, 1, 1, "Starting JoeyLib3D...");
jlDisplayPresent();
j3UtilStartup();
printAt(font, 1, 1, "Loading object... ");
jlDisplayPresent();
r = j3WorldLoad(world, "cube");
if (r) {
printAt(font, 1, 1, "Object loading: Success!");
jlDisplayPresent();
} else {
printAt(font, 1, 1, "Object loading: Failed.");
jlDisplayPresent();
}
//***TODO*** Add methods to inspect world/object information
//printf("Verticies: %d\n", sb_count(world->objects[0].verticies));
//printf("Triangles: %d\n", sb_count(world->objects[0].triangles));
int main(void) {
j3ObjectMoveTo(world->objects[0], 0, 0, 300); // Matching values in code I'm studying
j3ObjectScaleTo(world->objects[0], 30, 30, 30); // Matching values in code I'm studying
j3WorldT world;
j3ObjectT *object;
while (!jlKeyPressed() && !jlUtilMustExit()) {
j3ObjectRotate(world->objects[0], 2, 4, 6); // Matching values in code I'm studying
j3ObjectUpdate(world->objects[0]);
jlUtilStartup("JoeyLib 3D");
jlDrawColor(0);
jlDrawClear();
j3WorldLoad("cube", &world);
jlDrawColor(15);
jlDrawBox(0, 0, 319, 199);
j3DrawWireframe(world->objects[0]);
printf("Made it here\n");
jlDisplayPresent();
}
jlKeyRead();
object = (j3ObjectT *)utarray_front(world.objects);
printf("Verticies: %d\n", utarray_len(object->verticies));
printf("Triangles: %d\n", utarray_len(object->triangles));
j3WorldFree(world);
jlStaFree(font);
jlKeyWaitForAny();
j3UtilShutdown();
jlUtilShutdown();
}
#pragma GCC diagnostic pop
......@@ -3,5 +3,10 @@
GAME=$1
export JOEY=$2
pushd "${GAME}"
find . -type f -name "*.xcf" -exec ${JOEY}/utils/xcf2sta.sh {} \;
popd
mkdir -p data
cp -f "${GAME}"/*.sta 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