1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-11-23 20:59:58 +01:00

Rename functions

This commit is contained in:
Miloslav Ciz 2021-12-28 16:25:22 -06:00
parent 116a93fea0
commit da45121e10
20 changed files with 107 additions and 107 deletions

View file

@ -21519,7 +21519,7 @@ S3L_Model3D alligatorModel;
void alligatorModelInit() void alligatorModelInit()
{ {
S3L_initModel3D( S3L_model3DInit(
alligatorVertices, alligatorVertices,
ALLIGATOR_VERTEX_COUNT, ALLIGATOR_VERTEX_COUNT,
alligatorTriangleIndices, alligatorTriangleIndices,

View file

@ -93,7 +93,7 @@ S3L_Model3D carModel;
void carModelInit() void carModelInit()
{ {
S3L_initModel3D( S3L_model3DInit(
carVertices, carVertices,
CAR_VERTEX_COUNT, CAR_VERTEX_COUNT,
carTriangleIndices, carTriangleIndices,

View file

@ -398,7 +398,7 @@ S3L_Model3D cat1Model;
void cat1ModelInit() void cat1ModelInit()
{ {
S3L_initModel3D( S3L_model3DInit(
cat1Vertices, cat1Vertices,
CAT1_VERTEX_COUNT, CAT1_VERTEX_COUNT,
cat1TriangleIndices, cat1TriangleIndices,

View file

@ -398,7 +398,7 @@ S3L_Model3D cat2Model;
void cat2ModelInit() void cat2ModelInit()
{ {
S3L_initModel3D( S3L_model3DInit(
cat2Vertices, cat2Vertices,
CAT2_VERTEX_COUNT, CAT2_VERTEX_COUNT,
cat2TriangleIndices, cat2TriangleIndices,

View file

@ -757,7 +757,7 @@ S3L_Model3D chestModel;
void chestModelInit() void chestModelInit()
{ {
S3L_initModel3D( S3L_model3DInit(
chestVertices, chestVertices,
CHEST_VERTEX_COUNT, CHEST_VERTEX_COUNT,
chestTriangleIndices, chestTriangleIndices,

View file

@ -195,9 +195,9 @@ int main()
models[0] = cityModel; models[0] = cityModel;
models[1] = carModel; models[1] = carModel;
S3L_initScene(models,2,&scene); S3L_sceneInit(models,2,&scene);
S3L_setTransform3D(1909,16,-3317,0,-510,0,512,512,512,&(models[1].transform)); S3L_transform3DSet(1909,16,-3317,0,-510,0,512,512,512,&(models[1].transform));
int running = 1; int running = 1;
@ -207,7 +207,7 @@ int main()
S3L_Vec4 carDirection; S3L_Vec4 carDirection;
S3L_initVec4(&carDirection); S3L_vec4Init(&carDirection);
scene.camera.transform.translation.y = S3L_FRACTIONS_PER_UNIT / 2; scene.camera.transform.translation.y = S3L_FRACTIONS_PER_UNIT / 2;
scene.camera.transform.rotation.x = -S3L_FRACTIONS_PER_UNIT / 16; scene.camera.transform.rotation.x = -S3L_FRACTIONS_PER_UNIT / 16;

View file

@ -947,7 +947,7 @@ S3L_Model3D cityModel;
void cityModelInit() void cityModelInit()
{ {
S3L_initModel3D( S3L_model3DInit(
cityVertices, cityVertices,
CITY_VERTEX_COUNT, CITY_VERTEX_COUNT,
cityTriangleIndices, cityTriangleIndices,

View file

@ -79,10 +79,10 @@ void drawPixel(S3L_PixelInfo *p)
normal.y = S3L_interpolateBarycentric(n0.y,n1.y,n2.y,p->barycentric); normal.y = S3L_interpolateBarycentric(n0.y,n1.y,n2.y,p->barycentric);
normal.z = S3L_interpolateBarycentric(n0.z,n1.z,n2.z,p->barycentric); normal.z = S3L_interpolateBarycentric(n0.z,n1.z,n2.z,p->barycentric);
S3L_normalizeVec3(&normal); S3L_vec3Normalize(&normal);
S3L_Unit shading = S3L_Unit shading =
(S3L_dotProductVec3(normal,toLight) + S3L_FRACTIONS_PER_UNIT) / 2; (S3L_vec3Dot(normal,toLight) + S3L_FRACTIONS_PER_UNIT) / 2;
shading = S3L_interpolate(shading,0,p->depth,32 * S3L_FRACTIONS_PER_UNIT); shading = S3L_interpolate(shading,0,p->depth,32 * S3L_FRACTIONS_PER_UNIT);
@ -95,15 +95,15 @@ void drawPixel(S3L_PixelInfo *p)
int main() int main()
{ {
S3L_setVec4(&toLight,10,-10,-10,0); S3L_vec4Set(&toLight,10,-10,-10,0);
S3L_normalizeVec3(&toLight); S3L_vec3Normalize(&toLight);
alligatorModelInit(); alligatorModelInit();
S3L_computeModelNormals(alligatorModel,normals,0); S3L_computeModelNormals(alligatorModel,normals,0);
S3L_initScene(&alligatorModel,1,&scene); S3L_sceneInit(&alligatorModel,1,&scene);
scene.camera.transform.translation.z = -8 * S3L_FRACTIONS_PER_UNIT; scene.camera.transform.translation.z = -8 * S3L_FRACTIONS_PER_UNIT;
scene.camera.transform.translation.x = 9 * S3L_FRACTIONS_PER_UNIT; scene.camera.transform.translation.x = 9 * S3L_FRACTIONS_PER_UNIT;

View file

@ -721,7 +721,7 @@ S3L_Model3D houseModel;
void houseModelInit() void houseModelInit()
{ {
S3L_initModel3D( S3L_model3DInit(
houseVertices, houseVertices,
HOUSE_VERTEX_COUNT, HOUSE_VERTEX_COUNT,
houseTriangleIndices, houseTriangleIndices,

View file

@ -213,7 +213,7 @@ void drawPixel(S3L_PixelInfo *p)
toCameraDirection.x = scene.camera.transform.translation.x - position.x; toCameraDirection.x = scene.camera.transform.translation.x - position.x;
toCameraDirection.y = scene.camera.transform.translation.y - position.y; toCameraDirection.y = scene.camera.transform.translation.y - position.y;
toCameraDirection.z = scene.camera.transform.translation.z - position.z; toCameraDirection.z = scene.camera.transform.translation.z - position.z;
S3L_normalizeVec3(&toCameraDirection); S3L_vec3Normalize(&toCameraDirection);
if (p->modelIndex == WATER_MODEL_INDEX) if (p->modelIndex == WATER_MODEL_INDEX)
{ {
@ -267,11 +267,11 @@ void drawPixel(S3L_PixelInfo *p)
v = S3L_interpolateBarycentric(uv0.y,uv1.y,uv2.y,p->barycentric) / ((float) S3L_FRACTIONS_PER_UNIT); v = S3L_interpolateBarycentric(uv0.y,uv1.y,uv2.y,p->barycentric) / ((float) S3L_FRACTIONS_PER_UNIT);
} }
S3L_normalizeVec3(&normal); S3L_vec3Normalize(&normal);
S3L_reflect(toLightDirection,normal,&reflected); S3L_reflect(toLightDirection,normal,&reflected);
float diffuse = 0.5 - (S3L_dotProductVec3(toLightDirection,normal) / ((float) S3L_FRACTIONS_PER_UNIT)) * 0.5; float diffuse = 0.5 - (S3L_vec3Dot(toLightDirection,normal) / ((float) S3L_FRACTIONS_PER_UNIT)) * 0.5;
float specular = 0.5 + (S3L_dotProductVec3(reflected,toCameraDirection) / ((float) S3L_FRACTIONS_PER_UNIT)) * 0.5; float specular = 0.5 + (S3L_vec3Dot(reflected,toCameraDirection) / ((float) S3L_FRACTIONS_PER_UNIT)) * 0.5;
float fog = (p->depth / ((float) S3L_FRACTIONS_PER_UNIT * 20)); float fog = (p->depth / ((float) S3L_FRACTIONS_PER_UNIT * 20));
if (fog > 1.0) if (fog > 1.0)
@ -298,7 +298,7 @@ void drawPixel(S3L_PixelInfo *p)
previousColor[1] = frameBuffer[index + 1]; previousColor[1] = frameBuffer[index + 1];
previousColor[2] = frameBuffer[index + 2]; previousColor[2] = frameBuffer[index + 2];
float fresnel = 0.5 + (S3L_dotProductVec3(toCameraDirection,normal) / ((float) S3L_FRACTIONS_PER_UNIT)) * 0.5; float fresnel = 0.5 + (S3L_vec3Dot(toCameraDirection,normal) / ((float) S3L_FRACTIONS_PER_UNIT)) * 0.5;
color[0] = interpolate(150,0,fresnel); color[0] = interpolate(150,0,fresnel);
color[1] = interpolate(230,10,fresnel); color[1] = interpolate(230,10,fresnel);
@ -418,7 +418,7 @@ int main()
toLightDirection.z = 10; toLightDirection.z = 10;
toLightDirection.w = 0; toLightDirection.w = 0;
S3L_normalizeVec3(&toLightDirection); S3L_vec3Normalize(&toLightDirection);
treeModelInit(); treeModelInit();
@ -428,11 +428,11 @@ int main()
S3L_Unit scale = S3L_FRACTIONS_PER_UNIT / 4; S3L_Unit scale = S3L_FRACTIONS_PER_UNIT / 4;
S3L_setTransform3D(0,1.2 * S3L_FRACTIONS_PER_UNIT,-1.5 * S3L_FRACTIONS_PER_UNIT,0,0,0,scale,scale,scale,&(models[0].transform)); S3L_transform3DSet(0,1.2 * S3L_FRACTIONS_PER_UNIT,-1.5 * S3L_FRACTIONS_PER_UNIT,0,0,0,scale,scale,scale,&(models[0].transform));
S3L_setTransform3D(0.95 * S3L_FRACTIONS_PER_UNIT,1.3 * S3L_FRACTIONS_PER_UNIT,0,0,0,0,scale,scale * 1.3,scale,&(models[1].transform)); S3L_transform3DSet(0.95 * S3L_FRACTIONS_PER_UNIT,1.3 * S3L_FRACTIONS_PER_UNIT,0,0,0,0,scale,scale * 1.3,scale,&(models[1].transform));
S3L_setTransform3D(-2 * S3L_FRACTIONS_PER_UNIT,0.8 * S3L_FRACTIONS_PER_UNIT,1.5 * S3L_FRACTIONS_PER_UNIT,0,0,0,scale,scale,scale,&(models[2].transform)); S3L_transform3DSet(-2 * S3L_FRACTIONS_PER_UNIT,0.8 * S3L_FRACTIONS_PER_UNIT,1.5 * S3L_FRACTIONS_PER_UNIT,0,0,0,scale,scale,scale,&(models[2].transform));
S3L_initModel3D( S3L_model3DInit(
terrainVertices, terrainVertices,
GRID_W * GRID_H, GRID_W * GRID_H,
gridTriangles, gridTriangles,
@ -442,21 +442,21 @@ int main()
S3L_computeModelNormals(models[ISLAND_MODEL_INDEX],terrainNormals,0); S3L_computeModelNormals(models[ISLAND_MODEL_INDEX],terrainNormals,0);
S3L_computeModelNormals(treeModel,treeNormals,0); S3L_computeModelNormals(treeModel,treeNormals,0);
S3L_initModel3D( S3L_model3DInit(
waterVertices, waterVertices,
GRID_W * GRID_H, GRID_W * GRID_H,
gridTriangles, gridTriangles,
GRID_TRIANGLES, GRID_TRIANGLES,
&(models[WATER_MODEL_INDEX])); &(models[WATER_MODEL_INDEX]));
S3L_initScene(models,MODELS_TOTAL,&scene); S3L_sceneInit(models,MODELS_TOTAL,&scene);
char fileName[] = "test00.ppm"; char fileName[] = "test00.ppm";
S3L_Transform3D transform0, transform1; S3L_Transform3D transform0, transform1;
S3L_initTransform3D(&transform0); S3L_transform3DInit(&transform0);
S3L_initTransform3D(&transform1); S3L_transform3DInit(&transform1);
transform0.translation.x = -2 * S3L_FRACTIONS_PER_UNIT; transform0.translation.x = -2 * S3L_FRACTIONS_PER_UNIT;
transform0.translation.y = 5 * S3L_FRACTIONS_PER_UNIT; transform0.translation.y = 5 * S3L_FRACTIONS_PER_UNIT;

View file

@ -238,7 +238,7 @@ int main()
levelModelInit(); levelModelInit();
S3L_initScene(&levelModel,1,&scene); S3L_sceneInit(&levelModel,1,&scene);
int running = 1; int running = 1;

View file

@ -1390,7 +1390,7 @@ S3L_Model3D levelModel;
void levelModelInit() void levelModelInit()
{ {
S3L_initModel3D( S3L_model3DInit(
levelVertices, levelVertices,
LEVEL_VERTEX_COUNT, LEVEL_VERTEX_COUNT,
levelTriangleIndices, levelTriangleIndices,

View file

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
PROGRAM=test PROGRAM=testTerminal
clear; clear; g++ -x c -g -fmax-errors=5 -pedantic -O3 -Wall -Wextra -Wstrict-prototypes -Wold-style-definition -Wno-unused-parameter -Wno-missing-field-initializers -o $PROGRAM $PROGRAM.c -lSDL2 2>&1 >/dev/null && ./$PROGRAM clear; clear; g++ -x c -g -fmax-errors=5 -pedantic -O3 -Wall -Wextra -Wstrict-prototypes -Wold-style-definition -Wno-unused-parameter -Wno-missing-field-initializers -o $PROGRAM $PROGRAM.c -lSDL2 2>&1 >/dev/null && ./$PROGRAM
#clear; clear; clang -x c -g -pedantic -O3 -Wall -Wextra -o $PROGRAM $PROGRAM.c -lSDL2 2>&1 >/dev/null && ./$PROGRAM #clear; clear; clang -x c -g -pedantic -O3 -Wall -Wextra -o $PROGRAM $PROGRAM.c -lSDL2 2>&1 >/dev/null && ./$PROGRAM

View file

@ -187,9 +187,9 @@ void drawPixel(S3L_PixelInfo *p)
{ {
S3L_getIndexedTriangleValues(p->triangleIndex,model.triangles,normals,3,&n0,&n1,&n2); S3L_getIndexedTriangleValues(p->triangleIndex,model.triangles,normals,3,&n0,&n1,&n2);
l0 = 256 + S3L_clamp(S3L_dotProductVec3(n0,toLight),-511,511) / 2; l0 = 256 + S3L_clamp(S3L_vec3Dot(n0,toLight),-511,511) / 2;
l1 = 256 + S3L_clamp(S3L_dotProductVec3(n1,toLight),-511,511) / 2; l1 = 256 + S3L_clamp(S3L_vec3Dot(n1,toLight),-511,511) / 2;
l2 = 256 + S3L_clamp(S3L_dotProductVec3(n2,toLight),-511,511) / 2; l2 = 256 + S3L_clamp(S3L_vec3Dot(n2,toLight),-511,511) / 2;
} }
previousTriangle = p->triangleID; previousTriangle = p->triangleID;
@ -242,7 +242,7 @@ void drawPixel(S3L_PixelInfo *p)
n.y = S3L_interpolateBarycentric(n0.y,n1.y,n2.y,p->barycentric); n.y = S3L_interpolateBarycentric(n0.y,n1.y,n2.y,p->barycentric);
n.z = S3L_interpolateBarycentric(n0.z,n1.z,n2.z,p->barycentric); n.z = S3L_interpolateBarycentric(n0.z,n1.z,n2.z,p->barycentric);
S3L_normalizeVec3(&n); S3L_vec3Normalize(&n);
r = S3L_clamp(128 + n.x / 4,0,255); r = S3L_clamp(128 + n.x / 4,0,255);
g = S3L_clamp(128 + n.y / 4,0,255); g = S3L_clamp(128 + n.y / 4,0,255);
@ -346,8 +346,8 @@ void setModel(uint8_t index)
#undef modelCase #undef modelCase
S3L_initTransform3D(&(scene.models[0].transform)); S3L_transform3DInit(&(scene.models[0].transform));
S3L_initDrawConfig(&(scene.models[0].config)); S3L_drawConfigInit(&(scene.models[0].config));
if (index == 3) if (index == 3)
{ {
@ -380,9 +380,9 @@ int main()
toLight.y = 10; toLight.y = 10;
toLight.z = 10; toLight.z = 10;
S3L_normalizeVec3(&toLight); S3L_vec3Normalize(&toLight);
S3L_initScene(&model,1,&scene); S3L_sceneInit(&model,1,&scene);
houseModelInit(); houseModelInit();
chestModelInit(); chestModelInit();

View file

@ -45,7 +45,7 @@ S3L_Model3D plantModel;
void plantModelInit() void plantModelInit()
{ {
S3L_initModel3D( S3L_model3DInit(
plantVertices, plantVertices,
PLANT_VERTEX_COUNT, PLANT_VERTEX_COUNT,
plantTriangleIndices, plantTriangleIndices,

View file

@ -104,9 +104,9 @@ int testTriangleRasterization(
S3L_Vec4 p0, p1, p2; S3L_Vec4 p0, p1, p2;
S3L_setVec4(&p0,x0,y0,1000,0); S3L_vec4Set(&p0,x0,y0,1000,0);
S3L_setVec4(&p1,x1,y1,1000,0); S3L_vec4Set(&p1,x1,y1,1000,0);
S3L_setVec4(&p2,x2,y2,1000,0); S3L_vec4Set(&p2,x2,y2,1000,0);
S3L_drawTriangle(p0,p1,p2,0,0); S3L_drawTriangle(p0,p1,p2,0,0);
@ -329,9 +329,9 @@ int testRasterization(void)
#define dt(i1,i2,i3)\ #define dt(i1,i2,i3)\
{\ {\
S3L_Vec4 p0, p1, p2;\ S3L_Vec4 p0, p1, p2;\
S3L_setVec4(&p0,coords[2*i1],coords[2*i1 + 1],1000,0);\ S3L_vec4Set(&p0,coords[2*i1],coords[2*i1 + 1],1000,0);\
S3L_setVec4(&p1,coords[2*i2],coords[2*i2+1],1000,0);\ S3L_vec4Set(&p1,coords[2*i2],coords[2*i2+1],1000,0);\
S3L_setVec4(&p2,coords[2*i3],coords[2*i3+1],1000,0);\ S3L_vec4Set(&p2,coords[2*i3],coords[2*i3+1],1000,0);\
S3L_drawTriangle(p0,p1,p2,0,0);\ S3L_drawTriangle(p0,p1,p2,0,0);\
} }
@ -433,14 +433,14 @@ int testGeneral(void)
{ {
S3L_Vec4 v; S3L_Vec4 v;
S3L_setVec4(&v,x,y,z,0); S3L_vec4Set(&v,x,y,z,0);
S3L_normalizeVec3Fast(&v); S3L_vec3NormalizeFast(&v);
double l0 = vec3Len(v); double l0 = vec3Len(v);
double e0 = absVal(l0 - S3L_FRACTIONS_PER_UNIT); double e0 = absVal(l0 - S3L_FRACTIONS_PER_UNIT);
S3L_setVec4(&v,x,y,z,0); S3L_vec4Set(&v,x,y,z,0);
S3L_normalizeVec3(&v); S3L_vec3Normalize(&v);
double l1 = vec3Len(v); double l1 = vec3Len(v);
double e1 = absVal(l1 - S3L_FRACTIONS_PER_UNIT); double e1 = absVal(l1 - S3L_FRACTIONS_PER_UNIT);
@ -478,8 +478,8 @@ int testRender(void)
memset(testScreen,'.',S3L_RESOLUTION_X * S3L_RESOLUTION_Y); memset(testScreen,'.',S3L_RESOLUTION_X * S3L_RESOLUTION_Y);
S3L_initModel3D(cubeVertices,S3L_CUBE_VERTEX_COUNT,cubeTriangles,S3L_CUBE_TRIANGLE_COUNT,&cubeModel); S3L_model3DInit(cubeVertices,S3L_CUBE_VERTEX_COUNT,cubeTriangles,S3L_CUBE_TRIANGLE_COUNT,&cubeModel);
S3L_initModel3D(triangleVertices,3,triangleTriangles,1,&triangleModel); S3L_model3DInit(triangleVertices,3,triangleTriangles,1,&triangleModel);
models[0] = cubeModel; models[0] = cubeModel;
models[0].transform.translation.z -= S3L_FRACTIONS_PER_UNIT; models[0].transform.translation.z -= S3L_FRACTIONS_PER_UNIT;
@ -500,7 +500,7 @@ int testRender(void)
models[3].transform.translation.y = 1200; models[3].transform.translation.y = 1200;
models[3].transform.rotation.x = S3L_FRACTIONS_PER_UNIT / 2; // turn away, test BF culling models[3].transform.rotation.x = S3L_FRACTIONS_PER_UNIT / 2; // turn away, test BF culling
S3L_initScene(models,4,&scene); S3L_sceneInit(models,4,&scene);
scene.camera.transform.translation.z = -2 * S3L_FRACTIONS_PER_UNIT; scene.camera.transform.translation.z = -2 * S3L_FRACTIONS_PER_UNIT;
scene.camera.transform.translation.y = S3L_FRACTIONS_PER_UNIT / 3; scene.camera.transform.translation.y = S3L_FRACTIONS_PER_UNIT / 3;
@ -534,10 +534,10 @@ int main(void)
S3L_Mat4 m, m2; S3L_Mat4 m, m2;
S3L_Vec4 v; S3L_Vec4 v;
S3L_initMat4(&m); S3L_mat4Init(&m);
S3L_logMat4(m); S3L_logMat4(m);
S3L_initVec4(&v); S3L_vec4Init(&v);
S3L_logVec4(v); S3L_logVec4(v);

View file

@ -55,14 +55,14 @@ void drawPixel(S3L_PixelInfo *p)
int main() int main()
{ {
S3L_initModel3D( S3L_model3DInit(
cubeVertices, cubeVertices,
S3L_CUBE_VERTEX_COUNT, S3L_CUBE_VERTEX_COUNT,
cubeTriangles, cubeTriangles,
S3L_CUBE_TRIANGLE_COUNT, S3L_CUBE_TRIANGLE_COUNT,
&cubeModel); &cubeModel);
S3L_initScene( // Initialize the scene we'll be rendering. S3L_sceneInit( // Initialize the scene we'll be rendering.
&cubeModel, // This is like an array with only one model in it. &cubeModel, // This is like an array with only one model in it.
1, 1,
&scene); &scene);

View file

@ -189,7 +189,7 @@ S3L_Model3D treeModel;
void treeModelInit() void treeModelInit()
{ {
S3L_initModel3D( S3L_model3DInit(
treeVertices, treeVertices,
TREE_VERTEX_COUNT, TREE_VERTEX_COUNT,
treeTriangleIndices, treeTriangleIndices,

View file

@ -10,7 +10,7 @@
license: CC0 1.0 (public domain) license: CC0 1.0 (public domain)
found at https://creativecommons.org/publicdomain/zero/1.0/ found at https://creativecommons.org/publicdomain/zero/1.0/
+ additional waiver of all IP + additional waiver of all IP
version: 0.853d version: 0.860d
Before including the library, define S3L_PIXEL_FUNCTION to the name of the Before including the library, define S3L_PIXEL_FUNCTION to the name of the
function you'll be using to draw single pixels (this function will be called function you'll be using to draw single pixels (this function will be called
@ -363,8 +363,8 @@ typedef struct
#define S3L_logVec4(v)\ #define S3L_logVec4(v)\
printf("Vec4: %d %d %d %d\n",((v).x),((v).y),((v).z),((v).w)) printf("Vec4: %d %d %d %d\n",((v).x),((v).y),((v).z),((v).w))
static inline void S3L_initVec4(S3L_Vec4 *v); static inline void S3L_vec4Init(S3L_Vec4 *v);
static inline void S3L_setVec4(S3L_Vec4 *v, S3L_Unit x, S3L_Unit y, static inline void S3L_vec4Set(S3L_Vec4 *v, S3L_Unit x, S3L_Unit y,
S3L_Unit z, S3L_Unit w); S3L_Unit z, S3L_Unit w);
static inline void S3L_vec3Add(S3L_Vec4 *result, S3L_Vec4 added); static inline void S3L_vec3Add(S3L_Vec4 *result, S3L_Vec4 added);
static inline void S3L_vec3Sub(S3L_Vec4 *result, S3L_Vec4 substracted); static inline void S3L_vec3Sub(S3L_Vec4 *result, S3L_Vec4 substracted);
@ -373,16 +373,16 @@ S3L_Unit S3L_vec3Length(S3L_Vec4 v);
/** Normalizes Vec3. Note that this function tries to normalize correctly /** Normalizes Vec3. Note that this function tries to normalize correctly
rather than quickly! If you need to normalize quickly, do it yourself in a rather than quickly! If you need to normalize quickly, do it yourself in a
way that best fits your case. */ way that best fits your case. */
void S3L_normalizeVec3(S3L_Vec4 *v); void S3L_vec3Normalize(S3L_Vec4 *v);
/** Like S3L_normalizeVec3, but doesn't perform any checks on the input vector, /** Like S3L_vec3Normalize, but doesn't perform any checks on the input vector,
which is faster, but can be very innacurate or overflowing. You are supposed which is faster, but can be very innacurate or overflowing. You are supposed
to provide a "nice" vector (not too big or small). */ to provide a "nice" vector (not too big or small). */
static inline void S3L_normalizeVec3Fast(S3L_Vec4 *v); static inline void S3L_vec3NormalizeFast(S3L_Vec4 *v);
S3L_Unit S3L_vec2Length(S3L_Vec4 v); S3L_Unit S3L_vec2Length(S3L_Vec4 v);
void S3L_crossProduct(S3L_Vec4 a, S3L_Vec4 b, S3L_Vec4 *result); void S3L_vec3Cross(S3L_Vec4 a, S3L_Vec4 b, S3L_Vec4 *result);
static inline S3L_Unit S3L_dotProductVec3(S3L_Vec4 a, S3L_Vec4 b); static inline S3L_Unit S3L_vec3Dot(S3L_Vec4 a, S3L_Vec4 b);
/** Computes a reflection direction (typically used e.g. for specular component /** Computes a reflection direction (typically used e.g. for specular component
in Phong illumination). The input vectors must be normalized. The result will in Phong illumination). The input vectors must be normalized. The result will
@ -415,11 +415,11 @@ typedef struct
(t).rotation.x,(t).rotation.y,(t).rotation.z,\ (t).rotation.x,(t).rotation.y,(t).rotation.z,\
(t).scale.x,(t).scale.y,(t).scale.z) (t).scale.x,(t).scale.y,(t).scale.z)
static inline void S3L_initTransform3D(S3L_Transform3D *t); static inline void S3L_transform3DInit(S3L_Transform3D *t);
void S3L_lookAt(S3L_Vec4 pointTo, S3L_Transform3D *t); void S3L_lookAt(S3L_Vec4 pointTo, S3L_Transform3D *t);
void S3L_setTransform3D( void S3L_transform3DSet(
S3L_Unit tx, S3L_Unit tx,
S3L_Unit ty, S3L_Unit ty,
S3L_Unit tz, S3L_Unit tz,
@ -452,11 +452,11 @@ typedef S3L_Unit S3L_Mat4[4][4];
(m)[0][3],(m)[1][3],(m)[2][3],(m)[3][3]) (m)[0][3],(m)[1][3],(m)[2][3],(m)[3][3])
/** Initializes a 4x4 matrix to identity. */ /** Initializes a 4x4 matrix to identity. */
static inline void S3L_initMat4(S3L_Mat4 m); static inline void S3L_mat4Init(S3L_Mat4 m);
void S3L_copyMat4(S3L_Mat4 src, S3L_Mat4 dst); void S3L_mat4Copy(S3L_Mat4 src, S3L_Mat4 dst);
void S3L_transposeMat4(S3L_Mat4 m); void S3L_mat4Transpose(S3L_Mat4 m);
void S3L_makeTranslationMat( void S3L_makeTranslationMat(
S3L_Unit offsetX, S3L_Unit offsetX,
@ -502,7 +502,7 @@ typedef struct
S3L_Transform3D transform; S3L_Transform3D transform;
} S3L_Camera; } S3L_Camera;
void S3L_initCamera(S3L_Camera *camera); void S3L_cameraInit(S3L_Camera *camera);
typedef struct typedef struct
{ {
@ -514,7 +514,7 @@ typedef struct
int8_t visible; /**< Can be used to easily hide the model. */ int8_t visible; /**< Can be used to easily hide the model. */
} S3L_DrawConfig; } S3L_DrawConfig;
void S3L_initDrawConfig(S3L_DrawConfig *config); void S3L_drawConfigInit(S3L_DrawConfig *config);
typedef struct typedef struct
{ {
@ -530,7 +530,7 @@ typedef struct
S3L_DrawConfig config; S3L_DrawConfig config;
} S3L_Model3D; ///< Represents a 3D model. } S3L_Model3D; ///< Represents a 3D model.
void S3L_initModel3D( void S3L_model3DInit(
const S3L_Unit *vertices, const S3L_Unit *vertices,
S3L_Index vertexCount, S3L_Index vertexCount,
const S3L_Index *triangles, const S3L_Index *triangles,
@ -544,7 +544,7 @@ typedef struct
S3L_Camera camera; S3L_Camera camera;
} S3L_Scene; ///< Represent the 3D scene to be rendered. } S3L_Scene; ///< Represent the 3D scene to be rendered.
void S3L_initScene( void S3L_sceneInit(
S3L_Model3D *models, S3L_Model3D *models,
S3L_Index modelCount, S3L_Index modelCount,
S3L_Scene *scene); S3L_Scene *scene);
@ -580,7 +580,7 @@ typedef struct
} S3L_PixelInfo; /**< Used to pass the info about a rasterized pixel } S3L_PixelInfo; /**< Used to pass the info about a rasterized pixel
(fragment) to the user-defined drawing func. */ (fragment) to the user-defined drawing func. */
static inline void S3L_initPixelInfo(S3L_PixelInfo *p); static inline void S3L_pixelInfoInit(S3L_PixelInfo *p);
/** Corrects barycentric coordinates so that they exactly meet the defined /** Corrects barycentric coordinates so that they exactly meet the defined
conditions (each fall into <0,S3L_FRACTIONS_PER_UNIT>, sum = conditions (each fall into <0,S3L_FRACTIONS_PER_UNIT>, sum =
@ -954,12 +954,12 @@ static const S3L_Unit S3L_sinTable[S3L_SIN_TABLE_LENGTH] =
#define S3L_SIN_TABLE_UNIT_STEP\ #define S3L_SIN_TABLE_UNIT_STEP\
(S3L_FRACTIONS_PER_UNIT / (S3L_SIN_TABLE_LENGTH * 4)) (S3L_FRACTIONS_PER_UNIT / (S3L_SIN_TABLE_LENGTH * 4))
void S3L_initVec4(S3L_Vec4 *v) void S3L_vec4Init(S3L_Vec4 *v)
{ {
v->x = 0; v->y = 0; v->z = 0; v->w = S3L_FRACTIONS_PER_UNIT; v->x = 0; v->y = 0; v->z = 0; v->w = S3L_FRACTIONS_PER_UNIT;
} }
void S3L_setVec4(S3L_Vec4 *v, S3L_Unit x, S3L_Unit y, S3L_Unit z, S3L_Unit w) void S3L_vec4Set(S3L_Vec4 *v, S3L_Unit x, S3L_Unit y, S3L_Unit z, S3L_Unit w)
{ {
v->x = x; v->x = x;
v->y = y; v->y = y;
@ -981,7 +981,7 @@ void S3L_vec3Sub(S3L_Vec4 *result, S3L_Vec4 substracted)
result->z -= substracted.z; result->z -= substracted.z;
} }
void S3L_initMat4(S3L_Mat4 m) void S3L_mat4Init(S3L_Mat4 m)
{ {
#define M(x,y) m[x][y] #define M(x,y) m[x][y]
#define S S3L_FRACTIONS_PER_UNIT #define S S3L_FRACTIONS_PER_UNIT
@ -995,28 +995,28 @@ void S3L_initMat4(S3L_Mat4 m)
#undef S #undef S
} }
void S3L_copyMat4(S3L_Mat4 src, S3L_Mat4 dst) void S3L_mat4Copy(S3L_Mat4 src, S3L_Mat4 dst)
{ {
for (uint8_t j = 0; j < 4; ++j) for (uint8_t j = 0; j < 4; ++j)
for (uint8_t i = 0; i < 4; ++i) for (uint8_t i = 0; i < 4; ++i)
dst[i][j] = src[i][j]; dst[i][j] = src[i][j];
} }
S3L_Unit S3L_dotProductVec3(S3L_Vec4 a, S3L_Vec4 b) S3L_Unit S3L_vec3Dot(S3L_Vec4 a, S3L_Vec4 b)
{ {
return (a.x * b.x + a.y * b.y + a.z * b.z) / S3L_FRACTIONS_PER_UNIT; return (a.x * b.x + a.y * b.y + a.z * b.z) / S3L_FRACTIONS_PER_UNIT;
} }
void S3L_reflect(S3L_Vec4 toLight, S3L_Vec4 normal, S3L_Vec4 *result) void S3L_reflect(S3L_Vec4 toLight, S3L_Vec4 normal, S3L_Vec4 *result)
{ {
S3L_Unit d = 2 * S3L_dotProductVec3(toLight,normal); S3L_Unit d = 2 * S3L_vec3Dot(toLight,normal);
result->x = (normal.x * d) / S3L_FRACTIONS_PER_UNIT - toLight.x; result->x = (normal.x * d) / S3L_FRACTIONS_PER_UNIT - toLight.x;
result->y = (normal.y * d) / S3L_FRACTIONS_PER_UNIT - toLight.y; result->y = (normal.y * d) / S3L_FRACTIONS_PER_UNIT - toLight.y;
result->z = (normal.z * d) / S3L_FRACTIONS_PER_UNIT - toLight.z; result->z = (normal.z * d) / S3L_FRACTIONS_PER_UNIT - toLight.z;
} }
void S3L_crossProduct(S3L_Vec4 a, S3L_Vec4 b, S3L_Vec4 *result) void S3L_vec3Cross(S3L_Vec4 a, S3L_Vec4 b, S3L_Vec4 *result)
{ {
result->x = a.y * b.z - a.z * b.y; result->x = a.y * b.z - a.z * b.y;
result->y = a.z * b.x - a.x * b.z; result->y = a.z * b.x - a.x * b.z;
@ -1037,9 +1037,9 @@ void S3L_triangleNormal(S3L_Vec4 t0, S3L_Vec4 t1, S3L_Vec4 t2, S3L_Vec4 *n)
#undef ANTI_OVERFLOW #undef ANTI_OVERFLOW
S3L_crossProduct(t1,t2,n); S3L_vec3Cross(t1,t2,n);
S3L_normalizeVec3(n); S3L_vec3Normalize(n);
} }
void S3L_getIndexedTriangleValues( void S3L_getIndexedTriangleValues(
@ -1161,7 +1161,7 @@ void S3L_computeModelNormals(S3L_Model3D model, S3L_Unit *dst,
n.y /= normalCount; n.y /= normalCount;
n.z /= normalCount; n.z /= normalCount;
S3L_normalizeVec3(&n); S3L_vec3Normalize(&n);
} }
dst[vPos] = n.x; dst[vPos] = n.x;
@ -1523,7 +1523,7 @@ S3L_Unit S3L_vec2Length(S3L_Vec4 v)
return S3L_sqrt(v.x * v.x + v.y * v.y); return S3L_sqrt(v.x * v.x + v.y * v.y);
} }
void S3L_normalizeVec3(S3L_Vec4 *v) void S3L_vec3Normalize(S3L_Vec4 *v)
{ {
#define SCALE 16 #define SCALE 16
#define BOTTOM_LIMIT 16 #define BOTTOM_LIMIT 16
@ -1567,7 +1567,7 @@ void S3L_normalizeVec3(S3L_Vec4 *v)
v->z = (v->z * S3L_FRACTIONS_PER_UNIT) / l; v->z = (v->z * S3L_FRACTIONS_PER_UNIT) / l;
} }
void S3L_normalizeVec3Fast(S3L_Vec4 *v) void S3L_vec3NormalizeFast(S3L_Vec4 *v)
{ {
S3L_Unit l = S3L_vec3Length(*v); S3L_Unit l = S3L_vec3Length(*v);
@ -1579,10 +1579,10 @@ void S3L_normalizeVec3Fast(S3L_Vec4 *v)
v->z = (v->z * S3L_FRACTIONS_PER_UNIT) / l; v->z = (v->z * S3L_FRACTIONS_PER_UNIT) / l;
} }
void S3L_initTransform3D(S3L_Transform3D *t) void S3L_transform3DInit(S3L_Transform3D *t)
{ {
S3L_initVec4(&(t->translation)); S3L_vec4Init(&(t->translation));
S3L_initVec4(&(t->rotation)); S3L_vec4Init(&(t->rotation));
t->scale.x = S3L_FRACTIONS_PER_UNIT; t->scale.x = S3L_FRACTIONS_PER_UNIT;
t->scale.y = S3L_FRACTIONS_PER_UNIT; t->scale.y = S3L_FRACTIONS_PER_UNIT;
t->scale.z = S3L_FRACTIONS_PER_UNIT; t->scale.z = S3L_FRACTIONS_PER_UNIT;
@ -1659,7 +1659,7 @@ void S3L_lookAt(S3L_Vec4 pointTo, S3L_Transform3D *t)
t->rotation.x = S3L_asin(dx); t->rotation.x = S3L_asin(dx);
} }
void S3L_setTransform3D( void S3L_transform3DSet(
S3L_Unit tx, S3L_Unit tx,
S3L_Unit ty, S3L_Unit ty,
S3L_Unit tz, S3L_Unit tz,
@ -1684,10 +1684,10 @@ void S3L_setTransform3D(
t->scale.z = sz; t->scale.z = sz;
} }
void S3L_initCamera(S3L_Camera *camera) void S3L_cameraInit(S3L_Camera *camera)
{ {
camera->focalLength = S3L_FRACTIONS_PER_UNIT; camera->focalLength = S3L_FRACTIONS_PER_UNIT;
S3L_initTransform3D(&(camera->transform)); S3L_transform3DInit(&(camera->transform));
} }
void S3L_rotationToDirections( void S3L_rotationToDirections(
@ -1726,7 +1726,7 @@ void S3L_rotationToDirections(
} }
} }
void S3L_initPixelInfo(S3L_PixelInfo *p) void S3L_pixelInfoInit(S3L_PixelInfo *p)
{ {
p->x = 0; p->x = 0;
p->y = 0; p->y = 0;
@ -1740,7 +1740,7 @@ void S3L_initPixelInfo(S3L_PixelInfo *p)
p->previousZ = 0; p->previousZ = 0;
} }
void S3L_initModel3D( void S3L_model3DInit(
const S3L_Unit *vertices, const S3L_Unit *vertices,
S3L_Index vertexCount, S3L_Index vertexCount,
const S3L_Index *triangles, const S3L_Index *triangles,
@ -1753,21 +1753,21 @@ void S3L_initModel3D(
model->triangleCount = triangleCount; model->triangleCount = triangleCount;
model->customTransformMatrix = 0; model->customTransformMatrix = 0;
S3L_initTransform3D(&(model->transform)); S3L_transform3DInit(&(model->transform));
S3L_initDrawConfig(&(model->config)); S3L_drawConfigInit(&(model->config));
} }
void S3L_initScene( void S3L_sceneInit(
S3L_Model3D *models, S3L_Model3D *models,
S3L_Index modelCount, S3L_Index modelCount,
S3L_Scene *scene) S3L_Scene *scene)
{ {
scene->models = models; scene->models = models;
scene->modelCount = modelCount; scene->modelCount = modelCount;
S3L_initCamera(&(scene->camera)); S3L_cameraInit(&(scene->camera));
} }
void S3L_initDrawConfig(S3L_DrawConfig *config) void S3L_drawConfigInit(S3L_DrawConfig *config)
{ {
config->backfaceCulling = 2; config->backfaceCulling = 2;
config->visible = 1; config->visible = 1;
@ -1861,7 +1861,7 @@ void S3L_drawTriangle(
S3L_Index triangleIndex) S3L_Index triangleIndex)
{ {
S3L_PixelInfo p; S3L_PixelInfo p;
S3L_initPixelInfo(&p); S3L_pixelInfoInit(&p);
p.modelIndex = modelIndex; p.modelIndex = modelIndex;
p.triangleIndex = triangleIndex; p.triangleIndex = triangleIndex;
p.triangleID = (modelIndex << 16) | triangleIndex; p.triangleID = (modelIndex << 16) | triangleIndex;
@ -2424,7 +2424,7 @@ void S3L_makeWorldMatrix(S3L_Transform3D worldTransform, S3L_Mat4 m)
S3L_mat4Xmat4(m,t); S3L_mat4Xmat4(m,t);
} }
void S3L_transposeMat4(S3L_Mat4 m) void S3L_mat4Transpose(S3L_Mat4 m)
{ {
S3L_Unit tmp; S3L_Unit tmp;
@ -2453,7 +2453,7 @@ void S3L_makeCameraMatrix(S3L_Transform3D cameraTransform, S3L_Mat4 m)
cameraTransform.rotation.z, cameraTransform.rotation.z,
r); r);
S3L_transposeMat4(r); // transposing creates an inverse transform S3L_mat4Transpose(r); // transposing creates an inverse transform
S3L_mat4Xmat4(m,r); S3L_mat4Xmat4(m,r);
} }

View file

@ -207,7 +207,7 @@ print("S3L_Model3D " + NAME + "Model;\n")
print("void " + NAME + "ModelInit()") print("void " + NAME + "ModelInit()")
print("{") print("{")
print(" S3L_initModel3D(") print(" S3L_model3DInit(")
print(" " + NAME + "Vertices,") print(" " + NAME + "Vertices,")
print(" " + NAME.upper() + "_VERTEX_COUNT,") print(" " + NAME.upper() + "_VERTEX_COUNT,")
print(" " + NAME + "TriangleIndices,") print(" " + NAME + "TriangleIndices,")