stratgame

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/level/src/terrain.cc	Fri May 25 05:28:20 2012 +0300
     1.3 @@ -0,0 +1,53 @@
     1.4 +#include "terrain.h"
     1.5 +
     1.6 +Terrain::Terrain()
     1.7 +{
     1.8 +	root = 0;
     1.9 +}
    1.10 +
    1.11 +Terrain::~Terrain()
    1.12 +{
    1.13 +	delete root;
    1.14 +}
    1.15 +
    1.16 +float Terrain::get_height(float x, float y) const
    1.17 +{
    1.18 +	return root->get_height(x, y);
    1.19 +}
    1.20 +
    1.21 +
    1.22 +TerrainNode::TerrainNode()
    1.23 +{
    1.24 +	height = 0;
    1.25 +	child[0] = child[1] = child[2] = child[3];
    1.26 +}
    1.27 +
    1.28 +TerrainNode::~TerrainNode()
    1.29 +{
    1.30 +	for(auto c : child) {
    1.31 +		delete c;
    1.32 +	}
    1.33 +	delete [] height;
    1.34 +}
    1.35 +
    1.36 +TerrainNode *TerrainNode::get_child(float x, float y)
    1.37 +{
    1.38 +	int xidx = x >= 0.0 ? 1 : 0;
    1.39 +	int yidx = y >= 0.0 ? 1 : 0;
    1.40 +	return child[y * 2 + x];
    1.41 +}
    1.42 +
    1.43 +const TerrainNode *TerrainNode::get_child(float x, float y) const
    1.44 +{
    1.45 +	int xidx = x >= 0.0 ? 1 : 0;
    1.46 +	int yidx = y >= 0.0 ? 1 : 0;
    1.47 +	return child[y * 2 + x];
    1.48 +}
    1.49 +
    1.50 +float TerrainNode::get_height(float x, float y) const
    1.51 +{
    1.52 +	TerrainNode *child = get_child(x, y);
    1.53 +	if(child) {
    1.54 +
    1.55 +	}
    1.56 +}