# HG changeset patch # User John Tsiombikas # Date 1337912900 -10800 # Node ID cd12944a8ea842c423c6d7f194223cefe1297fb7 # Parent 8d95187cb3ee10bf070859182f122629d07dd223 foo diff -r 8d95187cb3ee -r cd12944a8ea8 level/src/terrain.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/level/src/terrain.cc Fri May 25 05:28:20 2012 +0300 @@ -0,0 +1,53 @@ +#include "terrain.h" + +Terrain::Terrain() +{ + root = 0; +} + +Terrain::~Terrain() +{ + delete root; +} + +float Terrain::get_height(float x, float y) const +{ + return root->get_height(x, y); +} + + +TerrainNode::TerrainNode() +{ + height = 0; + child[0] = child[1] = child[2] = child[3]; +} + +TerrainNode::~TerrainNode() +{ + for(auto c : child) { + delete c; + } + delete [] height; +} + +TerrainNode *TerrainNode::get_child(float x, float y) +{ + int xidx = x >= 0.0 ? 1 : 0; + int yidx = y >= 0.0 ? 1 : 0; + return child[y * 2 + x]; +} + +const TerrainNode *TerrainNode::get_child(float x, float y) const +{ + int xidx = x >= 0.0 ? 1 : 0; + int yidx = y >= 0.0 ? 1 : 0; + return child[y * 2 + x]; +} + +float TerrainNode::get_height(float x, float y) const +{ + TerrainNode *child = get_child(x, y); + if(child) { + + } +} diff -r 8d95187cb3ee -r cd12944a8ea8 level/src/terrain.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/level/src/terrain.h Fri May 25 05:28:20 2012 +0300 @@ -0,0 +1,37 @@ +#ifndef TERRAIN_H_ +#define TERRAIN_H_ + +#include +#include + +class TerrainNode; + +class Terrain { +private: + TerrainNode *root; + +public: + Terrain(); + ~Terrain(); + + float get_height(float x, float y) const; +}; + + +class TerrainNode { +private: + unsigned char *height; + +public: + TerrainNode *child[4]; + + TerrainNode(); + ~TerrainNode(); + + TerrainNode *get_child(float x, float y); + const TerrainNode *get_child(float x, float y) const; + + float get_height(float x, float y) const; +}; + +#endif // TERRAIN_H_ diff -r 8d95187cb3ee -r cd12944a8ea8 src/game_part.cc --- a/src/game_part.cc Wed May 23 17:10:46 2012 +0300 +++ b/src/game_part.cc Fri May 25 05:28:20 2012 +0300 @@ -3,6 +3,13 @@ #include "game_part.h" #include "level.h" +Game::Game() +{ + cam_theta = 0; + cam_phi = 45; + cam_dist = 5; +} + Game::~Game() {} bool Game::init() @@ -26,9 +33,9 @@ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glTranslatef(0, 0, -4); - glRotatef(50, 1, 0, 0); - glRotatef(current_time / 100.0, 0, 1, 0); + glTranslatef(0, 0, -cam_dist); + glRotatef(cam_phi, 1, 0, 0); + glRotatef(cam_theta, 0, 1, 0); level.draw(); } @@ -52,3 +59,39 @@ break; } } + +static bool bnstate[32]; +static int prev_x, prev_y; + +void Game::mouse_button(int bn, bool pressed) +{ + bnstate[bn] = pressed; + + if(pressed) { + if(bn == 3) { + cam_dist -= 0.2; + if(cam_dist < 0) { + cam_dist = 0; + } + } + if(bn == 4) { + cam_dist += 0.2; + } + } +} + +void Game::mouse_motion(int x, int y) +{ + int dx = x - prev_x; + int dy = y - prev_y; + prev_x = x; + prev_y = y; + + if(bnstate[2]) { + cam_theta += dx * 0.5; + cam_phi += dy * 0.5; + + if(cam_phi < 0) cam_phi = 0; + if(cam_phi > 90) cam_phi = 90; + } +} diff -r 8d95187cb3ee -r cd12944a8ea8 src/game_part.h --- a/src/game_part.h Wed May 23 17:10:46 2012 +0300 +++ b/src/game_part.h Fri May 25 05:28:20 2012 +0300 @@ -7,7 +7,10 @@ class Game : public Part { private: Level level; + float cam_theta, cam_phi, cam_dist; + public: + Game(); ~Game(); bool init(); @@ -17,6 +20,8 @@ void draw() const; void reshape(int x, int y); void key(int key, bool pressed); + void mouse_button(int bn, bool pressed); + void mouse_motion(int x, int y); }; #endif // GAME_PART_H_