diff --git a/programs/hqOffline.c b/programs/hqOffline.c index 95d9a49..7710e27 100644 --- a/programs/hqOffline.c +++ b/programs/hqOffline.c @@ -486,14 +486,14 @@ int main() S3L_initScene(models,MODELS_TOTAL,&scene); char fileName[] = "test00.ppm"; - - for (int i = 0; i < 50; ++i) // render the frames + + for (int i = 0; i < 100; ++i) // render the frames { animateWater(); - scene.camera.transform.translation.x = S3L_sin(i * 5) * 3; - scene.camera.transform.translation.y = 5 * S3L_FRACTIONS_PER_UNIT + S3L_cos(i * 6) * 2; - scene.camera.transform.translation.z = S3L_cos(i * 4) * 10; + scene.camera.transform.translation.x = 2000; + scene.camera.transform.translation.y = 3000; + scene.camera.transform.translation.z = -S3L_FRACTIONS_PER_UNIT * 8; S3L_Vec4 target; diff --git a/programs/testSDL.c b/programs/testSDL.c index bad4045..960be1c 100644 --- a/programs/testSDL.c +++ b/programs/testSDL.c @@ -133,12 +133,6 @@ void houseTex(int32_t u, int32_t v, uint8_t *r, uint8_t *g, uint8_t *b) void drawPixel(S3L_PixelInfo *p) { - -//setPixel(p->x,p->y,p->triangleIndex,p->triangleIndex,p->triangleIndex); -setPixel(p->x,p->y,0,0,0); - -return; - if (p->x < 0 || p ->x >= S3L_RESOLUTION_X || p->y < 0 || p->y >= S3L_RESOLUTION_Y) { offScreenPixels++; @@ -183,13 +177,13 @@ if (p->modelIndex != 0) uv0[0], uv1[0], uv2[0], - p->barycentric[0], p->barycentric[1], p->barycentric[2]); + p->barycentric); v = S3L_interpolateBarycentric( uv0[1], uv1[1], uv2[1], - p->barycentric[0], p->barycentric[1], p->barycentric[2]); + p->barycentric); uint8_t r,g,b; houseTex( @@ -211,9 +205,9 @@ n2.x = houseNormals[scene.models[p->modelIndex].triangles[p->triangleIndex * 3 + n2.y = houseNormals[scene.models[p->modelIndex].triangles[p->triangleIndex * 3 + 2] * 3 + 1]; n2.z = houseNormals[scene.models[p->modelIndex].triangles[p->triangleIndex * 3 + 2] * 3 + 2]; -n.x = S3L_interpolateBarycentric(n0.x,n1.x,n2.x,p->barycentric[0],p->barycentric[1],p->barycentric[2]); -n.y = S3L_interpolateBarycentric(n0.y,n1.y,n2.y,p->barycentric[0],p->barycentric[1],p->barycentric[2]); -n.z = S3L_interpolateBarycentric(n0.z,n1.z,n2.z,p->barycentric[0],p->barycentric[1],p->barycentric[2]); +n.x = S3L_interpolateBarycentric(n0.x,n1.x,n2.x,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); S3L_Vec4 V; @@ -239,13 +233,13 @@ else coords[0], coords[2], coords[4], - p->barycentric[0], p->barycentric[1], p->barycentric[2]); + p->barycentric); v = S3L_interpolateBarycentric( coords[1], coords[3], coords[5], - p->barycentric[0], p->barycentric[1], p->barycentric[2]); + p->barycentric); uint8_t col = texturePixel(u,v); setPixel(p->x,p->y,col,col * 30,(2 - col) * 120); diff --git a/small3dlib.h b/small3dlib.h index 0a63f49..e817bb2 100644 --- a/small3dlib.h +++ b/small3dlib.h @@ -73,7 +73,8 @@ | Rotations use Euler angles and are generally in the extinsic Euler angles in - ZXY order (by Z, then by X, then by Y). + ZXY order (by Z, then by X, then by Y). Positive rotation about an axis + rotates CW (clock-wise) when looking in the direction of the axis. Coordinates of pixels on screen start typically at the top left, from [0,0]. @@ -1178,7 +1179,7 @@ S3L_Unit S3L_asin(S3L_Unit x) S3L_Unit S3L_cos(S3L_Unit x) { - return S3L_sin(x - S3L_FRACTIONS_PER_UNIT / 4); + return S3L_sin(x + S3L_FRACTIONS_PER_UNIT / 4); } void S3L_correctBarycentricCoords(S3L_Unit barycentric[3]) @@ -1237,6 +1238,10 @@ void S3L_makeRotationMatrixZXY( S3L_Unit byZ, S3L_Mat4 *m) { + byX *= -1; + byY *= -1; + byZ *= -1; + S3L_Unit sx = S3L_sin(byX); S3L_Unit sy = S3L_sin(byY); S3L_Unit sz = S3L_sin(byZ); @@ -1344,6 +1349,7 @@ void S3L_initTransoform3D(S3L_Transform3D *t) t->scale.x = S3L_FRACTIONS_PER_UNIT; t->scale.y = S3L_FRACTIONS_PER_UNIT; t->scale.z = S3L_FRACTIONS_PER_UNIT; + t->scale.w = 0; } void S3L_lookAt(S3L_Vec4 pointFrom, S3L_Vec4 pointTo, S3L_Transform3D *t) @@ -1370,7 +1376,8 @@ void S3L_lookAt(S3L_Vec4 pointFrom, S3L_Vec4 pointTo, S3L_Transform3D *t) dx = (v.x * S3L_FRACTIONS_PER_UNIT) / S3L_nonZero(l); - t->rotation.x = S3L_asin(dx); + t->rotation.x = -1 * S3L_asin(dx); + } void S3L_setTransform3D( diff --git a/todo.txt b/todo.txt index 9835a83..f1f2e79 100644 --- a/todo.txt +++ b/todo.txt @@ -24,6 +24,9 @@ features: interpolation -- it will randomly picky one of three values, with greater probabilities at greater coords +- change the default backface culling to the other one (and edit the obj tool + accordingly) + - option to disable baycentric coordinates computing DONE - Z-buffer: