From eb075660e7cb61b138c2da337115c59857f89e17 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 16 Jul 2008 22:55:07 +0000 Subject: network protocol cleanup, radar test (doesn't work) --- src/render/draw.cc | 65 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 20 deletions(-) (limited to 'src/render/draw.cc') diff --git a/src/render/draw.cc b/src/render/draw.cc index c650169..18c3d73 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -12,6 +12,7 @@ #include "render/render.h" #include "render/textures.h" #include "render/draw.h" +#include "render/gl.h" namespace render { @@ -36,7 +37,7 @@ math::Vector3f v6(-1, 1, -1); math::Vector3f v7(-1, -1, -1); const float drawdistance = 128.0f; -const float drawfxdistance = 32.0f; +const float drawfxdistance = 64.0f; float angle = 0; @@ -299,6 +300,15 @@ void pass_prepare(float seconds) // reset light state gl::disable(GL_LIGHT1); + // get the current OpenGL transformation matrices + GLdouble gl_projection_matrix[16]; + GLdouble gl_model_matrix[16]; + GLint gl_viewport[4]; + + glGetDoublev(GL_PROJECTION, gl_projection_matrix); + glGetDoublev(GL_MODELVIEW, gl_model_matrix); + glGetIntegerv(GL_VIEWPORT, gl_viewport); + std::map::iterator it; for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { @@ -353,8 +363,9 @@ void pass_prepare(float seconds) entity->entity_clientstate = new core::ClientState(entity); } - entity->state()->state_visible = true; + entity->state()->state_visible = false; entity->state()->state_detailvisible = false; + entity->state()->state_targetable = false; // calculate visibility for entities with models if (entity->model()) { @@ -373,6 +384,8 @@ void pass_prepare(float seconds) } } else { + entity->state()->state_visible = true; + if (entity->type() == core::Entity::Globe) { core::EntityGlobe *globe = (core::EntityGlobe *) entity; @@ -408,6 +421,21 @@ void pass_prepare(float seconds) } } } + + // calculate screen position + if (entity->state()->visible()) { + GLdouble x = 0; + GLdouble y = 0; + GLdouble z = 0; + + math::Vector3f const & pos = entity->state()->location(); + if (gluProject((GLdouble) pos.x , (GLdouble)pos.y, (GLdouble)pos.z, gl_model_matrix, gl_projection_matrix, gl_viewport, &x, &y, &z) == GL_TRUE) { + entity->state()->state_screenlocation[0] = x; + entity->state()->state_screenlocation[1] = y; + entity->state()->state_screenlocation[2] = z; + entity->state()->state_targetable = true; + } + } } } @@ -723,7 +751,7 @@ void draw_pass_sky() gl::push(); gl::translate(Camera::eye()); - draw_sphere_inside(math::Color(), 8192); + draw_sphere_inside(math::Color(), 128); gl::pop(); gl::disable(GL_TEXTURE_2D); @@ -747,6 +775,7 @@ void draw_pass_spacegrid() gl::normal(0, 0, 1.0f); gl::begin(gl::Lines); + for (int i=-gridsize; i <= gridsize; i++) { gl::color(0,0, 0, 0); gl::vertex(i-dx, -gridsize-dy, z); @@ -780,15 +809,8 @@ void draw(float seconds) angle -= 360.0f; } - // Change to the projection matrix and set our viewing volume large enough for the skysphere - gl::matrixmode(GL_PROJECTION); - gl::loadidentity(); - gl::frustum(-frustum_size*Camera::aspect(), frustum_size*Camera::aspect(), - -frustum_size, frustum_size, frustum_front, 8192.0f); - - gl::matrixmode(GL_MODELVIEW); - gl::loadidentity(); - Camera::draw(seconds); // draw the current camera transformation + Camera::frame(seconds); + Camera::draw(); // draw the current camera transformation // calculate client state pass_prepare(seconds); @@ -813,24 +835,27 @@ void draw(float seconds) glEnableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_COLOR_ARRAY); - gl::disable(GL_BLEND); // disbable alpha blending - gl::disable(GL_RESCALE_NORMAL); + gl::enable(GL_DEPTH_TEST); + gl::depthmask(GL_FALSE); // disable depth buffer writing draw_pass_sky(); // draw the skysphere - gl::enable(GL_DEPTH_TEST); // enable depth buffer writing + + gl::depthmask(GL_TRUE); // enable writing to the depth buffer + gl::enable(GL_CULL_FACE); // enable culling gl::enable(GL_COLOR_MATERIAL); // enable color tracking gl::enable(GL_LIGHTING); gl::enable(GL_RESCALE_NORMAL); // rescale normals by the transformation matrix scale factor - + draw_pass_default(); // draw entities without model + + gl::disable(GL_RESCALE_NORMAL); glEnableClientState(GL_COLOR_ARRAY); - gl::disable(GL_RESCALE_NORMAL); draw_pass_model_vertex(); // draw entities with model - + glDisableClientState(GL_COLOR_ARRAY); draw_pass_model_evertex(); // draw entities with model, vertices with entity color @@ -855,8 +880,8 @@ void draw(float seconds) gl::disable(GL_LIGHTING); gl::disable(GL_COLOR_MATERIAL); // disable color tracking gl::disable(GL_CULL_FACE); // disable culling - gl::disable(GL_DEPTH_TEST); // disable depth buffer - + + gl::disable(GL_DEPTH_TEST); // disable depth buffer testing // GL_BLEND must be enabled for the GUI } -- cgit v1.2.3