summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/ray.cc
blob: e6952f21021c685b70e57fcc54c23574bd4f320b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 *  File:       .cc
 *  Summary:
 */

#include "AppHdr.h"

#include <cmath>

#include "ray.h"
#include "geom2d.h"

static geom::grid diamonds(geom::lineseq(1, 1, 0.5, 1),
                           geom::lineseq(1, -1, -0.5, 1));

static int ifloor(double d)
{
    return static_cast<int>(floor(d));
}

coord_def ray_def::pos() const
{
    // TODO: Assert we're in a central diamond.
    int x = ifloor(r.start.x);
    int y = ifloor(r.start.y);
    return (coord_def(x, y));
}

bool ray_def::advance()
{
    return (geom::nextcell(r, diamonds, true)
            && geom::nextcell(r, diamonds, false));
}

void ray_def::advance_and_bounce()
{
    // XXX
    r.dir *= -1;
}

void ray_def::regress()
{
    r.dir *= -1;
    advance();
    r.dir *= -1;
}