stratgame

view level/src/terrain.cc @ 4:cd12944a8ea8

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 25 May 2012 05:28:20 +0300
parents
children 2e38715de41b
line source
1 #include "terrain.h"
3 Terrain::Terrain()
4 {
5 root = 0;
6 }
8 Terrain::~Terrain()
9 {
10 delete root;
11 }
13 float Terrain::get_height(float x, float y) const
14 {
15 return root->get_height(x, y);
16 }
19 TerrainNode::TerrainNode()
20 {
21 height = 0;
22 child[0] = child[1] = child[2] = child[3];
23 }
25 TerrainNode::~TerrainNode()
26 {
27 for(auto c : child) {
28 delete c;
29 }
30 delete [] height;
31 }
33 TerrainNode *TerrainNode::get_child(float x, float y)
34 {
35 int xidx = x >= 0.0 ? 1 : 0;
36 int yidx = y >= 0.0 ? 1 : 0;
37 return child[y * 2 + x];
38 }
40 const TerrainNode *TerrainNode::get_child(float x, float y) const
41 {
42 int xidx = x >= 0.0 ? 1 : 0;
43 int yidx = y >= 0.0 ? 1 : 0;
44 return child[y * 2 + x];
45 }
47 float TerrainNode::get_height(float x, float y) const
48 {
49 TerrainNode *child = get_child(x, y);
50 if(child) {
52 }
53 }