From 151a2ac2434f4b4c23c107d9c21e4a18dd1a3c68 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 4 Feb 2008 18:42:05 +0000 Subject: converted client:: singleton classes to namespaces --- src/client/view.cc | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'src/client/view.cc') diff --git a/src/client/view.cc b/src/client/view.cc index 811a7f7..87afd38 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -22,32 +22,40 @@ using namespace render; namespace client { +namespace view +{ + ShipDrawer *shipdrawer = 0; StarDrawer *stardrawer = 0; game::Ship *target = 0; // the view's target -void View::init() +void init() { - // draw scene if (!shipdrawer) { stardrawer = new StarDrawer(&game.star); shipdrawer = new ShipDrawer(&game.ship); target = &game.ship; } + camera::init(); } -void View::shutdown() +void shutdown() { + camera::shutdown(); + delete stardrawer; stardrawer = 0; delete shipdrawer; shipdrawer = 0; } -void View::reset() +void reset() { + // set clear color + gl::clearcolor(0.0f, 0.0f, 0.0f, 1.0f); + // shading model: Gouraud (smooth). gl::shademodel(GL_SMOOTH); @@ -66,7 +74,7 @@ void View::reset() } -void View::draw_world(float elapsed) +void draw_world(float elapsed) { // draw the world gl::push(); @@ -83,7 +91,7 @@ void View::draw_world(float elapsed) } -void View::draw_background(float elapsed) +void draw_background(float elapsed) { using namespace gl; @@ -129,7 +137,7 @@ void View::draw_background(float elapsed) end(); } -void View::draw_loader() +void draw_loader() { gl::enable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, render::textures[0]); // bitmaps/loader.tga @@ -141,19 +149,19 @@ void View::draw_loader() gl::vertex(0,0, 0); glTexCoord2f(1.0f, 0.0f); - gl::vertex(video.width,0,0); + gl::vertex(video::width,0,0); glTexCoord2f(1.0f, 1.0f); - gl::vertex(video.width,video.height,0); + gl::vertex(video::width,video::height,0); glTexCoord2f(0.0f, 1.0f); - gl::vertex(0,video.height,0); + gl::vertex(0,video::height,0); gl::end(); gl::disable(GL_TEXTURE_2D); } -void View::draw_status() +void draw_status() { using namespace std; @@ -185,12 +193,12 @@ void View::draw_status() gl::color(0.0f, 1.0f, 0.0f, 1.0f); std::string version("ver. "); version.append(VERSION); - draw_text(video.width-(version.size()+1)*CHARWIDTH, 4, version); + draw_text(video::width-(version.size()+1)*CHARWIDTH, 4, version); gl::disable(GL_TEXTURE_2D); } -void View::frame(float seconds) +void frame(float seconds) { // Clear the color and depth buffers. gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -203,18 +211,13 @@ void View::frame(float seconds) gl::loadidentity(); const float frustumsize = 0.5f; - x = -frustumsize * video.ratio; - width = video.ratio; - y = -frustumsize; - height = 1; - gl::frustum(x, x+width, y, y +height, 1.0f, 1024.0f); + gl::frustum(-frustumsize*video::aspect, frustumsize*video::aspect, -frustumsize, frustumsize, 1.0f, 1024.0f); - gl::matrixmode(GL_MODELVIEW); + gl::matrixmode(GL_MODELVIEW); // map world to screen coordinates gl::loadidentity(); gl::rotate(90.0f, 0, 1.0, 0); - // Camera transformation - camera.draw(seconds); + camera::draw(seconds); // draw the current camera transformation gl::enable(GL_DEPTH_TEST); // enable depth buffer writing gl::enable(GL_CULL_FACE); // enable culling @@ -232,7 +235,7 @@ void View::frame(float seconds) // switch to ortographic projection to draw the GUI gl::matrixmode(GL_PROJECTION); gl::loadidentity(); - glOrtho(0, video.width, video.height, 0, -1000.0f, 1000.0f); + glOrtho(0, video::width, video::height, 0, -1000.0f, 1000.0f); gl::matrixmode(GL_MODELVIEW); gl::loadidentity(); @@ -252,5 +255,7 @@ void View::frame(float seconds) gl::disable(GL_BLEND); } -} // namespace view +} //namespace view + +} // namespace client -- cgit v1.2.3