summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/ray.cc
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-11-03 12:01:39 +0100
committerRobert Vollmert <rvollmert@gmx.net>2009-11-03 12:01:50 +0100
commitf4f1ff8cbaaa06d58f7a509b5a74d7f847aa4d51 (patch)
treea4772d18f3cd5b0367e8724ee33ee87f66b644d4 /crawl-ref/source/ray.cc
parentc3ef566864421728eaafd453ce5b0a524457d641 (diff)
downloadcrawl-ref-f4f1ff8cbaaa06d58f7a509b5a74d7f847aa4d51.tar.gz
crawl-ref-f4f1ff8cbaaa06d58f7a509b5a74d7f847aa4d51.zip
Move reflection line choice into separate function.
Diffstat (limited to 'crawl-ref/source/ray.cc')
-rw-r--r--crawl-ref/source/ray.cc97
1 files changed, 52 insertions, 45 deletions
diff --git a/crawl-ref/source/ray.cc b/crawl-ref/source/ray.cc
index 398032438e..04aafeef4e 100644
--- a/crawl-ref/source/ray.cc
+++ b/crawl-ref/source/ray.cc
@@ -165,6 +165,56 @@ static geom::ray _mirror(const geom::ray &rorig, const coord_def &side)
return (r);
}
+static geom::line _choose_reflect_line(bool rx, bool ry, bool rxy)
+{
+ geom::line l;
+ if (rxy)
+ {
+ if (rx && ry)
+ {
+ // x + y = 1.5
+ l.f = geom::form(1, 1);
+ l.val = 1.5;
+ }
+ else if (!rx && !ry)
+ {
+ // x + y = 2.5
+ l.f = geom::form(1, 1);
+ l.val = 2.5;
+ }
+ else if (rx)
+ {
+ // x = 1
+ l.f = geom::form(1, 0);
+ l.val = 1;
+ }
+ else if (ry)
+ {
+ // y = 1
+ l.f = geom::form(0, 1);
+ l.val = 1;
+ }
+ }
+ else if (rx)
+ {
+ // Flattened corners: y = x - 0.5
+ // l.f = geom::form(1, -1);
+ // l.val = 0.5;
+ // Instead like rxy && rx: x = 1
+ l.f = geom::form(1, 0);
+ l.val = 1;
+ }
+ else // ry
+ {
+ // y = x + 0.5
+ // l.f = geom::form(1, -1);
+ // l.val = -0.5;
+ l.f = geom::form(0, 1);
+ l.val = 1;
+ }
+ return (l);
+}
+
void ray_def::bounce(const reflect_grid &rg)
{
#ifdef DEBUG_REFLECTION
@@ -244,51 +294,8 @@ void ray_def::bounce(const reflect_grid &rg)
else
{
// These all reduce to reflection at one line.
- geom::line l;
- if (rxy)
- {
- if (rx && ry)
- {
- // x + y = 1.5
- l.f = geom::form(1, 1);
- l.val = 1.5;
- }
- else if (!rx && !ry)
- {
- // x + y = 2.5
- l.f = geom::form(1, 1);
- l.val = 2.5;
- }
- else if (rx)
- {
- // x = 1
- l.f = geom::form(1, 0);
- l.val = 1;
- }
- else if (ry)
- {
- // y = 1
- l.f = geom::form(0, 1);
- l.val = 1;
- }
- }
- else if (rx)
- {
- // Flattened corners: y = x - 0.5
- // l.f = geom::form(1, -1);
- // l.val = 0.5;
- // Instead like rxy && rx: x = 1
- l.f = geom::form(1, 0);
- l.val = 1;
- }
- else // ry
- {
- // y = x + 0.5
- // l.f = geom::form(1, -1);
- // l.val = -0.5;
- l.f = geom::form(0, 1);
- l.val = 1;
- }
+ geom::line l = _choose_reflect_line(rx, ry, rxy);
+
double t = intersect(rmirr, l);
ASSERT(double_is_zero(t) || t >= 0);
rmirr.advance(t);