summaryrefslogtreecommitdiffstats
path: root/src/game/shared/world/ray_dda.hh
blob: c3cbb09abcf281fe55e67ad0d944ef24f1591ba4 (plain)
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
// SPDX-License-Identifier: BSD-2-Clause
// Copyright (c) 2025 Kirill Dmitrievich
// File: ray_dda.hh
// Description: Fast voxel grid traversal with an arbitrary starting position

#ifndef SHARED_WORLD_RAY_DDA_HH
#define SHARED_WORLD_RAY_DDA_HH
#pragma once

#include "shared/types.hh"

class Dimension;
class Voxel;

class RayDDA final {
public:
    RayDDA(void) = default;
    explicit RayDDA(const Dimension* dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction);
    explicit RayDDA(const Dimension& dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction);

    void reset(const Dimension* dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction);
    void reset(const Dimension& dimension, const chunk_pos& start_chunk, const glm::fvec3& start_fpos, const glm::fvec3& direction);

    const Voxel* step(void);

public:
    const Dimension* dimension;
    chunk_pos start_chunk;
    glm::fvec3 start_fpos;
    glm::fvec3 direction;

    glm::fvec3 delta_dist;
    glm::fvec3 side_dist;
    voxel_pos vstep;

    double distance;
    voxel_pos vnormal;
    voxel_pos vpos;
};

#endif