Commit 99de9c6b authored by Scott Duensing's avatar Scott Duensing

Backface removal, solid drawing, and basic lighting.

parent d2fd766c
This diff is collapsed.
......@@ -27,13 +27,22 @@
#include "joey.h"
//***TODO*** verticies is vertices
typedef float j3Matrix4x4T[4][4];
typedef struct {
jint16 x;
jint16 y;
jint16 z;
} j3FacingT;
typedef struct {
float x;
float y;
float z;
} j3VertexT;
} j3VertexT, j3Vector3DT;
typedef struct {
j3VertexT local; // Original vertex positions
......@@ -42,7 +51,13 @@ typedef struct {
} j3CoordinatesT;
typedef struct {
juint16 index[3]; // We do this instead of just a typedef so it works with stretch_buffer
jint16 color; // Assigned color of this face
jint16 shade; // Color of this face after lighting
bool lit; // Do we care about lighting?
bool visible; // Can we see this triangle?
bool twoSided; // Are both sides visible?
float normalLength; // Magnatude of surface normal
juint16 index[3]; // We do this instead of just a typedef so it works with stretch_buffer
} j3TriangleT;
typedef struct {
......@@ -107,6 +122,7 @@ typedef struct {
// Syntatic sugar
#define j3DrawSolid(o) _j3DrawSolid(&(o))
#define j3DrawWireframe(o) _j3DrawWireframe(&(o))
#define j3ObjectReset(o) _j3ObjectReset(&(o))
#define j3ObjectUpdate(o) _j3ObjectUpdate(&(o))
......@@ -115,13 +131,21 @@ typedef struct {
// Prototypes
void j3MathMatrix4x4Identity(j3Matrix4x4T result);
void j3MathMatrix4x4Mult(j3Matrix4x4T a, j3Matrix4x4T b, j3Matrix4x4T result);
void j3UtilShutdown(void);
void j3UtilStartup(void);
void j3DrawTriangle2D(jint16 x1, jint16 y1, jint16 x2,jint16 y2, jint16 x3, jint16 y3, jint16 color);
void j3MathCrossProduct3D(j3Vector3DT *u, j3Vector3DT *v, j3Vector3DT *normal);
float j3MathDotProduct3D(j3Vector3DT *u, j3Vector3DT *v);
void j3MathMatrix4x4Identity(j3Matrix4x4T result);
void j3MathMatrix4x4Mult(j3Matrix4x4T a, j3Matrix4x4T b, j3Matrix4x4T result);
void j3MathMakeVector3D(j3VertexT *init, j3VertexT *term, j3Vector3DT *result);
float j3MathVectorMagnatude3D(j3Vector3DT *v);
void j3UtilShutdown(void);
void j3UtilStartup(void);
// Private Prototypes
void _j3DrawSolid(j3ObjectT *o);
void _j3DrawTriangleBottom(jint16 x1, jint16 y1, jint16 x2,jint16 y2, jint16 x3, jint16 y3);
void _j3DrawTriangleTop(jint16 x1, jint16 y1, jint16 x2,jint16 y2, jint16 x3, jint16 y3);
void _j3DrawWireframePair(j3ObjectT *o, juint16 v1, juint16 v2);
void _j3DrawWireframe(j3ObjectT *o);
void _j3ObjectReset(j3ObjectT *o);
......
......@@ -59,6 +59,8 @@ void printAt(jlStaT *font, jint16 cx, jint16 cy, const char *what, ...) {
int main(void) {
jint16 x;
jint16 y;
jint16 c;
jlStaT *font = NULL;
j3WorldT *world = NULL;
bool r;
......@@ -81,8 +83,18 @@ int main(void) {
printAt(font, 1, 1, "Object loading: Success!");
jlDisplayPresent();
// Assign fake colors until we can read them from the J3D
c = 1;
for (x=0; x<world->objectCount; x++) {
for (y=0; y<world->objects[x].triangleCount; y++) {
world->objects[x].triangles->color = c++;
if (c > 15) {
c = 1;
}
}
}
#ifdef JOEY_LINUX
jint16 y;
printf("Objects: %d\n", world->objectCount);
for (x=0; x<world->objectCount; x++) {
printf("Object %d:\n", x);
......@@ -121,7 +133,8 @@ int main(void) {
for (x=0; x<world->objectCount; x++) {
j3ObjectRotate(world->objects[x], 2, 4, 6); // Matching values in code I'm studying
j3ObjectUpdate(world->objects[x]);
j3DrawWireframe(world->objects[x]);
//j3DrawWireframe(world->objects[x]);
j3DrawSolid(world->objects[x]);
}
printAt(font, 1, 1, "Verticies: %d", world->objects[0].vertexCount);
......
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