1#ifndef NANOMMO_TERRAIN_TERRAIN_H_
2#define NANOMMO_TERRAIN_TERRAIN_H_
7#include "absl/log/check.h"
18 Grid(T* cells,
int rows,
int columns)
19 : cells_(cells), rows_(rows), columns_(columns) {}
22 CHECK(j >= 0 && j < rows_ && i >= 0 && i < columns_)
23 <<
"grid[" << j <<
", " << i <<
"] is outside its " << rows_
24 <<
" rows of " << columns_;
25 return cells_[j * columns_ + i];
48 static constexpr float kCell = 2.0f;
59 static constexpr float kTrunk = 0.5f;
69 float Height(
float x,
float z)
const;
73 bool Walkable(
float x,
float z)
const;
75 const std::vector<Tree>&
trees()
const {
return trees_; }
82 uint32_t
seed()
const {
return seed_; }
85 int cells()
const {
return cells_; }
95 bool InATree(
float x,
float z)
const;
100 std::vector<float> corners_;
101 std::vector<Tree> trees_;
103 std::vector<int> tree_in_;
104 int tree_squares_ = 0;
T & operator[](int j, int i) const
Grid(T *cells, int rows, int columns)
float half_size() const
From the middle to each side of the grid.
float edge() const
Half a metre short of each side, so that players stay on the grid.
static constexpr float kCell
In metres. Each cell of the grid is two triangles.
Terrain()
The board we had: flat, twelve metres across, for the tests.
const std::vector< Tree > & trees() const
static constexpr float kSeaLevel
float Corner(int i, int j) const
The height at a corner of the grid, from 0 to cells() along each side.
static constexpr float kTrunk
How close to the middle of a trunk a player can stand.
static constexpr float kTreeSpacing
The trees grow on a grid of squares this size, at most one in each.
float Height(float x, float z) const
On the triangles between the grid's corners, as the client draws them.
bool Walkable(float x, float z) const
int cells() const
Along each side.
static constexpr float kWading
Players wade into the sea up to their knees.
float yaw
In radians, around the vertical.
float scale
How much bigger or smaller than the model it is.