1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-12-22 01:26:17 +01:00

Add Pokitto files

This commit is contained in:
Miloslav Číž 2019-07-02 01:02:37 +02:00
parent 4af97b0d0d
commit a7b1c5a117
8 changed files with 4472 additions and 0 deletions

104
programs/pokitto/carModel.h Normal file
View file

@ -0,0 +1,104 @@
#ifndef CAR_MODEL_H
#define CAR_MODEL_H
#define CAR_VERTEX_COUNT 12
const S3L_Unit carVertices[CAR_VERTEX_COUNT * 3] = {
-51, 14, -108, // 0
-31, 103, -92, // 3
-31, 103, -3, // 6
51, 14, -108, // 9
31, 103, -92, // 12
31, 103, -3, // 15
-48, 59, 31, // 18
48, 59, 31, // 21
-40, 52, 86, // 24
-44, 14, 86, // 27
44, 14, 86, // 30
40, 52, 86 // 33
}; // carVertices
#define CAR_TRIANGLE_COUNT 18
const S3L_Index carTriangleIndices[CAR_TRIANGLE_COUNT * 3] = {
4, 3, 5, // 0
2, 7, 6, // 3
1, 0, 4, // 6
7, 5, 3, // 9
2, 4, 5, // 12
2, 0, 1, // 15
9, 6, 8, // 18
7, 8, 6, // 21
3, 4, 0, // 24
9, 11, 10, // 27
7, 3, 10, // 30
0, 6, 9, // 33
6, 0, 2, // 36
10, 11, 7, // 39
2, 5, 7, // 42
2, 1, 4, // 45
7, 11, 8, // 48
9, 8, 11 // 51
}; // carTriangleIndices
#define CAR_UV_COUNT 24
const S3L_Unit carUVs[CAR_UV_COUNT * 2] = {
451, 476, // 0
459, 509, // 2
422, 477, // 4
422, 476, // 6
409, 451, // 8
409, 476, // 10
451, 476, // 12
484, 476, // 14
451, 451, // 16
409, 492, // 18
422, 451, // 20
422, 477, // 22
459, 509, // 24
451, 476, // 26
398, 509, // 28
409, 492, // 30
398, 493, // 32
397, 476, // 34
484, 451, // 36
386, 476, // 38
397, 451, // 40
386, 451, // 42
398, 509, // 44
398, 493 // 46
}; // carUVs
#define CAR_UV_INDEX_COUNT 18
const S3L_Index carUVIndices[CAR_UV_INDEX_COUNT * 3] = {
0, 1, 2, // 0
3, 4, 5, // 3
6, 7, 8, // 6
9, 2, 1, // 9
3, 8, 10, // 12
11, 12, 13, // 15
14, 15, 16, // 18
4, 17, 5, // 21
18, 8, 7, // 24
19, 20, 21, // 27
9, 1, 22, // 30
12, 15, 14, // 33
15, 12, 11, // 36
22, 23, 9, // 39
3, 10, 4, // 42
3, 6, 8, // 45
4, 20, 17, // 48
19, 17, 20 // 51
}; // carUVIndices
S3L_Model3D carModel;
void carModelInit()
{
S3L_initModel3D(
carVertices,
CAR_VERTEX_COUNT,
carTriangleIndices,
CAR_TRIANGLE_COUNT,
&carModel);
}
#endif // guard

BIN
programs/pokitto/city.bin Executable file

Binary file not shown.

BIN
programs/pokitto/level.bin Executable file

Binary file not shown.

243
programs/pokitto/level.cpp Normal file
View file

