From 75a90df8bf7f38e746e021c23248e1607931132c Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Fri, 1 Jul 2011 17:20:53 +0200 Subject: Import and render tree models. Trees are loaded from the new trees.blend using assimp. Tree objects are then received from the server and rendered on the given terrain locations. Each chunk now holds a list of objects and coordinates, which can be used to easily add other models as well. Also moded the GLSL fog code to its own shader which can be linked in different programs. --- game.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'game.cpp') diff --git a/game.cpp b/game.cpp index e24bacf..1288b0c 100644 --- a/game.cpp +++ b/game.cpp @@ -88,6 +88,9 @@ void Game::handle_type(const boost::system::error_code& error, std::size_t bytes case message::MSG_TYPE_PLAYER: handle_player(); break; + case message::MSG_TYPE_OBJECT: + handle_object(); + break; default: std::cout << "unknown type: " << (int)*type << std::endl; } @@ -154,6 +157,25 @@ void Game::handle_player() { scene->players.push_back(Player::p(new Player(id, pos, name))); } +void Game::handle_object() { + message::Object m; + + m.recv(socket); + + // type is ignored for now + uint32_t type = m.get_type(); + Vector3 pos(m.get_pos()); + + Terrain::Chunk *chunk = scene->terrain->find_chunk(pos.x, pos.z); + if(!chunk) { + std::cerr << "got object for non-existing chunk, discarding" << std::endl; + return; + } + + pos.y = chunk->find(pos.x, pos.z)->get_height(pos.x, pos.z); + chunk->objects.push_back(Terrain::Chunk::ObjectPair(scene->tree, pos)); +} + Game& Game::get_instance() { if(!game) game = new Game(); -- cgit v1.2.3