From a41edc31ce81daf69157a345525933ca6c560004 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 9 May 2001 20:02:28 +0000 Subject: [PATCH] check for tiny values in dir[] vector in calcposobjs(), prevents FP underflows later --- progs/demos/fire.c | 7 +++++++ progs/demos/ipers.c | 7 +++++++ progs/demos/ray.c | 7 +++++++ progs/demos/terrain.c | 7 +++++++ progs/demos/tunnel.c | 7 +++++++ progs/demos/tunnel2.c | 7 +++++++ 6 files changed, 42 insertions(+) diff --git a/progs/demos/fire.c b/progs/demos/fire.c index e895b0e..e4492cb 100644 --- a/progs/demos/fire.c +++ b/progs/demos/fire.c @@ -257,6 +257,13 @@ calcposobs(void) dir[2] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0); dir[1] = cos(beta * M_PI / 180.0); + if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5) + dir[0] = 0; + if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5) + dir[1] = 0; + if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5) + dir[2] = 0; + obs[0] += v * dir[0]; obs[1] += v * dir[1]; obs[2] += v * dir[2]; diff --git a/progs/demos/ipers.c b/progs/demos/ipers.c index d38c4d1..029de00 100644 --- a/progs/demos/ipers.c +++ b/progs/demos/ipers.c @@ -205,6 +205,13 @@ calcposobs(void) dir[1] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0); dir[2] = cos(beta * M_PI / 180.0); + if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5) + dir[0] = 0; + if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5) + dir[1] = 0; + if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5) + dir[2] = 0; + obs[0] += v * dir[0]; obs[1] += v * dir[1]; obs[2] += v * dir[2]; diff --git a/progs/demos/ray.c b/progs/demos/ray.c index aede3d8..44289b7 100644 --- a/progs/demos/ray.c +++ b/progs/demos/ray.c @@ -102,6 +102,13 @@ calcposobs(void) dir[1] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0); dir[2] = cos(beta * M_PI / 180.0); + if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5) + dir[0] = 0; + if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5) + dir[1] = 0; + if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5) + dir[2] = 0; + obs[0] += v * dir[0]; obs[1] += v * dir[1]; obs[2] += v * dir[2]; diff --git a/progs/demos/terrain.c b/progs/demos/terrain.c index 2fe1df3..5b5ad3e 100644 --- a/progs/demos/terrain.c +++ b/progs/demos/terrain.c @@ -81,6 +81,13 @@ calcposobs(void) dir[2] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0); dir[1] = cos(beta * M_PI / 180.0); + if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5) + dir[0] = 0; + if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5) + dir[1] = 0; + if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5) + dir[2] = 0; + alpha1 = alpha + FOV / 2.0; v1[0] = sin(alpha1 * M_PI / 180.0); v1[1] = cos(alpha1 * M_PI / 180.0); diff --git a/progs/demos/tunnel.c b/progs/demos/tunnel.c index d495b31..f0faa61 100644 --- a/progs/demos/tunnel.c +++ b/progs/demos/tunnel.c @@ -164,6 +164,13 @@ calcposobs(void) dir[1] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0); dir[2] = cos(beta * M_PI / 180.0); + if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5) + dir[0] = 0; + if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5) + dir[1] = 0; + if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5) + dir[2] = 0; + obs[0] += v * dir[0]; obs[1] += v * dir[1]; obs[2] += v * dir[2]; diff --git a/progs/demos/tunnel2.c b/progs/demos/tunnel2.c index 8d66248..048cd6d 100644 --- a/progs/demos/tunnel2.c +++ b/progs/demos/tunnel2.c @@ -162,6 +162,13 @@ calcposobs(void) dir[1] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0); dir[2] = cos(beta * M_PI / 180.0); + if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5) + dir[0] = 0; + if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5) + dir[1] = 0; + if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5) + dir[2] = 0; + obs[0] += v * dir[0]; obs[1] += v * dir[1]; obs[2] += v * dir[2]; -- 2.7.4