From 242bf42ffcfba4adcc03491080f4d8e24046127e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Tue, 18 Jun 2019 20:44:45 +0200 Subject: [PATCH] Continue HQ program --- programs/hqOffline.c | 44 ++++++++++++++++++++++++++++++++++---------- small3dlib.h | 10 +++++----- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/programs/hqOffline.c b/programs/hqOffline.c index 7710e27..45fc4b5 100644 --- a/programs/hqOffline.c +++ b/programs/hqOffline.c @@ -486,22 +486,46 @@ int main() S3L_initScene(models,MODELS_TOTAL,&scene); char fileName[] = "test00.ppm"; + + S3L_Transform3D transform0, transform1; + S3L_Vec4 target0, target1; + + S3L_initTransoform3D(&transform0); + S3L_initTransoform3D(&transform1); + + target0 = scene.models[0].transform.translation; + target1 = scene.models[2].transform.translation; + + transform0.translation.x = 2 * S3L_FRACTIONS_PER_UNIT; + transform0.translation.y = 4 * S3L_FRACTIONS_PER_UNIT; + transform0.translation.z = -14 * S3L_FRACTIONS_PER_UNIT; + + S3L_lookAt(target0,&transform0); + + transform1.translation.x = 5 * S3L_FRACTIONS_PER_UNIT; + transform1.translation.y = 6 * S3L_FRACTIONS_PER_UNIT; + transform1.translation.z = 3 * S3L_FRACTIONS_PER_UNIT; + + transform1.rotation.x = S3L_FRACTIONS_PER_UNIT / 8; + + S3L_lookAt(target1,&transform1); + + transform1.rotation.y = -S3L_FRACTIONS_PER_UNIT + transform1.rotation.y; + + int frames = 100; - for (int i = 0; i < 100; ++i) // render the frames + for (int i = 0; i < frames; ++i) // render the frames { animateWater(); - scene.camera.transform.translation.x = 2000; - scene.camera.transform.translation.y = 3000; - scene.camera.transform.translation.z = -S3L_FRACTIONS_PER_UNIT * 8; + float t = i / ((float) frames); - S3L_Vec4 target; - - target.x = 0; - target.y = 0; - target.z = 0; + scene.camera.transform.translation.x = interpolate(transform0.translation.x,transform1.translation.x,t); + scene.camera.transform.translation.y = interpolate(transform0.translation.y,transform1.translation.y,t); + scene.camera.transform.translation.z = interpolate(transform0.translation.z,transform1.translation.z,t); - S3L_lookAt(scene.camera.transform.translation,target,&scene.camera.transform); + scene.camera.transform.rotation.x = interpolate(transform0.rotation.x,transform1.rotation.x,t); + scene.camera.transform.rotation.y = interpolate(transform0.rotation.y,transform1.rotation.y,t); clearFrameBuffer(); diff --git a/small3dlib.h b/small3dlib.h index e817bb2..518bdd1 100644 --- a/small3dlib.h +++ b/small3dlib.h @@ -327,7 +327,7 @@ typedef struct static inline void S3L_initTransoform3D(S3L_Transform3D *t); -void S3L_lookAt(S3L_Vec4 pointFrom, S3L_Vec4 pointTo, S3L_Transform3D *t); +void S3L_lookAt(S3L_Vec4 pointTo, S3L_Transform3D *t); void S3L_setTransform3D( S3L_Unit tx, @@ -1352,12 +1352,12 @@ void S3L_initTransoform3D(S3L_Transform3D *t) t->scale.w = 0; } -void S3L_lookAt(S3L_Vec4 pointFrom, S3L_Vec4 pointTo, S3L_Transform3D *t) +void S3L_lookAt(S3L_Vec4 pointTo, S3L_Transform3D *t) { S3L_Vec4 v; - v.x = pointTo.x - pointFrom.x; - v.y = pointTo.z - pointFrom.z; + v.x = pointTo.x - t->translation.x; + v.y = pointTo.z - t->translation.z; S3L_Unit dx = v.x; S3L_Unit l = S3L_vec2Length(v); @@ -1369,7 +1369,7 @@ void S3L_lookAt(S3L_Vec4 pointFrom, S3L_Vec4 pointTo, S3L_Transform3D *t) if (v.y < 0) t->rotation.y = S3L_FRACTIONS_PER_UNIT / 2 - t->rotation.y; - v.x = pointTo.y - pointFrom.y; + v.x = pointTo.y - t->translation.y; v.y = l; l = S3L_vec2Length(v);