diff --git a/house.h b/house.h new file mode 100644 index 0000000..20295a6 --- /dev/null +++ b/house.h @@ -0,0 +1,124 @@ +#ifndef HOUSE_H +#define HOUSE_H + +const S3L_Unit houseVertices[] = { +0x388,0x35e,0x157,0x388,0x35e,0x22c,0x331,0x183,0x1c9,0x331,0x17a,0x13c,0x2e0, +0x35e,0x22c,0x2a5,0x19a,0x1c9,0x40b,0x360,0x2ba,0x2e8,0x18d,0x13c,0x33d,0x35e, +0x157,0x30d,0x25a,-0x123,0x33d,0x35e,-0x207,0x30d,0x25c,0x6c,0x5e,0x383,0x2e0, +0x2e0,0x35e,0x1c7,0x2a5,0x1ae,0x16c,0x26c,0x664,-0x58,0x22,0x633,-0x58,0x336, +-0x1c,0x13e,0x2fd,-0x1c,0x13e,0x290,-0x1c,0x17e,0x290,-0x1c,0x1f6,0x336,-0x1c, +0x1f6,0x12d,0x197,0x16c,0x10d,-0x1c,0x180,0x13e,0x2d0,0x1b9,0x10d,-0x1a,0x1d4, +0x13e,0x2cf,0x232,0xe8,0x274,0x22a,0xba,-0x1a,0x1da,0xe8,0x275,0x1a6,0xba,-0x1c, +0x176,0x290,0x25c,0x6c,0x2e8,0x198,0x66,0x290,0x10a,0x55,0x290,0x10a,-0x104, +0x290,0x25a,-0x123,0x2f2,0x10a,0x55,0x2f2,0x10a,-0x104,0x2fd,-0x1c,-0x1ee,-0x344, +0x35e,0x157,-0x2ed,0x177,0x13c,-0x2ed,0x177,0x1c9,-0x344,0x35e,0x22c,-0x262, +0x17c,0x1c9,-0x29c,0x35e,0x22c,-0x3ba,0x369,0x2ca,-0x2f9,0x35e,0x157,-0x2a4, +0x197,0x13c,-0x2c9,0x25e,-0xf7,-0x295,0x167,-0x1f3,-0x2a4,0x199,-0xfb,-0x262, +0x187,0x16c,-0x29c,0x35e,0x1c7,-0x4c7,0x6a0,-0x8b,-0x3a8,0x369,-0x358,-0x2b8, +-0x1c,0x13e,-0x2fb,-0x1c,0x13e,-0x24c,-0x1c,0x1e0,-0x24c,-0x1c,0x17e,-0x2fb, +-0x1c,0x1e0,-0xc9,-0x1c,0x180,-0xdd,0x197,0x16c,-0xee,0x2c1,0x1b9,-0xc9,-0x1a, +0x1d4,-0xee,0x2bf,0x232,-0x75,-0x1a,0x1da,-0x98,0x265,0x22a,-0x75,-0x1c,0x176, +-0x98,0x266,0x1a6,-0x344,0x35e,-0x207,-0x24b,0x25e,0x47,-0x24b,0xd2,0x48,-0x2a4, +0x199,0x4b,-0x2c9,0x25e,0x47,-0x2ad,0xd2,0x48,-0x2f9,0x35e,-0x207,0x388,0x35e, +-0x207,0x331,0x1a7,-0x1ec,0x331,0x197,-0x279,0x388,0x34f,-0x2dd,0x4c9,0x719, +-0x71,-0x29c,0x35e,-0x277,0x7b,0x37a,-0x2fb,0x2e0,0x35e,-0x277,0x2ae,0x1aa, +-0x279,0x2e0,0x35e,-0x2dd,0x3fd,0x33d,-0x33a,0x2e8,0x1a7,-0x1ec,0x2ae,0x1aa, +-0x21c,-0x227,0x664,-0x58,-0x283,0x5c7,0x47,0x336,-0x1c,-0x1ee,0x290,-0x1c, +-0x290,0x290,-0x1c,-0x22e,0x336,-0x1c,-0x290,0x2e8,0x199,-0x115,-0x344,0x35e, +-0x2dd,-0x2de,0x167,-0x279,-0x2de,0x167,-0x1f3,-0x29c,0x35e,-0x2dd,-0x263,0x167, +-0x279,-0x24b,0x25e,-0xf7,-0x24b,0xd2,-0xf8,-0x263,0x167,-0x21c,-0x2f1,-0x1c, +-0x1ee,-0x2b8,-0x1c,-0x1ee,-0x24c,-0x1c,-0x22e,-0x24c,-0x1c,-0x290,-0x2f1,-0x1c, +-0x290,-0x2ad,0xd2,-0xf8,-0x2be,0x56d,0xa1,-0x274,0x6bc,0x64,-0x2d1,0x6b0,0x10d, +-0x358,0x6cd,0x70,-0x31a,0x5c0,0x55,0x388,0x35e,0x22c,0x376,0x35e,-0x281,0x376, +0x35e,-0x281,-0x344,0x35e,0x22c,-0x332,0x35e,-0x281,-0x332,0x35e,-0x281,0x388, +0x35e,-0x2dd,0x376,0x35e,0x1d1,0x376,0x35e,0x1d1,-0x344,0x35e,-0x2dd,-0x332, +0x35e,0x1d1,-0x332,0x35e,0x1d1}; + +const S3L_Index houseTriangleIndices[] = { +0,2,3,4,2,1,4,1,6,0,6,1,3,8,0,10,11,9,8,7,11,12,4,6,5,13,14,15,16,12,3,18,7,5,19, +20,2,20,21,2,17,3,22,19,14,24,14,13,25,24,26,23,22,24,25,27,28,28,29,30,31,32,33, +32,31,11,31,34,35,36,33,32,37,18,38,18,36,7,39,41,42,41,44,42,44,45,42,39,42,45, +39,47,40,48,49,50,12,45,44,43,52,44,53,54,45,55,40,47,43,58,51,41,57,43,56,41,40, +58,61,51,51,62,52,63,62,60,60,62,61,63,66,64,65,68,66,45,69,39,70,71,72,72,73,70, +74,72,71,75,49,48,76,78,79,15,6,80,81,82,83,78,85,79,85,86,79,76,79,86,10,77,76, +0,10,76,7,32,11,82,86,85,84,83,85,16,89,90,15,82,16,38,77,87,84,93,88,78,92,84, +91,78,77,35,34,95,95,9,35,11,35,9,37,95,34,33,37,34,7,36,32,69,97,98,89,54,53,99, +82,81,99,97,96,99,96,54,69,54,96,98,75,69,101,71,70,46,73,47,82,99,54,100,81,103, +15,86,82,89,16,82,73,75,48,98,105,49,100,106,107,100,108,97,97,104,98,103,93,106, +81,88,103,109,55,74,101,50,102,50,101,48,102,74,71,109,102,50,48,70,73,73,72,47, +69,46,39,86,0,76,80,6,86,30,68,67,27,68,29,27,64,66,62,26,24,24,52,62,12,52,13,4, +12,13,12,44,52,10,9,87,87,9,95,87,95,37,38,87,37,109,50,49,49,105,109,74,47,72, +47,74,55,90,112,110,112,114,110,114,111,90,113,112,111,45,114,53,110,114,45,12, +16,90,110,12,90,110,45,12,90,89,114,89,53,114,82,85,83,0,1,2,4,5,2,3,7,8,10,8,11, +5,4,13,3,17,18,5,14,19,2,5,20,2,21,17,22,23,19,24,22,14,25,23,24,25,26,27,28,27, +29,31,33,34,37,36,18,39,40,41,41,43,44,39,46,47,43,51,52,55,56,40,43,57,58,41,59, +57,56,59,41,58,60,61,51,61,62,63,64,62,63,65,66,65,67,68,45,54,69,76,77,78,15,12, +6,78,84,85,10,87,77,0,8,10,84,88,83,38,91,77,84,92,93,78,94,92,91,94,78,11,31,35, +33,36,37,69,96,97,89,82,54,99,100,97,98,49,75,101,102,71,100,99,81,15,80,86,73, +46,75,98,104,105,100,103,106,100,107,108,97,108,104,103,88,93,81,83,88,109,105, +55,102,109,74,48,101,70,69,75,46,86,6,0,30,29,68,27,66,68,27,26,64,62,64,26,24, +13,52,90,111,112,112,113,114,114,113,111}; + +const S3L_Unit houseUVs[] = { +0x711,0x6bc,0x2af,0x711,0x6bc,0x459,0x663,0x307,0x392,0x663,0x2f4,0x278,0x5c1, +0x6bc,0x459,0x54a,0x335,0x392,0x816,0x6c0,0x574,0x5d1,0x31b,0x278,0x67b,0x6bc, +0x2af,0x61b,0x4b5,-0x246,0x67b,0x6bc,-0x40f,0x61b,0x4b8,0xd9,0xbc,0x707,0x5c1, +0x5c1,0x6bc,0x38e,0x54a,0x35c,0x2d9,0x4d8,0xcc8,-0xb0,0x44,0xc66,-0xb0,0x66c, +-0x39,0x27c,0x5fa,-0x39,0x27c,0x521,-0x39,0x2fd,0x521,-0x39,0x3ed,0x66c,-0x39, +0x3ed,0x25a,0x32e,0x2d8,0x21b,-0x39,0x300,0x27d,0x5a1,0x372,0x21b,-0x34,0x3a8, +0x27d,0x59e,0x464,0x1d0,0x4e9,0x455,0x174,-0x34,0x3b4,0x1d0,0x4eb,0x34d,0x174, +-0x39,0x2ec,0x520,0x4b8,0xd9,0x5d1,0x331,0xcc,0x520,0x214,0xab,0x520,0x215, +-0x209,0x520,0x4b5,-0x246,0x5e4,0x214,0xab,0x5e4,0x215,-0x209,0x5fa,-0x39,-0x3dc, +-0x688,0x6bc,0x2af,-0x5da,0x2ef,0x278,-0x5da,0x2ef,0x392,-0x688,0x6bc,0x459, +-0x4c5,0x2f8,0x392,-0x538,0x6bc,0x459,-0x775,0x6d3,0x595,-0x5f3,0x6bc,0x2af, +-0x548,0x32e,0x278,-0x592,0x4bd,-0x1ee,-0x52b,0x2ce,-0x3e7,-0x548,0x332,-0x1f7, +-0x4c5,0x30e,0x2d9,-0x538,0x6bc,0x38e,-0x98e,0xd41,-0x116,-0x750,0x6d3,-0x6b1, +-0x571,-0x39,0x27c,-0x5f7,-0x39,0x27c,-0x498,-0x39,0x3c1,-0x498,-0x39,0x2fd, +-0x5f7,-0x39,0x3c1,-0x192,-0x39,0x300,-0x1bb,0x32e,0x2d8,-0x1dd,0x582,0x372, +-0x192,-0x34,0x3a8,-0x1dd,0x57f,0x464,-0xeb,-0x34,0x3b4,-0x130,0x4ca,0x455,-0xeb, +-0x39,0x2ec,-0x130,0x4cc,0x34d,-0x688,0x6bc,-0x40f,-0x497,0x4bd,0x8e,-0x497, +0x1a4,0x91,-0x548,0x332,0x97,-0x592,0x4bd,0x8e,-0x55b,0x1a4,0x91,-0x5f3,0x6bc, +-0x40f,0x711,0x6bc,-0x40f,0x663,0x34e,-0x3d8,0x663,0x32e,-0x4f2,0x711,0x69f, +-0x5ba,0x992,0xe32,-0xe3,-0x538,0x6bc,-0x4ee,0xf7,0x6f5,-0x5f7,0x5c1,0x6bc, +-0x4ee,0x55d,0x354,-0x4f2,0x5c1,0x6bc,-0x5ba,0x7fa,0x67a,-0x675,0x5d1,0x34e, +-0x3d8,0x55d,0x354,-0x439,-0x44f,0xcc8,-0xb0,-0x506,0xb8f,0x8f,0x66c,-0x39, +-0x3dc,0x521,-0x39,-0x521,0x521,-0x39,-0x45d,0x66c,-0x39,-0x521,0x5d1,0x332, +-0x22b,-0x688,0x6bc,-0x5ba,-0x5bc,0x2ce,-0x4f2,-0x5bc,0x2ce,-0x3e7,-0x538,0x6bc, +-0x5ba,-0x4c6,0x2ce,-0x4f2,-0x497,0x4bd,-0x1ee,-0x497,0x1a4,-0x1f1,-0x4c6,0x2ce, +-0x439,-0x5e3,-0x39,-0x3dc,-0x571,-0x39,-0x3dc,-0x498,-0x39,-0x45d,-0x498,-0x39, +-0x521,-0x5e3,-0x39,-0x521,-0x55b,0x1a4,-0x1f1,-0x57d,0xadb,0x143,-0x4e9,0xd79, +0xc8,-0x5a2,0xd60,0x21a,-0x6b0,0xd9a,0xe0,-0x635,0xb81,0xaa,0x711,0x6bc,0x459, +0x6ed,0x6bc,-0x502,0x6ed,0x6bc,-0x502,-0x688,0x6bc,0x459,-0x664,0x6bc,-0x502, +-0x664,0x6bc,-0x502,0x711,0x6bc,-0x5ba,0x6ed,0x6bc,0x3a2,0x6ed,0x6bc,0x3a2, +-0x688,0x6bc,-0x5ba,-0x664,0x6bc,0x3a2,-0x664,0x6bc,0x3a2}; + +const S3L_Index houseUVIndices[] = { +0,2,3,4,2,1,4,1,6,0,6,1,3,8,0,10,11,9,8,7,11,12,4,6,5,13,14,15,16,12,3,18,7,5,19, +20,2,20,21,2,17,3,22,19,14,24,14,13,25,24,26,23,22,24,25,27,28,28,29,30,31,32,33, +32,31,11,31,34,35,36,33,32,37,18,38,18,36,7,39,41,42,41,44,42,44,45,42,39,42,45, +39,47,40,48,49,50,12,45,44,43,52,44,53,54,45,55,40,47,43,58,51,41,57,43,56,41,40, +58,61,51,51,62,52,63,62,60,60,62,61,63,66,64,65,68,66,45,69,39,70,71,72,72,73,70, +74,72,71,75,49,48,76,78,79,15,6,80,81,82,83,78,85,79,85,86,79,76,79,86,10,77,76, +0,10,76,7,32,11,82,86,85,84,83,85,16,89,90,15,82,16,38,77,87,84,93,88,78,92,84, +91,78,77,35,34,95,95,9,35,11,35,9,37,95,34,33,37,34,7,36,32,69,97,98,89,54,53,99, +82,81,99,97,96,99,96,54,69,54,96,98,75,69,101,71,70,46,73,47,82,99,54,100,81,103, +15,86,82,89,16,82,73,75,48,98,105,49,100,106,107,100,108,97,97,104,98,103,93,106, +81,88,103,109,55,74,101,50,102,50,101,48,102,74,71,109,102,50,48,70,73,73,72,47, +69,46,39,86,0,76,80,6,86,30,68,67,27,68,29,27,64,66,62,26,24,24,52,62,12,52,13,4, +12,13,12,44,52,10,9,87,87,9,95,87,95,37,38,87,37,109,50,49,49,105,109,74,47,72, +47,74,55,90,112,110,112,114,110,114,111,90,113,112,111,45,114,53,110,114,45,12, +16,90,110,12,90,110,45,12,90,89,114,89,53,114,82,85,83,0,1,2,4,5,2,3,7,8,10,8,11, +5,4,13,3,17,18,5,14,19,2,5,20,2,21,17,22,23,19,24,22,14,25,23,24,25,26,27,28,27, +29,31,33,34,37,36,18,39,40,41,41,43,44,39,46,47,43,51,52,55,56,40,43,57,58,41,59, +57,56,59,41,58,60,61,51,61,62,63,64,62,63,65,66,65,67,68,45,54,69,76,77,78,15,12, +6,78,84,85,10,87,77,0,8,10,84,88,83,38,91,77,84,92,93,78,94,92,91,94,78,11,31,35, +33,36,37,69,96,97,89,82,54,99,100,97,98,49,75,101,102,71,100,99,81,15,80,86,73, +46,75,98,104,105,100,103,106,100,107,108,97,108,104,103,88,93,81,83,88,109,105, +55,102,109,74,48,101,70,69,75,46,86,6,0,30,29,68,27,66,68,27,26,64,62,64,26,24, +13,52,90,111,112,112,113,114,114,113,111}; + +S3L_Model3D house = +{.vertices=houseVertices,.vertexCount=127,.triangles=houseTriangleIndices, +.triangleCount=200}; + +#endif // guard diff --git a/obj2array.py b/obj2array.py index e68cafb..086ca27 100644 --- a/obj2array.py +++ b/obj2array.py @@ -12,6 +12,7 @@ def printHelp(): print(" python obj2array.py [-c -sX -uY -vZ -n] file\n") print(" -c compact format (off by default)") print(" -t use direct instead of indexed UV coords (off by default)") + print(" -h include header guards (for model per file)") print(" -nS use the name S for the model (defaut: \"model\")") print(" -sX scale the model by X (default: 512)") print(" -uY scale the U texture coord by Y (default: 512)") @@ -29,6 +30,7 @@ VERTEX_SCALE = 512 U_SCALE = 512 V_SCALE = 512 NAME = "model" +GUARDS = False COMPACT = False INDEXED_UVS = True @@ -37,6 +39,8 @@ for s in sys.argv: COMPACT = True elif s == "-t": INDEXED_UVS = False + elif s == "-h": + GUARDS = True elif s[:2] == "-s": VERTEX_SCALE = int(s[2:]) elif s[:2] == "-u": @@ -85,8 +89,8 @@ for line in objFile: # print the result: -def arrayString(name, array, components, scales, align, short): - result = name + " = [\n" +def arrayString(name, array, components, scales, align, short, dataType): + result = "const " + dataType + " " + name + "[] = {\n" if COMPACT: lineLen = 0 @@ -122,7 +126,7 @@ def arrayString(name, array, components, scales, align, short): lineLen += len(item) n += 1 - result += "]\n" + result += "};\n" else: # non-compact n = 0 @@ -138,18 +142,22 @@ def arrayString(name, array, components, scales, align, short): result += line n += 1 - result += "]; // " + name + "\n" + result += "}; // " + name + "\n" return result result = "" -print(arrayString(NAME + "Vertices",vertices,3,[VERTEX_SCALE],5,False)) -print(arrayString(NAME + "TriangleIndices",triangles,3,[1],5,True)) +if GUARDS: + print("#ifndef " + NAME.upper() + "_H") + print("#define " + NAME.upper() + "_H\n") + +print(arrayString(NAME + "Vertices",vertices,3,[VERTEX_SCALE],5,False,"S3L_Unit")) +print(arrayString(NAME + "TriangleIndices",triangles,3,[1],5,True,"S3L_Index")) if INDEXED_UVS: - print(arrayString(NAME + "UVs",vertices,2,[U_SCALE,V_SCALE],5,False)) - print(arrayString(NAME + "UVIndices",triangleUVs,3,[1],5,True)) + print(arrayString(NAME + "UVs",vertices,2,[U_SCALE,V_SCALE],5,False,"S3L_Unit")) + print(arrayString(NAME + "UVIndices",triangleUVs,3,[1],5,True,"S3L_Index")) else: uvs2 = [] for item in triangleUVs: @@ -161,19 +169,22 @@ else: uvs[item[2]][0], uvs[item[2]][1]]) - print(arrayString(NAME + "TriangleUVs",uvs2,6,[U_SCALE,V_SCALE],5,False)) + print(arrayString(NAME + "TriangleUVs",uvs2,6,[U_SCALE,V_SCALE],5,False,"S3L_Unit")) -print("S3L_Model " + NAME + " = ") +print("S3L_Model3D " + NAME + " = ") if COMPACT: print("{.vertices=" + - NAME + "Verices,.vertexCount=" + str(len(vertices)) + - ",.triangles=" + NAME + "\nTriangles,.triangleCount=" + + NAME + "Vertices,.vertexCount=" + str(len(vertices)) + + ",.triangles=" + NAME + "TriangleIndices,\n.triangleCount=" + str(len(triangles)) + "};"); else: print("{") print(" .vertices = " + NAME + "Vertices,") print(" .vertexCount = " + str(len(vertices)) + ",") - print(" .triangles = " + NAME + "Triangles,") + print(" .triangles = " + NAME + "TriangleIndices,") print(" .triangleCount = " + str(len(triangles))) print("};") + +if GUARDS: + print("\n#endif // guard") diff --git a/s3l.h b/s3l.h index 9cbffed..8430b25 100644 --- a/s3l.h +++ b/s3l.h @@ -72,6 +72,8 @@ Coordinates of pixels on screen start typically at the top left, from [0,0]. + There is NO subpixel accuracy (screen coordinates are only integer). + Triangle rasterization rules are these (mostly same as OpenGL, D3D etc.): - Let's define: diff --git a/testSDL.c b/testSDL.c index 13142d0..ccf8147 100644 --- a/testSDL.c +++ b/testSDL.c @@ -19,6 +19,8 @@ #include "s3l.h" +#include "house.h" + int32_t offScreenPixels = 0; const int16_t test_coords[] = @@ -107,7 +109,7 @@ void drawPixel(S3L_PixelInfo *p) S3L_Unit u, v, *coords; coords = tex_coords + p->triangleID * 6; - +/* u = S3L_interpolateBarycentric( coords[0], coords[2], @@ -119,14 +121,14 @@ void drawPixel(S3L_PixelInfo *p) coords[3], coords[5], p->barycentric0, p->barycentric1, p->barycentric2); +*/ +// uint8_t col = texturePixel(u,v); - uint8_t col = texturePixel(u,v); - - setPixel(p->x,p->y,col * 120,20,(2 - col) * 120); +// setPixel(p->x,p->y,col * 120,20,(2 - col) * 120); uint8_t sss = (p->depth / 5000.0) * 255 ; -//setPixel(p->x,p->y,sss,sss,sss); +setPixel(p->x,p->y,sss,sss,128); //setPixel(p->x,p->y,p->modelID * 64,p->modelID * 128,255); @@ -177,8 +179,11 @@ int main() S3L_initDrawConfig(&(scene.models[0].config)); scene.models[0].transform.translation.x = S3L_FRACTIONS_PER_UNIT; - scene.models[1] = scene.models[0]; - scene.models[1].transform.translation.x = 0.5 * S3L_FRACTIONS_PER_UNIT; +// scene.models[1] = scene.models[0]; +// scene.models[1].transform.translation.x = 0.5 * S3L_FRACTIONS_PER_UNIT; + scene.models[1] = house; + S3L_initTransoform3D(&(scene.models[1].transform)); + S3L_initDrawConfig(&(scene.models[1].config)); // scene.camera.transform.translation.x = S3L_FRACTIONS_PER_UNIT; // scene.camera.transform.translation.y = S3L_FRACTIONS_PER_UNIT;