166 lines
4.4 KiB
C
166 lines
4.4 KiB
C
/*
|
|
* 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 <stdio.h>
|
|
#include <string.h>
|
|
#include <stdarg.h>
|
|
|
|
#define JOEY_MAIN
|
|
#include "joey.h"
|
|
|
|
#ifdef JOEY_IIGS
|
|
segment "j3dTest";
|
|
#endif
|
|
|
|
#include "j3d.h"
|
|
|
|
|
|
void printAt(jlStaT *font, jint16 cx, jint16 cy, const char *what, ...);
|
|
|
|
|
|
__attribute__((__format__ (__printf__, 4, 0)))
|
|
void printAt(jlStaT *font, jint16 cx, jint16 cy, const char *what, ...) {
|
|
jint16 x;
|
|
jint16 y;
|
|
jint16 counter;
|
|
char msg[40]; // Very short messages (screen width). Be careful!
|
|
va_list va;
|
|
|
|
va_start(va, what);
|
|
vsprintf(msg, what, va);
|
|
va_end(va);
|
|
|
|
for (counter=0; counter<(int)strlen(msg); counter++) {
|
|
x = msg[counter] % 40;
|
|
y = msg[counter] / 40;
|
|
jlDrawBlit8x8(font, x, y, counter + cx, cy);
|
|
}
|
|
}
|
|
|
|
|
|
int main(void) {
|
|
jint16 x;
|
|
jint16 y;
|
|
jint16 c;
|
|
jlStaT *font = NULL;
|
|
j3WorldT *world = NULL;
|
|
bool r;
|
|
|
|
jlUtilStartup("JoeyLib 3D");
|
|
jlStaLoad(font, "font");
|
|
|
|
printAt(font, 1, 1, "Starting JoeyLib3D...");
|
|
jlDisplayPresent();
|
|
j3UtilStartup();
|
|
|
|
printAt(font, 1, 1, "Loading object... ");
|
|
jlDisplayPresent();
|
|
r = j3WorldLoad(world, "pyramid");
|
|
if (!r) {
|
|
printAt(font, 1, 1, "Object loading: Failed.");
|
|
jlDisplayPresent();
|
|
jlKeyWaitForAny();
|
|
} else {
|
|
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[y].color = c++;
|
|
if (c > 15) {
|
|
c = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
#ifdef JOEY_LINUX
|
|
printf("Objects: %d\n", world->objectCount);
|
|
for (x=0; x<world->objectCount; x++) {
|
|
printf("Object %d:\n", x);
|
|
printf(" Verticies: %d\n", world->objects[x].vertexCount);
|
|
for (y=0; y<world->objects[x].vertexCount; y++) {
|
|
printf(" Vertex %d: %f %f %f\n",
|
|
y,
|
|
(double)world->objects[x].verticies[y].local.x,
|
|
(double)world->objects[x].verticies[y].local.y,
|
|
(double)world->objects[x].verticies[y].local.z
|
|
);
|
|
}
|
|
printf(" Triangles: %d\n", world->objects[x].triangleCount);
|
|
for (y=0; y<world->objects[x].triangleCount; y++) {
|
|
printf(" Triangle %d: %d %d %d\n",
|
|
y,
|
|
world->objects[x].triangles[y].index[0],
|
|
world->objects[x].triangles[y].index[1],
|
|
world->objects[x].triangles[y].index[2]
|
|
);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
for (x=0; x<world->objectCount; x++) {
|
|
j3ObjectMoveTo(world->objects[x], 0, 0, 300); // Matching values in code I'm studying
|
|
j3ObjectScaleTo(world->objects[x], 30, 30, 30); // Matching values in code I'm studying
|
|
}
|
|
|
|
while (!jlKeyPressed() && !jlUtilMustExit()) {
|
|
jlDrawColor(0);
|
|
jlDrawClear();
|
|
jlDrawColor(15);
|
|
jlDrawBox(0, 0, 319, 199);
|
|
|
|
//***TODO*** HACK!!!
|
|
_j3PolygonCount = 0;
|
|
|
|
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]);
|
|
//j3DrawSolid(world->objects[x]);
|
|
j3DrawWorld(world);
|
|
}
|
|
|
|
c = 0;
|
|
for (x=0; x<world->objects[0].triangleCount; x++) {
|
|
if (world->objects[0].triangles[x].visible) {
|
|
c++;
|
|
}
|
|
}
|
|
|
|
printAt(font, 1, 1, "Verticies: %d", world->objects[0].vertexCount);
|
|
printAt(font, 1, 2, "Triangles: %d (%d visible) ", world->objects[0].triangleCount, c);
|
|
|
|
jlDisplayPresent();
|
|
jlUtilSleep(1);
|
|
}
|
|
jlKeyRead();
|
|
}
|
|
|
|
j3WorldFree(world);
|
|
jlStaFree(font);
|
|
|
|
j3UtilShutdown();
|
|
jlUtilShutdown();
|
|
}
|
|
|