From 912ebb62d5e8602a196a59887ef4d41cf0d6edbf Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 9 Mar 2008 11:04:35 +0000 Subject: fixed sphere black hole, added basic HUD with speed and direction indicator, basic shaped entities readable from world.ini --- src/render/draw.cc | 119 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 83 insertions(+), 36 deletions(-) (limited to 'src/render/draw.cc') diff --git a/src/render/draw.cc b/src/render/draw.cc index 2dbdc6f..3fed4dd 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -6,28 +6,25 @@ #include "core/core.h" #include "core/model.h" -#include "render/box.h" #include "render/draw.h" -#include "render/render.h" #include "render/sphere.h" namespace render { -render::Sphere sphere(math::Vector3f(0,0,0),1); -render::Box cube(math::Vector3f(0.5f, 0.5f, 0.5f), math::Vector3f(-0.5f, -0.5f, -0.5f)); +render::Sphere sphere(1); -math::Vector3f v0(1.0f, -1.0f, -1.0f); -math::Vector3f v1(1.0f, 1.0f, -1.0f); -math::Vector3f v2(1.0f, 1.0f, 1.0f); -math::Vector3f v3(1.0f, -1.0f, 1.0f); +math::Vector3f v0(1, -1, 1); +math::Vector3f v1(1, 1, 1); +math::Vector3f v2(-1, 1, 1); +math::Vector3f v3(-1, -1, 1); -math::Vector3f v4(-1.0f, -1.0f, -1.0f); -math::Vector3f v5(-1.0f, 1.0f, -1.0f); -math::Vector3f v6(-1.0f, 1.0f, 1.0f); -math::Vector3f v7(-1.0f, -1.0f, 1.0f); -float angle = 0; +math::Vector3f v4(1, -1, -1); +math::Vector3f v5(1, 1, -1); +math::Vector3f v6(-1, 1, -1); +math::Vector3f v7(-1, -1, -1); +float angle = 0; void draw_model(core::Model *model, core::Entity *entity) { @@ -41,6 +38,7 @@ void draw_model(core::Model *model, core::Entity *entity) // draw all vertexes gl::begin(gl::Polygon); + //gl::begin(gl::LineLoop); gl::normal((*fit)->normal()); for (std::vector::iterator vit = (*fit)->face_vertex.begin(); vit != (*fit)->face_vertex.end(); vit++) { gl::vertex(*(*vit)); @@ -67,17 +65,59 @@ void draw_model_engines(core::Model *model, core::EntityControlable *entity) void draw_entity_sphere(core::Entity *entity) { - render::gl::color(entity->color()); + sphere.sphere_color = entity->color(); sphere.radius = entity->radius(); sphere.draw(); } void draw_entity_cube(core::Entity *entity) { - cube.topcolor = entity->color(); - cube.bottomcolor = entity->color(); - cube.radius = entity->radius(); - cube.draw(); + float radius = entity->radius()/2; + gl::scale(radius, radius, radius); + + gl::color(entity->color()); + gl::begin(gl::Quads); + + // top + gl::normal(0,0,1); + gl::vertex(v0); + gl::vertex(v1); + gl::vertex(v2); + gl::vertex(v3); + + // bottom + gl::normal(0,0, -1); + gl::vertex(v7); + gl::vertex(v6); + gl::vertex(v5); + gl::vertex(v4); + + // sides + gl::normal(1,0,0); + gl::vertex(v1); + gl::vertex(v0); + gl::vertex(v4); + gl::vertex(v5); + + gl::normal(-1,0,0); + gl::vertex(v3); + gl::vertex(v2); + gl::vertex(v6); + gl::vertex(v7); + + gl::normal(0,1,0); + gl::vertex(v2); + gl::vertex(v1); + gl::vertex(v5); + gl::vertex(v6); + + gl::normal(0,-1,0); + gl::vertex(v0); + gl::vertex(v3); + gl::vertex(v7); + gl::vertex(v4); + + gl::end(); } @@ -116,15 +156,17 @@ void draw_entity_default(core::Entity *entity) if (model) { draw_model(model, entity); } else { - gl::disable(GL_LIGHTING); - gl::disable(GL_LIGHT0); + //gl::disable(GL_LIGHTING); + //gl::disable(GL_LIGHT0); switch(entity->shape()) { case core::Entity::Sphere: draw_entity_sphere(entity); break; - + case core::Entity::Diamond: + + case core::Entity::Axis: draw_entity_axis(entity); break; @@ -135,8 +177,8 @@ void draw_entity_default(core::Entity *entity) break; } - gl::enable(GL_LIGHTING); - gl::enable(GL_LIGHT0); // disable camera light + //gl::enable(GL_LIGHTING); + //gl::enable(GL_LIGHT0); // disable camera light } gl::pop(); @@ -166,24 +208,24 @@ void draw_entity_controlable(core::EntityControlable *entity) gl::color(math::Color(0.0f, 1.0f ,0.0f , 0.5f)); gl::begin(gl::LineLoop); - gl::normal(0, -0.5, -0.5); - gl::vertex(v0); - gl::normal(0, 0.5, -0.5); - gl::vertex(v1); gl::normal(0, 0.5, 0.5); - gl::vertex(v2); + gl::vertex(v1); gl::normal(0, -0.5, 0.5); - gl::vertex(v3); - gl::end(); - - gl::begin(gl::LineLoop); + gl::vertex(v0); gl::normal(0, -0.5, -0.5); gl::vertex(v4); gl::normal(0, 0.5, -0.5); - gl::vertex(v5); + gl::vertex(v5); + gl::end(); + + gl::begin(gl::LineLoop); + gl::normal(0, -0.5, 0.5); + gl::vertex(v3); gl::normal(0, 0.5, 0.5); + gl::vertex(v2); + gl::normal(0, 0.5, -0.5); gl::vertex(v6); - gl::normal(0, -0.5, 0.5); + gl::normal(0, -0.5, -0.5); gl::vertex(v7); gl::end(); @@ -239,8 +281,10 @@ void draw(math::Vector3f const &target, float seconds) gl::enable(GL_CULL_FACE); // enable culling gl::enable(GL_COLOR_MATERIAL); // enable color tracking gl::enable(GL_LIGHTING); - gl::enable(GL_LIGHT0); // enable camera light - + gl::enable(GL_LIGHT0); + + gl::disable(GL_BLEND); // disbable alpha blending for world polys + std::map::iterator it; for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { switch ((*it).second->type()) { @@ -259,6 +303,9 @@ void draw(math::Vector3f const &target, float seconds) gl::disable(GL_LIGHTING); gl::disable(GL_COLOR_MATERIAL); // disable color tracking gl::disable(GL_CULL_FACE); // disable culling + + gl::enable(GL_BLEND); // enable alpha blending again + draw_spacegrid(target); // draw the blue spacegrid gl::disable(GL_DEPTH_TEST); // disable depth buffer writing -- cgit v1.2.3