diff --git a/s3l.h b/s3l.h index a3c883c..b42876e 100644 --- a/s3l.h +++ b/s3l.h @@ -1315,14 +1315,6 @@ void S3L_makeWorldMatrix(S3L_Transform3D worldTransform, S3L_Mat4 *m) void S3L_makeCameraMatrix(S3L_Transform3D cameraTransform, S3L_Mat4 *m) { -/* - S3L_makeTranslationMat( - -1 * cameraTransform.translation.x, - -1 * cameraTransform.translation.y, - -1 * cameraTransform.translation.z, - m); -*/ - S3L_makeTranslationMat( -1 * cameraTransform.translation.x, -1 * cameraTransform.translation.y, @@ -1340,10 +1332,11 @@ void S3L_makeCameraMatrix(S3L_Transform3D cameraTransform, S3L_Mat4 *m) S3L_mat4Xmat4(m,&r); } -static inline void S3L_zDivide(S3L_Vec4 *vector) +static inline void S3L_perspectiveDivide(S3L_Vec4 *vector, + S3L_Unit focalLength) { - vector->x = (vector->x * S3L_FRACTIONS_PER_UNIT) / S3L_nonZero(vector->z); - vector->y = (vector->y * S3L_FRACTIONS_PER_UNIT) / S3L_nonZero(vector->z); + vector->x = (vector->x * focalLength) / vector->z; + vector->y = (vector->y * focalLength) / vector->z; } void S3L_drawModelIndexed( @@ -1382,7 +1375,7 @@ void S3L_drawModelIndexed( transformed##n.x = pointModel.x;\ transformed##n.y = pointModel.y;\ transformed##n.z = pointModel.z;\ - S3L_zDivide(&transformed##n); + S3L_perspectiveDivide(&transformed##n,camera->focalLength); project(0) project(1) diff --git a/testSDL.c b/testSDL.c index 33eaa99..60a830b 100644 --- a/testSDL.c +++ b/testSDL.c @@ -196,6 +196,7 @@ int main() SDL_Event event; S3L_initCamera(&camera); + camera.transform.translation.z = -S3L_FRACTIONS_PER_UNIT * 2; // camera.transform.translation.x = S3L_FRACTIONS_PER_UNIT; // camera.transform.translation.y = S3L_FRACTIONS_PER_UNIT;