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:
parent
116a93fea0
commit
da45121e10
20 changed files with 107 additions and 107 deletions
|
@ -21519,7 +21519,7 @@ S3L_Model3D alligatorModel;
|
|||
|
||||
void alligatorModelInit()
|
||||
{
|
||||
S3L_initModel3D(
|
||||
S3L_model3DInit(
|
||||
alligatorVertices,
|
||||
ALLIGATOR_VERTEX_COUNT,
|
||||
alligatorTriangleIndices,
|
||||
|
|
|
@ -93,7 +93,7 @@ S3L_Model3D carModel;
|
|||
|
||||
void carModelInit()
|
||||
{
|
||||
S3L_initModel3D(
|
||||
S3L_model3DInit(
|
||||
carVertices,
|
||||
CAR_VERTEX_COUNT,
|
||||
carTriangleIndices,
|
||||
|
|
|
@ -398,7 +398,7 @@ S3L_Model3D cat1Model;
|
|||
|
||||
void cat1ModelInit()
|
||||
{
|
||||
S3L_initModel3D(
|
||||
S3L_model3DInit(
|
||||
cat1Vertices,
|
||||
CAT1_VERTEX_COUNT,
|
||||
cat1TriangleIndices,
|
||||
|
|
|
@ -398,7 +398,7 @@ S3L_Model3D cat2Model;
|
|||
|
||||
void cat2ModelInit()
|
||||
{
|
||||
S3L_initModel3D(
|
||||
S3L_model3DInit(
|
||||
cat2Vertices,
|
||||
CAT2_VERTEX_COUNT,
|
||||
cat2TriangleIndices,
|
||||
|
|
|
@ -757,7 +757,7 @@ S3L_Model3D chestModel;
|
|||
|
||||
void chestModelInit()
|
||||
{
|
||||
S3L_initModel3D(
|
||||
S3L_model3DInit(
|
||||
chestVertices,
|
||||
CHEST_VERTEX_COUNT,
|
||||
chestTriangleIndices,
|
||||
|
|
|
@ -195,9 +195,9 @@ int main()
|
|||
models[0] = cityModel;
|
||||
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;
|
||||
|
||||
|
@ -207,7 +207,7 @@ int main()
|
|||
|
||||
S3L_Vec4 carDirection;
|
||||
|
||||
S3L_initVec4(&carDirection);
|
||||
S3L_vec4Init(&carDirection);
|
||||
|
||||
scene.camera.transform.translation.y = S3L_FRACTIONS_PER_UNIT / 2;
|
||||
scene.camera.transform.rotation.x = -S3L_FRACTIONS_PER_UNIT / 16;
|
||||
|
|
|
@ -947,7 +947,7 @@ S3L_Model3D cityModel;
|
|||
|
||||
void cityModelInit()
|
||||
{
|
||||
S3L_initModel3D(
|
||||
S3L_model3DInit(
|
||||
cityVertices,
|
||||
CITY_VERTEX_COUNT,
|
||||
cityTriangleIndices,
|
||||
|
|
|
@ -79,10 +79,10 @@ void drawPixel(S3L_PixelInfo *p)
|
|||
normal.y = S3L_interpolateBarycentric(n0.y,n1.y,n2.y,p->barycentric);
|
||||
normal.z = S3L_interpolateBarycentric(n0.z,n1.z,n2.z,p->barycentric);
|
||||
|
||||
S3L_normalizeVec3(&normal);
|
||||
S3L_vec3Normalize(&normal);
|
||||
|
||||
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);
|
||||
|
||||
|
@ -95,15 +95,15 @@ void drawPixel(S3L_PixelInfo *p)
|
|||
|
||||
int main()
|
||||
{
|
||||
S3L_setVec4(&toLight,10,-10,-10,0);
|
||||
S3L_vec4Set(&toLight,10,-10,-10,0);
|
||||
|
||||
S3L_normalizeVec3(&toLight);
|
||||
S3L_vec3Normalize(&toLight);
|
||||
|
||||
alligatorModelInit();
|
||||
|
||||
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.x = 9 * S3L_FRACTIONS_PER_UNIT;
|
||||
|
|
|
@ -721,7 +721,7 @@ S3L_Model3D houseModel;
|
|||
|
||||
void houseModelInit()
|
||||
{
|
||||
S3L_initModel3D(
|
||||
S3L_model3DInit(
|
||||
houseVertices,
|
||||
HOUSE_VERTEX_COUNT,
|
||||
houseTriangleIndices,
|
||||
|
|
|
@ -213,7 +213,7 @@ void drawPixel(S3L_PixelInfo *p)
|
|||
toCameraDirection.x = scene.camera.transform.translation.x - position.x;
|
||||
toCameraDirection.y = scene.camera.transform.translation.y - position.y;
|
||||
toCameraDirection.z = scene.camera.transform.translation.z - position.z;
|
||||
S3L_normalizeVec3(&toCameraDirection);
|
||||
S3L_vec3Normalize(&toCameraDirection);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
S3L_normalizeVec3(&normal);
|
||||
S3L_vec3Normalize(&normal);
|
||||
S3L_reflect(toLightDirection,normal,&reflected);
|
||||
|
||||
float diffuse = 0.5 - (S3L_dotProductVec3(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 diffuse = 0.5 - (S3L_vec3Dot(toLightDirection,normal) / ((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));
|
||||
|
||||
if (fog > 1.0)
|
||||
|
@ -298,7 +298,7 @@ void drawPixel(S3L_PixelInfo *p)
|
|||
previousColor[1] = frameBuffer[index + 1];
|
||||
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[1] = interpolate(230,10,fresnel);
|
||||
|
@ -418,7 +418,7 @@ int main()
|
|||
toLightDirection.z = 10;
|
||||
toLightDirection.w = 0;
|
||||
|
||||
S3L_normalizeVec3(&toLightDirection);
|
||||
S3L_vec3Normalize(&toLightDirection);
|
||||
|
||||
treeModelInit();
|
||||
|
||||
|
@ -428,11 +428,11 @@ int main()
|
|||
|
||||
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_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_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(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.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(-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,
|
||||
GRID_W * GRID_H,
|
||||
gridTriangles,
|
||||
|
@ -442,21 +442,21 @@ int main()
|
|||
S3L_computeModelNormals(models[ISLAND_MODEL_INDEX],terrainNormals,0);
|
||||
S3L_computeModelNormals(treeModel,treeNormals,0);
|
||||
|
||||
S3L_initModel3D(
|
||||
S3L_model3DInit(
|
||||
waterVertices,
|
||||
GRID_W * GRID_H,
|
||||
gridTriangles,
|
||||
GRID_TRIANGLES,
|
||||
&(models[WATER_MODEL_INDEX]));
|
||||
|
||||
S3L_initScene(models,MODELS_TOTAL,&scene);
|
||||
S3L_sceneInit(models,MODELS_TOTAL,&scene);
|
||||
|
||||
char fileName[] = "test00.ppm";
|
||||
|
||||
S3L_Transform3D transform0, transform1;
|
||||
|
||||
S3L_initTransform3D(&transform0);
|
||||
S3L_initTransform3D(&transform1);
|
||||
S3L_transform3DInit(&transform0);
|
||||
S3L_transform3DInit(&transform1);
|
||||
|
||||
transform0.translation.x = -2 * S3L_FRACTIONS_PER_UNIT;
|
||||
transform0.translation.y = 5 * S3L_FRACTIONS_PER_UNIT;
|
||||
|
|
|
@ -238,7 +238,7 @@ int main()
|
|||
|
||||
levelModelInit();
|
||||
|
||||
S3L_initScene(&levelModel,1,&scene);
|
||||
S3L_sceneInit(&levelModel,1,&scene);
|
||||
|
||||
int running = 1;
|
||||
|
||||
|
|
|
@ -1390,7 +1390,7 @@ S3L_Model3D levelModel;
|
|||
|
||||
void levelModelInit()
|
||||
{
|
||||
S3L_initModel3D(
|
||||
S3L_model3DInit(
|
||||
levelVertices,
|
||||
LEVEL_VERTEX_COUNT,
|
||||
levelTriangleIndices,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/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; clang -x c -g -pedantic -O3 -Wall -Wextra -o $PROGRAM $PROGRAM.c -lSDL2 2>&1 >/dev/null && ./$PROGRAM
|
||||
|
|
|
@ -187,9 +187,9 @@ void drawPixel(S3L_PixelInfo *p)
|
|||
{
|
||||
S3L_getIndexedTriangleValues(p->triangleIndex,model.triangles,normals,3,&n0,&n1,&n2);
|
||||
|
||||
l0 = 256 + S3L_clamp(S3L_dotProductVec3(n0,toLight),-511,511) / 2;
|
||||
l1 = 256 + S3L_clamp(S3L_dotProductVec3(n1,toLight),-511,511) / 2;
|
||||
l2 = 256 + S3L_clamp(S3L_dotProductVec3(n2,toLight),-511,511) / 2;
|
||||
l0 = 256 + S3L_clamp(S3L_vec3Dot(n0,toLight),-511,511) / 2;
|
||||
l1 = 256 + S3L_clamp(S3L_vec3Dot(n1,toLight),-511,511) / 2;
|
||||
l2 = 256 + S3L_clamp(S3L_vec3Dot(n2,toLight),-511,511) / 2;
|
||||
}
|
||||
|
||||
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.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);
|
||||
g = S3L_clamp(128 + n.y / 4,0,255);
|
||||
|
@ -346,8 +346,8 @@ void setModel(uint8_t index)
|
|||
|
||||
#undef modelCase
|
||||
|
||||
S3L_initTransform3D(&(scene.models[0].transform));
|
||||
S3L_initDrawConfig(&(scene.models[0].config));
|
||||
S3L_transform3DInit(&(scene.models[0].transform));
|
||||
S3L_drawConfigInit(&(scene.models[0].config));
|
||||
|
||||
if (index == 3)
|
||||
{
|
||||
|
@ -380,9 +380,9 @@ int main()
|
|||
toLight.y = 10;
|
||||
toLight.z = 10;
|
||||
|
||||
S3L_normalizeVec3(&toLight);
|
||||
S3L_vec3Normalize(&toLight);
|
||||
|
||||
S3L_initScene(&model,1,&scene);
|
||||
S3L_sceneInit(&model,1,&scene);
|
||||
|
||||
houseModelInit();
|
||||
chestModelInit();
|
||||
|
|
|
@ -45,7 +45,7 @@ S3L_Model3D plantModel;
|
|||
|
||||
void plantModelInit()
|
||||
{
|
||||
S3L_initModel3D(
|
||||
S3L_model3DInit(
|
||||
plantVertices,
|
||||
PLANT_VERTEX_COUNT,
|
||||
plantTriangleIndices,
|
||||
|
|
|
@ -104,9 +104,9 @@ int testTriangleRasterization(
|
|||
|
||||
S3L_Vec4 p0, p1, p2;
|
||||
|
||||
S3L_setVec4(&p0,x0,y0,1000,0);
|
||||
S3L_setVec4(&p1,x1,y1,1000,0);
|
||||
S3L_setVec4(&p2,x2,y2,1000,0);
|
||||
S3L_vec4Set(&p0,x0,y0,1000,0);
|
||||
S3L_vec4Set(&p1,x1,y1,1000,0);
|
||||
S3L_vec4Set(&p2,x2,y2,1000,0);
|
||||
|
||||
S3L_drawTriangle(p0,p1,p2,0,0);
|
||||
|
||||
|
@ -329,9 +329,9 @@ int testRasterization(void)
|
|||
#define dt(i1,i2,i3)\
|
||||
{\
|
||||
S3L_Vec4 p0, p1, p2;\
|
||||
S3L_setVec4(&p0,coords[2*i1],coords[2*i1 + 1],1000,0);\
|
||||
S3L_setVec4(&p1,coords[2*i2],coords[2*i2+1],1000,0);\
|
||||
S3L_setVec4(&p2,coords[2*i3],coords[2*i3+1],1000,0);\
|
||||
S3L_vec4Set(&p0,coords[2*i1],coords[2*i1 + 1],1000,0);\
|
||||
S3L_vec4Set(&p1,coords[2*i2],coords[2*i2+1],1000,0);\
|
||||
S3L_vec4Set(&p2,coords[2*i3],coords[2*i3+1],1000,0);\
|
||||
S3L_drawTriangle(p0,p1,p2,0,0);\
|
||||
}
|
||||
|
||||
|
@ -433,14 +433,14 @@ int testGeneral(void)
|
|||
{
|
||||
S3L_Vec4 v;
|
||||
|
||||
S3L_setVec4(&v,x,y,z,0);
|
||||
S3L_normalizeVec3Fast(&v);
|
||||
S3L_vec4Set(&v,x,y,z,0);
|
||||
S3L_vec3NormalizeFast(&v);
|
||||
|
||||
double l0 = vec3Len(v);
|
||||
double e0 = absVal(l0 - S3L_FRACTIONS_PER_UNIT);
|
||||
|
||||
S3L_setVec4(&v,x,y,z,0);
|
||||
S3L_normalizeVec3(&v);
|
||||
S3L_vec4Set(&v,x,y,z,0);
|
||||
S3L_vec3Normalize(&v);
|
||||
|
||||
double l1 = vec3Len(v);
|
||||
double e1 = absVal(l1 - S3L_FRACTIONS_PER_UNIT);
|
||||
|
@ -478,8 +478,8 @@ int testRender(void)
|
|||
|
||||
memset(testScreen,'.',S3L_RESOLUTION_X * S3L_RESOLUTION_Y);
|
||||
|
||||
S3L_initModel3D(cubeVertices,S3L_CUBE_VERTEX_COUNT,cubeTriangles,S3L_CUBE_TRIANGLE_COUNT,&cubeModel);
|
||||
S3L_initModel3D(triangleVertices,3,triangleTriangles,1,&triangleModel);
|
||||
S3L_model3DInit(cubeVertices,S3L_CUBE_VERTEX_COUNT,cubeTriangles,S3L_CUBE_TRIANGLE_COUNT,&cubeModel);
|
||||
S3L_model3DInit(triangleVertices,3,triangleTriangles,1,&triangleModel);
|
||||
|
||||
models[0] = cubeModel;
|
||||
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.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.y = S3L_FRACTIONS_PER_UNIT / 3;
|
||||
|
@ -534,10 +534,10 @@ int main(void)
|
|||
S3L_Mat4 m, m2;
|
||||
S3L_Vec4 v;
|
||||
|
||||
S3L_initMat4(&m);
|
||||
S3L_mat4Init(&m);
|
||||
S3L_logMat4(m);
|
||||
|
||||
S3L_initVec4(&v);
|
||||
S3L_vec4Init(&v);
|
||||
|
||||
S3L_logVec4(v);
|
||||
|
||||
|
|
|
@ -55,14 +55,14 @@ void drawPixel(S3L_PixelInfo *p)
|
|||
|
||||
int main()
|
||||
{
|
||||
S3L_initModel3D(
|
||||
S3L_model3DInit(
|
||||
cubeVertices,
|
||||
S3L_CUBE_VERTEX_COUNT,
|
||||
cubeTriangles,
|
||||
S3L_CUBE_TRIANGLE_COUNT,
|
||||
&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.
|
||||
1,
|
||||
&scene);
|
||||
|
|
|
@ -189,7 +189,7 @@ S3L_Model3D treeModel;
|
|||
|
||||
void treeModelInit()
|
||||
{
|
||||
S3L_initModel3D(
|
||||
S3L_model3DInit(
|
||||
treeVertices,
|
||||
TREE_VERTEX_COUNT,
|
||||
treeTriangleIndices,
|
||||
|
|
94
small3dlib.h
94
small3dlib.h
|
@ -10,7 +10,7 @@
|
|||
license: CC0 1.0 (public domain)
|
||||
found at https://creativecommons.org/publicdomain/zero/1.0/
|
||||
+ additional waiver of all IP
|
||||
version: 0.853d
|
||||
version: 0.860d
|
||||
|
||||
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
|
||||
|
@ -249,7 +249,7 @@ typedef uint16_t S3L_Index;
|
|||
#endif
|
||||
|
||||
#if S3L_PERSPECTIVE_CORRECTION
|
||||
#define S3L_COMPUTE_DEPTH 1 // PC inevitably computes depth, so enable it
|
||||
#define S3L_COMPUTE_DEPTH 1 // PC inevitably computes depth, so enable it
|
||||
#endif
|
||||
|
||||
#ifndef S3L_COMPUTE_DEPTH
|
||||
|
@ -363,8 +363,8 @@ typedef struct
|
|||
#define S3L_logVec4(v)\
|
||||
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_setVec4(S3L_Vec4 *v, S3L_Unit x, S3L_Unit y,
|
||||
static inline void S3L_vec4Init(S3L_Vec4 *v);
|
||||
static inline void S3L_vec4Set(S3L_Vec4 *v, S3L_Unit x, S3L_Unit y,
|
||||
S3L_Unit z, S3L_Unit w);
|
||||
static inline void S3L_vec3Add(S3L_Vec4 *result, S3L_Vec4 added);
|
||||
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
|
||||
rather than quickly! If you need to normalize quickly, do it yourself in a
|
||||
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
|
||||
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);
|
||||
void S3L_crossProduct(S3L_Vec4 a, S3L_Vec4 b, S3L_Vec4 *result);
|
||||
static inline S3L_Unit S3L_dotProductVec3(S3L_Vec4 a, S3L_Vec4 b);
|
||||
void S3L_vec3Cross(S3L_Vec4 a, S3L_Vec4 b, S3L_Vec4 *result);
|
||||
static inline S3L_Unit S3L_vec3Dot(S3L_Vec4 a, S3L_Vec4 b);
|
||||
|
||||
/** Computes a reflection direction (typically used e.g. for specular component
|
||||
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).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_setTransform3D(
|
||||
void S3L_transform3DSet(
|
||||
S3L_Unit tx,
|
||||
S3L_Unit ty,
|
||||
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])
|
||||
|
||||
/** 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(
|
||||
S3L_Unit offsetX,
|
||||
|
@ -502,7 +502,7 @@ typedef struct
|
|||
S3L_Transform3D transform;
|
||||
} S3L_Camera;
|
||||
|
||||
void S3L_initCamera(S3L_Camera *camera);
|
||||
void S3L_cameraInit(S3L_Camera *camera);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -514,7 +514,7 @@ typedef struct
|
|||
int8_t visible; /**< Can be used to easily hide the model. */
|
||||
} S3L_DrawConfig;
|
||||
|
||||
void S3L_initDrawConfig(S3L_DrawConfig *config);
|
||||
void S3L_drawConfigInit(S3L_DrawConfig *config);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -530,7 +530,7 @@ typedef struct
|
|||
S3L_DrawConfig config;
|
||||
} S3L_Model3D; ///< Represents a 3D model.
|
||||
|
||||
void S3L_initModel3D(
|
||||
void S3L_model3DInit(
|
||||
const S3L_Unit *vertices,
|
||||
S3L_Index vertexCount,
|
||||
const S3L_Index *triangles,
|
||||
|
@ -544,7 +544,7 @@ typedef struct
|
|||
S3L_Camera camera;
|
||||
} S3L_Scene; ///< Represent the 3D scene to be rendered.
|
||||
|
||||
void S3L_initScene(
|
||||
void S3L_sceneInit(
|
||||
S3L_Model3D *models,
|
||||
S3L_Index modelCount,
|
||||
S3L_Scene *scene);
|
||||
|
@ -580,7 +580,7 @@ typedef struct
|
|||
} S3L_PixelInfo; /**< Used to pass the info about a rasterized pixel
|
||||
(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
|
||||
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\
|
||||
(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;
|
||||
}
|
||||
|
||||
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->y = y;
|
||||
|
@ -981,7 +981,7 @@ void S3L_vec3Sub(S3L_Vec4 *result, S3L_Vec4 substracted)
|
|||
result->z -= substracted.z;
|
||||
}
|
||||
|
||||
void S3L_initMat4(S3L_Mat4 m)
|
||||
void S3L_mat4Init(S3L_Mat4 m)
|
||||
{
|
||||
#define M(x,y) m[x][y]
|
||||
#define S S3L_FRACTIONS_PER_UNIT
|
||||
|
@ -995,28 +995,28 @@ void S3L_initMat4(S3L_Mat4 m)
|
|||
#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 i = 0; i < 4; ++i)
|
||||
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;
|
||||
}
|
||||
|
||||
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->y = (normal.y * d) / S3L_FRACTIONS_PER_UNIT - toLight.y;
|
||||
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->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
|
||||
|
||||
S3L_crossProduct(t1,t2,n);
|
||||
S3L_vec3Cross(t1,t2,n);
|
||||
|
||||
S3L_normalizeVec3(n);
|
||||
S3L_vec3Normalize(n);
|
||||
}
|
||||
|
||||
void S3L_getIndexedTriangleValues(
|
||||
|
@ -1161,7 +1161,7 @@ void S3L_computeModelNormals(S3L_Model3D model, S3L_Unit *dst,
|
|||
n.y /= normalCount;
|
||||
n.z /= normalCount;
|
||||
|
||||
S3L_normalizeVec3(&n);
|
||||
S3L_vec3Normalize(&n);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void S3L_normalizeVec3(S3L_Vec4 *v)
|
||||
void S3L_vec3Normalize(S3L_Vec4 *v)
|
||||
{
|
||||
#define SCALE 16
|
||||
#define BOTTOM_LIMIT 16
|
||||
|
@ -1567,7 +1567,7 @@ void S3L_normalizeVec3(S3L_Vec4 *v)
|
|||
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);
|
||||
|
||||
|
@ -1579,10 +1579,10 @@ void S3L_normalizeVec3Fast(S3L_Vec4 *v)
|
|||
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_initVec4(&(t->rotation));
|
||||
S3L_vec4Init(&(t->translation));
|
||||
S3L_vec4Init(&(t->rotation));
|
||||
t->scale.x = S3L_FRACTIONS_PER_UNIT;
|
||||
t->scale.y = 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);
|
||||
}
|
||||
|
||||
void S3L_setTransform3D(
|
||||
void S3L_transform3DSet(
|
||||
S3L_Unit tx,
|
||||
S3L_Unit ty,
|
||||
S3L_Unit tz,
|
||||
|
@ -1684,10 +1684,10 @@ void S3L_setTransform3D(
|
|||
t->scale.z = sz;
|
||||
}
|
||||
|
||||
void S3L_initCamera(S3L_Camera *camera)
|
||||
void S3L_cameraInit(S3L_Camera *camera)
|
||||
{
|
||||
camera->focalLength = S3L_FRACTIONS_PER_UNIT;
|
||||
S3L_initTransform3D(&(camera->transform));
|
||||
S3L_transform3DInit(&(camera->transform));
|
||||
}
|
||||
|
||||
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->y = 0;
|
||||
|
@ -1740,7 +1740,7 @@ void S3L_initPixelInfo(S3L_PixelInfo *p)
|
|||
p->previousZ = 0;
|
||||
}
|
||||
|
||||
void S3L_initModel3D(
|
||||
void S3L_model3DInit(
|
||||
const S3L_Unit *vertices,
|
||||
S3L_Index vertexCount,
|
||||
const S3L_Index *triangles,
|
||||
|
@ -1753,21 +1753,21 @@ void S3L_initModel3D(
|
|||
model->triangleCount = triangleCount;
|
||||
model->customTransformMatrix = 0;
|
||||
|
||||
S3L_initTransform3D(&(model->transform));
|
||||
S3L_initDrawConfig(&(model->config));
|
||||
S3L_transform3DInit(&(model->transform));
|
||||
S3L_drawConfigInit(&(model->config));
|
||||
}
|
||||
|
||||
void S3L_initScene(
|
||||
void S3L_sceneInit(
|
||||
S3L_Model3D *models,
|
||||
S3L_Index modelCount,
|
||||
S3L_Scene *scene)
|
||||
{
|
||||
scene->models = models;
|
||||
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->visible = 1;
|
||||
|
@ -1861,7 +1861,7 @@ void S3L_drawTriangle(
|
|||
S3L_Index triangleIndex)
|
||||
{
|
||||
S3L_PixelInfo p;
|
||||
S3L_initPixelInfo(&p);
|
||||
S3L_pixelInfoInit(&p);
|
||||
p.modelIndex = modelIndex;
|
||||
p.triangleIndex = triangleIndex;
|
||||
p.triangleID = (modelIndex << 16) | triangleIndex;
|
||||
|
@ -2424,7 +2424,7 @@ void S3L_makeWorldMatrix(S3L_Transform3D worldTransform, S3L_Mat4 m)
|
|||
S3L_mat4Xmat4(m,t);
|
||||
}
|
||||
|
||||
void S3L_transposeMat4(S3L_Mat4 m)
|
||||
void S3L_mat4Transpose(S3L_Mat4 m)
|
||||
{
|
||||
S3L_Unit tmp;
|
||||
|
||||
|
@ -2453,7 +2453,7 @@ void S3L_makeCameraMatrix(S3L_Transform3D cameraTransform, S3L_Mat4 m)
|
|||
cameraTransform.rotation.z,
|
||||
r);
|
||||
|
||||
S3L_transposeMat4(r); // transposing creates an inverse transform
|
||||
S3L_mat4Transpose(r); // transposing creates an inverse transform
|
||||
|
||||
S3L_mat4Xmat4(m,r);
|
||||
}
|
||||
|
|
|
@ -207,7 +207,7 @@ print("S3L_Model3D " + NAME + "Model;\n")
|
|||
|
||||
print("void " + NAME + "ModelInit()")
|
||||
print("{")
|
||||
print(" S3L_initModel3D(")
|
||||
print(" S3L_model3DInit(")
|
||||
print(" " + NAME + "Vertices,")
|
||||
print(" " + NAME.upper() + "_VERTEX_COUNT,")
|
||||
print(" " + NAME + "TriangleIndices,")
|
||||
|
|
Loading…
Reference in a new issue