diff options
author | Stijn Buys <ingar@osirion.org> | 2008-07-16 22:55:07 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-07-16 22:55:07 +0000 |
commit | eb075660e7cb61b138c2da337115c59857f89e17 (patch) | |
tree | 0fe031a8f3562b22f61d0f95b740fe5f2326fd7b /src/render | |
parent | fecc54ad8c5a108831c2bc268f9dd7e16b511b7e (diff) |
network protocol cleanup, radar test (doesn't work)
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/camera.cc | 26 | ||||
-rw-r--r-- | src/render/camera.h | 5 | ||||
-rw-r--r-- | src/render/draw.cc | 65 | ||||
-rw-r--r-- | src/render/text.cc | 8 |
4 files changed, 71 insertions, 33 deletions
diff --git a/src/render/camera.cc b/src/render/camera.cc index 287e4ad..8fe84a7 100644 --- a/src/render/camera.cc +++ b/src/render/camera.cc @@ -150,9 +150,8 @@ void Camera::next_mode() } } -void Camera::draw(float seconds) +void Camera::frame(float seconds) { - math::Matrix4f matrix; math::Axis target_axis; float d = 0; @@ -304,14 +303,28 @@ void Camera::draw(float seconds) distance += frustum_front; + // calculate eye position + camera_eye = camera_target - (distance * camera_axis.forward()); +} + +void Camera::draw() +{ + // 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, 2048.0f); + + gl::matrixmode(GL_MODELVIEW); + gl::loadidentity(); + // map world coordinates to opengl coordinates gl::rotate(90.0f, 0, 1.0, 0); gl::rotate(-90.0f, 1.0f , 0, 0); - // assign transformation matrix - matrix.assign(camera_axis); - // apply the transpose of the axis transformation (the axis is orhtonormal) + math::Matrix4f matrix; + matrix.assign(camera_axis); gl::multmatrix(matrix.transpose()); // match the camera with the current target @@ -319,9 +332,6 @@ void Camera::draw(float seconds) // apply camera offset gl::translate(distance * camera_axis.forward()); - - // calculate eye position - camera_eye = camera_target - (distance * camera_axis.forward()); } void Camera::set_direction(float direction) diff --git a/src/render/camera.h b/src/render/camera.h index 52d2e13..edc3496 100644 --- a/src/render/camera.h +++ b/src/render/camera.h @@ -46,8 +46,11 @@ public: /// reset the current mode static void reset(); + /// progress the camera + static void frame(float elapsed); + /// draw the OpenGL camera transformation - static void draw(float elapsed); + static void draw(); /// set target direction static void set_direction(float direction); 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<unsigned int, core::Entity *>::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 } diff --git a/src/render/text.cc b/src/render/text.cc index 7c1ae8e..f5c221f 100644 --- a/src/render/text.cc +++ b/src/render/text.cc @@ -98,16 +98,16 @@ void Text::draw(float x, float y, const char ascii) gl::begin(gl::Quads); glTexCoord2f(fcol, frow); - gl::vertex(x,y,1); + gl::vertex(x,y, 0); glTexCoord2f(fcol + 0.0625f, frow); - gl::vertex(x+text_fontwidth,y,1); + gl::vertex(x+text_fontwidth,y, 0); glTexCoord2f(fcol +0.0625f, frow + 0.0625f); - gl::vertex(x+text_fontwidth,y+text_fontheight,1); + gl::vertex(x+text_fontwidth,y+text_fontheight, 0); glTexCoord2f(fcol, frow+0.0625f); - gl::vertex(x,y+text_fontheight,1); + gl::vertex(x,y+text_fontheight, 0); gl::end(); } |