/* * JoeyLib 3D * Copyright (C) 2019 Scott Duensing * * 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 #include #include #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 tx; jint16 ty; 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); tx = cx * 8; ty = cy * 8; for (counter=0; counter<(int)strlen(msg); counter++) { x = msg[counter] % 40; y = msg[counter] / 40; jlDrawBlit8x8(jlStaSurfaceGet(font), x, y, tx, ty); tx += 8; } } int main(void) { jint16 x; jint16 y; jint16 c; jint16 cubeId; jint16 cubePieces; jlStaT *font = NULL; j3PropT *cube = NULL; j3WorldT *world = NULL; jlUtilStartup("JoeyLib 3D"); jlStaLoad(font, "font"); printAt(font, 1, 1, "Starting JoeyLib3D..."); jlDisplayPresent(); j3UtilStartup(); printAt(font, 1, 1, "Loading object... "); jlDisplayPresent(); cubePieces = j3PropLoad(cube, "cube"); if (cubePieces < 0) { printAt(font, 1, 1, "Object loading: Failed."); jlDisplayPresent(); jlKeyWaitForAny(); } else { printAt(font, 1, 1, "Object loading: Success!"); jlDisplayPresent(); // Add prop to world cubeId = j3WorldAddProp(world, cube); // Assign fake colors until we can read them from the J3D c = 1; for (y=0; yobjects[cubeId].triangleCount; y++) { world->objects[cubeId].triangles[y].color = c++; if (c > 15) { c = 1; } } #ifdef JOEY_LINUX printf("Objects: %d\n", world->objectCount); for (x=0; xobjectCount; x++) { printf("Object %d:\n", x); printf(" Verticies: %d\n", world->objects[x].vertexCount); for (y=0; yobjects[x].vertexCount; y++) { printf(" Vertex %d: %f %f %f\n", y, (double)world->objects[x].vertices[y].original.x, (double)world->objects[x].vertices[y].original.y, (double)world->objects[x].vertices[y].original.z ); } printf(" Triangles: %d\n", world->objects[x].triangleCount); for (y=0; yobjects[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; xobjectCount; 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()) { jlDrawColorSet(0); jlDrawClear(); jlDrawColorSet(15); jlDrawBox(0, 0, 319, 199); for (x=0; xobjectCount; x++) { j3ObjectRotate(world->objects[x], 2, 4, 6); // Matching values in code I'm studying j3DrawWorld(world); } c = 0; for (x=0; xobjects[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(); } j3PropFree(cube); j3WorldFree(world); jlStaFree(font); j3UtilShutdown(); jlUtilShutdown(); }