@ -0,0 +1,243 @@
/*
Example program of small3dlib for Pokitto -- Quake-like level.
author: Miloslav Ciz
license: CC0 1.0
*/
#include "Pokitto.h"
#define SUBSAMPLE 3
#if 1 // This can switch between a textured and flat mode.
#define S3L_Z_BUFFER 2
#define S3L_SORT 0
#define S3L_STENCIL_BUFFER 0
#define S3L_FLAT 0
#define S3L_PERSPECTIVE_CORRECTION 2
#else
#define S3L_Z_BUFFER 2
#define S3L_SORT 0
#define S3L_STENCIL_BUFFER 0
#define S3L_FLAT 1
#define S3L_MAX_TRIANGES_DRAWN 200
#endif
#define S3L_PIXEL_FUNCTION pixelFunc
// Because we'll be writing pixels as 2x2, define the resolution one smaller.
#define BASE_W 109
#define BASE_H 87
#define S3L_RESOLUTION_X (BASE_W - BASE_W / SUBSAMPLE)
#define S3L_RESOLUTION_Y (BASE_H - BASE_H / SUBSAMPLE)
#define S3L_STRICT_NEAR_CULLING 0
#define S3L_COMPUTE_DEPTH 1 // for fog
#define S3L_REDUCED_Z_BUFFER_GRANULARITY 6
#include "small3dlib.h"
#include "levelTexture1Pal.h"
#include "levelModel.h"
Pokitto::Core pokitto;
#if S3L_FLAT
uint8_t triangleColors[LEVEL_TRIANGLE_COUNT];
#endif
static inline uint8_t texture(int32_t u, int32_t v)
{
u = S3L_wrap(u,LEVEL1_TEXTURE_WIDTH);
v = S3L_wrap(v,LEVEL1_TEXTURE_HEIGHT);
uint32_t index = v * LEVEL1_TEXTURE_WIDTH + u;
return level1Texture[index];
}
S3L_ScreenCoord subsampleMap[BASE_W + SUBSAMPLE];
uint32_t previousTriangle = 100;
static inline uint8_t addIntensity(uint8_t color, int16_t intensity)
{
int16_t newValue = (color & 0b00001111) + intensity; // value as in HSV
if (newValue >= 16)
newValue = 15;
return (color & 0b11110000) | newValue;
}
static inline uint8_t substractIntensity(uint8_t color, int16_t intensity)
{
int16_t newValue = (color & 0b00001111) - intensity; // value as in HSV
if (newValue <= 0)
return 0;
return (color & 0b11110000) | newValue;
}
uint8_t c = 0;
S3L_Vec4 uv0, uv1, uv2;
S3L_Index material = 0;
void pixelFunc(S3L_PixelInfo *p)
{
uint8_t val;
uint8_t *buf = pokitto.display.screenbuffer;
#if S3L_FLAT
val = triangleColors[p->triangleIndex];
#else
if (p->triangleIndex != previousTriangle)
{
material = levelMaterials[p->triangleIndex];
if (material == 1)
c = 135;
else if (material == 2)
c = 213;
else
S3L_getIndexedTriangleValues(p->triangleIndex,levelUVIndices,levelUVs,2,&uv0,&uv1,&uv2);
previousTriangle = p->triangleID;
}
S3L_Unit fog = p->depth >> 9;
if (material == 0)
{
S3L_Unit uv[2];
uv[0] = S3L_interpolateBarycentric(uv0.x,uv1.x,uv2.x,p->barycentric);
uv[1] = S3L_interpolateBarycentric(uv0.y,uv1.y,uv2.y,p->barycentric);
c = texture(uv[0] / 32,uv[1] / 32);
}
val = substractIntensity(c,fog);
#endif
buf += subsampleMap[p->y] * 110;
buf += subsampleMap[p->x];
*buf = val;
buf++;
*buf = val;
buf += 109;
*buf = val;
buf++;
*buf = val;
}
S3L_Scene scene;
void draw()
{
S3L_newFrame();
S3L_drawScene(scene);
}
unsigned short palette[256];
int main()
{
for (uint16_t i = 0; i < BASE_W + SUBSAMPLE; ++i)
subsampleMap[i] = i + i / SUBSAMPLE;
#if S3L_FLAT
S3L_Vec4 toLight;
S3L_setVec4(&toLight,10,5,7,0);
S3L_normalizeVec3(&toLight);
for (uint16_t i = 0; i < LEVEL_TRIANGLE_COUNT; ++i)
{
uint8_t c;
S3L_Vec4 v0, v1, v2;
S3L_getIndexedTriangleValues(
i,
levelTriangleIndices,
levelVertices,3,&v0,&v1,&v2);
material = levelMaterials[i];
if (material == 1)
c = 38;
else if (material == 2)
c = 53;
else
c = 24;
S3L_Vec4 normal;
S3L_triangleNormal(v0,v1,v2,&normal);
triangleColors[i] = addIntensity(c,
S3L_max(0,(S3L_dotProductVec3(normal,toLight) + S3L_FRACTIONS_PER_UNIT) / 64));
}
#endif
pokitto.begin();
pokitto.setFrameRate(60);
pokitto.display.load565Palette(level1Palette);
S3L_initCamera(&scene.camera);
levelModelInit();
S3L_initScene(&levelModel,1,&scene);
while (pokitto.isRunning())
{
if (pokitto.update())
{
S3L_Vec4 camF, camR, camU;
int step = 300;
int step2 = 8;
S3L_rotationToDirections(
scene.camera.transform.rotation,
step,
&camF,
&camR,
&camU);
if (pokitto.aBtn())
{
if (pokitto.upBtn())
scene.camera.transform.rotation.x += 8;
else if (pokitto.downBtn())
scene.camera.transform.rotation.x -= 8;
else if (pokitto.rightBtn())
scene.camera.transform.rotation.y += 8;
else if (pokitto.leftBtn())
scene.camera.transform.rotation.y -= 8;
}
else
{
if (pokitto.upBtn())
S3L_vec3Add(&(scene.camera.transform.translation),camF);
else if (pokitto.downBtn())
S3L_vec3Sub(&scene.camera.transform.translation,camF);
else if (pokitto.rightBtn())
S3L_vec3Add(&scene.camera.transform.translation,camR);
else if (pokitto.leftBtn())
S3L_vec3Sub(&scene.camera.transform.translation,camR);
}
draw();
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,72 @@
#ifndef LEVEL1_TEXTURE_H
#define LEVEL1_TEXTURE_H
uint16_t level1Palette[256] = {
0,4226,8452,12678,16936,21162,25388,29614,35921,40147,44373,48599,52857,57083,
61309,65535,4193,8418,12611,16836,21029,25254,29447,33672,37865,42090,46283,
50508,54701,58926,63119,65264,2177,6402,8579,12804,14981,19206,21383,25608,
27785,32010,34187,38412,40589,44814,46991,51184,2177,4354,6531,8709,10886,13063,
15240,17418,19595,21772,23949,26127,28304,30481,32658,34804,2178,4356,6534,8712,
10890,13068,15246,17424,19602,21780,23958,26136,28314,30492,32670,34815,2114,
4260,6374,8520,10634,12780,14894,17040,19154,21300,23414,25560,27674,29820,
31934,34079,2114,6276,8390,12552,14666,18828,20942,25104,29266,31380,35542,
37656,41818,43932,48094,50207,4161,8323,12485,16646,20808,24970,29131,33293,
37455,41616,45778,49940,54101,58263,62425,64538,4096,8192,12288,16384,20480,
24576,28672,32768,36864,40960,45056,49152,53248,57344,61440,63488,4192,8384,
12576,16768,20960,25152,29344,33536,37728,41920,46112,50304,54496,58688,62880,
64992,2176,4352,6528,8704,10880,13056,15232,17408,19584,21760,23936,26112,28288,
30464,32640,34784,128,257,385,514,642,771,899,1028,1156,1285,1413,1542,1670,
1799,1927,2024,130,260,390,520,650,780,910,1040,1170,1300,1430,1560,1690,1820,
1950,2047,34,68,102,136,170,204,238,272,306,340,374,408,442,476,510,543,2050,
4100,6150,8200,10250,12300,14350,18448,20498,22548,24598,26648,28698,30748,
32798,36895,4097,8194,12292,16389,20486,24584,28681,32779,36876,40973,45071,
49168,53265,57363,61460,63509
}; // level1Palette
#define LEVEL1_TEXTURE_WIDTH 32
#define LEVEL1_TEXTURE_HEIGHT 32
uint8_t level1Texture[1024] = {
20,20,21,20,20,20,20,20,20,20,20,21,21,22,22,21,21,20,21,21,21,21,21,20,21,21,
21,21,21,20,20,20,26,26,24,20,25,25,25,25,25,25,25,24,25,25,24,25,25,21,21,25,
26,25,24,24,25,25,26,26,26,26,26,25,22,22,22,20,25,25,22,22,22,22,22,22,22,22,
23,24,25,23,20,23,23,22,22,21,22,22,22,22,22,22,22,22,23,23,22,20,25,23,23,23,
23,23,23,23,23,22,23,22,24,23,21,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,
22,19,25,24,23,23,23,23,24,24,23,23,23,23,24,23,21,23,24,24,24,24,24,24,24,24,
24,24,24,24,24,24,22,20,24,24,24,24,23,24,24,24,24,24,24,24,25,22,20,24,24,24,
24,24,24,24,24,24,24,24,24,24,24,24,22,20,24,24,24,24,24,24,24,24,24,24,24,24,
25,22,21,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,23,20,24,24,24,23,24,24,
24,24,24,24,24,24,25,22,20,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,22,21,
23,24,24,24,24,24,24,24,24,24,24,24,25,22,21,25,24,24,24,24,24,24,24,24,24,24,
24,24,23,23,22,21,22,25,25,24,24,24,24,24,24,25,25,24,23,22,20,24,24,24,24,24,
24,24,24,24,24,23,23,23,20,20,20,20,20,21,21,21,21,20,20,21,21,20,21,21,21,20,
20,22,23,22,22,22,21,21,21,21,21,20,20,20,20,22,24,23,23,23,25,24,23,23,21,22,
20,20,21,25,24,24,23,23,22,23,23,23,23,23,23,22,23,23,22,21,20,24,24,24,24,23,
23,24,22,23,24,23,26,20,25,8,8,25,24,24,24,24,24,25,24,24,25,24,25,8,9,26,20,22,
22,23,23,23,23,23,23,23,22,22,23,20,24,24,23,23,23,23,22,23,22,22,22,22,22,22,
22,23,23,23,20,23,23,23,23,23,23,23,23,23,23,23,22,21,23,24,24,24,24,24,23,24,
23,23,23,22,22,23,23,23,22,22,21,23,24,24,23,23,24,24,24,24,24,24,23,21,23,23,
23,24,24,23,23,24,24,23,23,23,24,24,23,23,22,23,20,23,24,24,24,24,24,24,24,24,
24,24,23,21,23,23,23,24,24,24,24,24,24,24,24,24,23,24,23,23,24,24,20,23,24,24,
24,24,24,24,24,24,24,24,22,21,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,
24,24,21,23,24,24,24,24,24,24,24,24,24,24,23,21,23,24,24,24,24,24,24,24,24,24,
24,24,24,24,24,24,24,24,20,24,24,24,24,24,24,24,23,24,24,24,23,20,22,24,24,24,
24,24,24,24,24,24,24,24,24,23,23,24,24,24,20,24,24,24,24,24,24,24,24,24,24,24,
23,20,22,25,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,20,21,22,21,22,24,
24,24,24,24,24,24,23,21,21,23,24,23,23,24,24,24,24,24,24,23,23,23,23,23,24,24,
19,19,20,19,19,19,20,20,20,21,21,21,21,20,21,21,21,21,20,21,21,21,21,22,22,21,
21,21,20,20,20,20,24,24,24,24,24,23,22,20,24,24,24,25,25,25,25,25,25,25,25,25,
25,25,23,20,22,24,24,25,25,25,24,24,23,23,23,23,23,23,22,20,24,22,23,23,23,23,
23,23,23,23,22,22,22,22,23,20,23,23,24,23,22,22,21,22,21,22,22,21,21,22,23,20,
22,23,23,24,23,23,23,23,23,23,22,22,22,22,23,20,22,24,23,23,23,22,20,21,23,23,
23,23,22,22,23,20,23,23,23,24,24,23,23,23,23,23,23,23,23,23,23,20,22,24,23,23,
23,23,23,23,24,24,24,24,24,24,23,20,23,24,24,24,24,24,24,24,24,24,24,24,24,24,
23,20,22,24,24,24,24,24,24,24,24,24,24,24,24,24,23,20,23,24,24,24,24,24,24,24,
24,24,24,24,24,24,24,20,22,24,24,24,24,24,24,24,24,24,24,24,24,24,23,20,24,24,
24,24,24,24,24,24,24,24,24,24,24,24,24,20,22,24,24,24,24,24,24,24,24,24,24,24,
24,24,23,21,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,20,22,24,24,24,24,24,
24,24,24,24,24,23,23,23,23,20,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,19,
22,24,24,24,24,24,24,24
}; // level1Texture
#endif // guard

BIN
programs/pokitto/modelViewer.bin Executable file

Binary file not shown.

File diff suppressed because it is too large Load diff