From d7f0804248baac350a51d3a28cd11e69c56f31bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Wed, 19 Jun 2019 19:05:18 +0200 Subject: [PATCH] Add collisions to city --- programs/city.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/programs/city.c b/programs/city.c index 3656d18..2ee7ccf 100644 --- a/programs/city.c +++ b/programs/city.c @@ -258,7 +258,19 @@ int main() { if (coll == 1) { - models[1].transform.translation = previousPos; + S3L_Vec4 newPos = models[1].transform.translation; + newPos.x = previousPos.x; + + if (collision(newPos)) + { + newPos = models[1].transform.translation; + newPos.z = previousPos.z; + + if (collision(newPos)) + newPos = previousPos; + } + + models[1].transform.translation = newPos; } else if (coll == 2) { @@ -272,6 +284,7 @@ int main() } } + scene.camera.transform.translation.x = scene.models[1].transform.translation.x - carDirection.x; scene.camera.transform.translation.y = S3L_FRACTIONS_PER_UNIT / 2; scene.camera.transform.translation.z = scene.models[1].transform.translation.z - carDirection.z;