Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-03-09 11:04:35 +0000
committerStijn Buys <ingar@osirion.org>2008-03-09 11:04:35 +0000
commit912ebb62d5e8602a196a59887ef4d41cf0d6edbf (patch)
tree248fa306aa28762108e900de8d7c8b655a603fef /src
parent07c0040f3433cc637fecbb712fb3b6f5ad1ab5de (diff)
fixed sphere black hole, added basic HUD with speed and direction indicator, basic shaped entities readable from world.ini
Diffstat (limited to 'src')
-rw-r--r--src/client/view.cc8
-rw-r--r--src/core/entity.cc3
-rw-r--r--src/core/entity.h2
-rw-r--r--src/core/model.cc25
-rw-r--r--src/filesystem/inifile.cc79
-rw-r--r--src/filesystem/inifile.h13
-rw-r--r--src/game/game.cc167
-rw-r--r--src/render/Makefile.am4
-rw-r--r--src/render/box.cc102
-rw-r--r--src/render/box.h47
-rw-r--r--src/render/draw.cc119
-rw-r--r--src/render/draw.h2
-rw-r--r--src/render/render.h1
-rw-r--r--src/render/sphere.cc77
-rw-r--r--src/render/sphere.h11
15 files changed, 317 insertions, 343 deletions
diff --git a/src/client/view.cc b/src/client/view.cc
index 0a5c44e..8da7892 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -168,6 +168,14 @@ void draw_status()
n = (n+1) % MAXNOTIFYLINES;
}
+ // draw a basic HUD
+ if (core::localcontrol()) {
+ status.str("");
+ status << " dir " << std::setfill('0') << std::setw(3) << roundf(core::localcontrol()->direction()) <<
+ " speed " << std::setfill(' ') << std::setw(5) << std::fixed << std::setprecision(2) << core::localcontrol()->speed();
+ draw_text(CHARWIDTH, video::height - CHARHEIGHT -4, status);
+ }
+
gl::disable(GL_TEXTURE_2D);
}
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 891c758..36868af 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -98,6 +98,9 @@ Entity::Entity(unsigned int flags) :
entity_destroyed = false;
entity_dirty = false;
+ entity_modelname.clear();
+ entity_name.clear();
+
add(this);
}
diff --git a/src/core/entity.h b/src/core/entity.h
index d887bc1..0eda501 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -33,7 +33,7 @@ public:
enum Type {Default=0, Dynamic=1, Controlable=2};
/// Entity shape constants
- enum Shape {Diamond=0, Sphere=1, Cube=2};
+ enum Shape {Diamond=0, Sphere=1, Cube=2, Axis=3};
/// create a new entity and add it to the registry
Entity(unsigned int flags = 0);
diff --git a/src/core/model.cc b/src/core/model.cc
index 1e571c3..52f0dde 100644
--- a/src/core/model.cc
+++ b/src/core/model.cc
@@ -453,16 +453,31 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
color = 0;
} else
color = new math::Color(1.0f, 0.0, 1.0f);
-
+
+ /*
+ // split face into triangles
+ while (vl.size() >2 ) {
+ std::vector<Vector3f *>::iterator v0 = vl.begin();
+ std::vector<Vector3f *>::reverse_iterator vn = vl.rbegin();
+ std::vector<Vector3f *>::reverse_iterator vn1 = vl.rbegin();
+ ++vn1;
+ */
Face *mf = new Face(face->normal()*-1, color);
- if (color) delete color;
-
for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
mf->add_vertex(*(*it) * model_scale);
}
-
- //con_debug << "adding face\n";
add_face(mf);
+ /*
+ mf->add_vertex(*(*vn) * model_scale);
+ mf->add_vertex(*(*v0) * model_scale);
+ mf->add_vertex(*(*vn1) * model_scale);
+ add_face(mf);
+
+ vl.pop_back();
+ }
+ */
+
+ if (color) delete color;
} else {
con_debug << "Unresolved face!\n";
}
diff --git a/src/filesystem/inifile.cc b/src/filesystem/inifile.cc
index 02dbcf8..dcc0876 100644
--- a/src/filesystem/inifile.cc
+++ b/src/filesystem/inifile.cc
@@ -4,10 +4,12 @@
the terms of the GNU General Public License version 2
*/
-// project headers
+#include "math/mathlib.h"
#include "filesystem/filesystem.h"
#include "filesystem/inifile.h"
+#include <sstream>
+
namespace filesystem {
IniFile::IniFile() {}
@@ -49,7 +51,7 @@ bool IniFile::got_section() const {
}
bool IniFile::got_section(const char * sectionlabel) const {
- return (last_read_was_section && section_current == sectionlabel);
+ return (last_read_was_section && (section_current.compare(sectionlabel) == 0));
}
bool IniFile::getline() {
@@ -83,11 +85,14 @@ bool IniFile::getline() {
} else {
// key=value pair
size_t found = s.find('=');
- if (found !=std::string::npos) {
- // FIXME strip spaces, make lowercase
+ if (found != std::string::npos) {
+ // make lowercase
key_current = s.substr(0, found);
- if (key_current.size() > 0) {
+ while (key_current.size() && key_current[key_current.size()-1] == ' ')
+ key_current.erase(key_current.size()-1, 1);
+
+ if (key_current.size()) {
value_current = s.substr(found+1, s.size() - found - 1);
last_read_was_key = true;
return true;
@@ -101,7 +106,6 @@ bool IniFile::getline() {
}
bool IniFile::got_key_string(const char * keylabel, std::string & valuestring) {
- //condebug << "IniFile got_value_string " << keylabel << " " << last_read_was_key << std::endl;
if (last_read_was_key && (key_current.compare(keylabel) == 0 )) {
valuestring.assign(value_current);
return true;
@@ -110,6 +114,69 @@ bool IniFile::got_key_string(const char * keylabel, std::string & valuestring) {
}
}
+bool IniFile::got_key_vector3f(const char * keylabel, math::Vector3f & v) {
+ if (last_read_was_key && (key_current.compare(keylabel) == 0 )) {
+ std::istringstream is(value_current);
+ float x, y, z;
+ if ((is >> x) && (is >> y) && (is >> z)) {
+ v = math::Vector3f(x,y,z);
+ } else {
+ v= math::Vector3f();
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool IniFile::got_key_float(const char * keylabel, float & f) {
+ if (last_read_was_key && (key_current.compare(keylabel) == 0 )) {
+ std::istringstream is(value_current);
+ if (!(is >> f)) {
+ f = 0;
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool IniFile::got_key(const char * keylabel) {
+ return (last_read_was_key && (key_current.compare(keylabel) == 0 ));
+}
+
+bool IniFile::got_key_angle(const char * keylabel, float & f) {
+ if (last_read_was_key && (key_current.compare(keylabel) == 0 )) {
+ std::istringstream is(value_current);
+ if ((is >> f)) {
+ f = math::degrees360f(f);
+ } else {
+ f = 0;
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool IniFile::got_key_color(const char * keylabel, math::Color & color) {
+ if (last_read_was_key && (key_current.compare(keylabel) == 0 )) {
+ std::istringstream is(value_current);
+ float r, g, b;
+ if ((is >> r) && (is >> g) && (is >> b)) {
+ if ((r > 1) || (g > 1) || (b > 1)) {
+ r /= 255; g /= 255; b /= 255;
+ }
+ color = math::Color(r, g, b);
+ } else {
+ color = math::Color();
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
void IniFile::close()
{
inifile_ifs.close();
diff --git a/src/filesystem/inifile.h b/src/filesystem/inifile.h
index 632d432..568eade 100644
--- a/src/filesystem/inifile.h
+++ b/src/filesystem/inifile.h
@@ -10,6 +10,8 @@
#include <string>
#include <fstream>
+#include "math/vector3f.h"
+#include "math/color.h"
#include "filesystem/file.h"
namespace filesystem {
@@ -57,9 +59,20 @@ public:
return last_read_was_key;
}
+ bool got_key(const char * keylabel);
+
/// check if the last read key=value pair matches keylabel and store the value in valuestring
bool got_key_string(const char * keylabel, std::string & valuestring);
+ bool got_key_color(const char * keylabel, math::Color & color);
+
+ bool got_key_float(const char * keylabel, float & f);
+
+ bool got_key_angle(const char * keylabel, float & f);
+
+ bool got_key_vector3f(const char * keylabel, math::Vector3f & v);
+
+
inline unsigned int line() const {
return line_number;
}
diff --git a/src/game/game.cc b/src/game/game.cc
index 96c382e..ff42817 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -127,73 +127,57 @@ void Game::init()
Star *star = 0;
core::Entity *entity = 0;
- std::string tmp;
while (f.getline()) {
if (f.got_key()) {
if (f.section().compare("star") == 0) {
-
- if (f.got_key_string("name", tmp)) {
- star->entity_name = tmp;
-
- } else if (f.got_key_string("model", tmp)) {
- star->entity_modelname = tmp;
-
- } else if (f.got_key_string("location", tmp)) {
- std::istringstream is(tmp);
- float x, y, z;
- if ((is >> x) && (is >> y) && (is >> z)) {
- star->entity_location = math::Vector3f(x,y,z);
- }
-
- } else if (f.got_key_string("color", tmp)) {
- std::istringstream is(tmp);
- float r, g, b;
- if ((is >> r) && (is >> g) && (is >> b)) {
- star->entity_color = math::Color(r, g, b);
- }
- } else
+ if (f.got_key_string("name", star->entity_name))
+ continue;
+ else if (f.got_key_string("model", star->entity_modelname))
+ continue;
+ else if (f.got_key_vector3f("location", star->entity_location ))
+ continue;
+ else if (f.got_key_color("color", star->entity_color))
+ continue;
+ else
con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl;
} else if (f.section().compare("entity") == 0) {
- if (f.got_key_string("name", tmp)) {
- entity->entity_name = tmp;
-
- } else if (f.got_key_string("model", tmp)) {
- entity->entity_modelname = tmp;
-
- } else if (f.got_key_string("direction", tmp)) {
- std::istringstream is(tmp);
- float a;
- if (is >> a) {
- entity->entity_direction = math::degrees360f(a);
- }
-
- } else if (f.got_key_string("location", tmp)) {
- std::istringstream is(tmp);
- float x, y, z;
- if ((is >> x) && (is >> y) && (is >> z)) {
- entity->entity_location = math::Vector3f(x,y,z);
- }
-
- } else if (f.got_key_string("color", tmp)) {
- std::istringstream is(tmp);
- float r, g, b;
- if ((is >> r) && (is >> g) && (is >> b)) {
- entity->entity_color = math::Color(r, g, b);
+ std::string shapename;
+
+ if (f.got_key_string("shape", shapename)) {
+ if (shapename.compare("axis") == 0) {
+ entity->entity_shape = core::Entity::Axis;
+ } else if (shapename.compare("cube") == 0) {
+ entity->entity_shape = core::Entity::Cube;
+ } else if (shapename.compare("diamond") == 0) {
+ entity->entity_shape = core::Entity::Diamond;
+ } else if (shapename.compare("sphere") == 0) {
+ entity->entity_shape = core::Entity::Sphere;
+ } else {
+ con_warn << f.name() << " unknown shape '" << shapename << "' at line " << f.line() << std::endl;
}
-
- } else {
+ continue;
+ } else if (f.got_key_string("name", entity->entity_name))
+ continue;
+ else if (f.got_key_string("model", entity->entity_modelname))
+ continue;
+ else if (f.got_key_angle("direction", entity->entity_direction))
+ continue;
+ else if (f.got_key_angle("radius", entity->entity_radius))
+ continue;
+ else if (f.got_key_vector3f("location", entity->entity_location))
+ continue;
+ else if (f.got_key_color("color", entity->entity_color))
+ continue;
+ else
con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl;
- }
}
} else if (f.got_section("star")) {
- //con_debug << "[star] section" << std::endl;
star = new Star();
} else if (f.got_section("entity")) {
- //con_debug << "[entity] section" << std::endl;
entity = new core::Entity();
} else if (f.got_section()) {
@@ -202,6 +186,7 @@ void Game::init()
}
f.close();
+/*
// the green cube
core::Entity *cube = new core::Entity(core::Entity::Solid & core::Entity::Static);
cube->entity_shape = core::Entity::Cube;
@@ -233,37 +218,7 @@ void Game::init()
axis->entity_color = Color(1.0f, 1.0f, 0.0f);
axis->entity_location = Vector3f(0, 0, 0);
axis->entity_name = "axis: Origin";
-
- /*
-
- // the star
- Star *star = new Star();
- star->entity_location = Vector3f(256.0f, -256.0f, 0.0f);
- star->entity_name = "star: Sabishi Hoshi";
-
- // Canasta
- cube = new core::Entity(core::Entity::Solid & core::Entity::Static);
- cube->entity_shape = core::Entity::Diamond;
- cube->entity_color = Color(0.5f, 1.0f, 5.0f);
- cube->entity_location = Vector3f(16.0f, 20.0f, 0.0f);
- cube->entity_name = "wreck: Canasta";
- cube->entity_modelname = "ships/canasta";
-
- // Micron Vector
- cube = new core::Entity(core::Entity::Solid & core::Entity::Static);
- cube->entity_shape = core::Entity::Diamond;
- cube->entity_color = Color(0.5f, 1.0f, 5.0f);
- cube->entity_location = Vector3f(17.0f, 21.0f, 0.0f);
- cube->entity_name = "wreck: Micron Vector";
- cube->entity_modelname = "ships/micron_vector";
-
- // Alexandria
- core::Entity *alexandria = new core::Entity(core::Entity::Solid & core::Entity::Static);
- alexandria->entity_location = Vector3f(0.0f, -64.0f, 0.0f);
- alexandria->entity_name = "station: Alexandria";
- alexandria->entity_modelname = "stations/alexandria";
- */
-
+*/
// read ship model specifications
f.open("ships");
if (!f.is_open())
@@ -276,40 +231,22 @@ void Game::init()
if (f.got_key()) {
if (f.section() == "ship") {
- if (f.got_key_string("name", tmp)) {
- shipmodel->shipmodel_name = tmp;
-
- } else if (f.got_key_string("model", tmp)) {
- shipmodel->shipmodel_modelname = tmp;
-
- } else if (f.got_key_string("default", tmp)) {
-
+ if (f.got_key_string("name",shipmodel->shipmodel_name)) {
+ continue;
+ } else if (f.got_key_string("model", shipmodel->shipmodel_modelname)) {
+ continue;
+ } else if (f.got_key("default")) {
default_shipmodel = shipmodel;
-
- } else if (f.got_key_string("acceleration", tmp)) {
- std::istringstream is(tmp);
- float a;
- if (is >> a) {
- shipmodel->shipmodel_acceleration = a;
- }
-
- } else if (f.got_key_string("maxspeed", tmp)) {
- std::istringstream is(tmp);
- float ms;
- if (is >> ms) {
- shipmodel->shipmodel_maxspeed = ms;
- }
-
- } else if (f.got_key_string("turnspeed", tmp)) {
-
- std::istringstream is(tmp);
- float ts;
- if (is >> ts) {
- shipmodel->shipmodel_turnspeed = ts;
- }
-
- } else
+ continue;
+ } else if (f.got_key_float("acceleration", shipmodel->shipmodel_acceleration)) {
+ continue;
+ } else if (f.got_key_float("maxspeed", shipmodel->shipmodel_maxspeed)) {
+ continue;
+ } else if (f.got_key_float("turnspeed", shipmodel->shipmodel_turnspeed)) {
+ continue;
+ } else {
con_warn << f.name() << " unknown key '" << f.key() << "' at line " << f.line() << std::endl;
+ }
}
} else if (f.got_section("ship")) {
shipmodel = new ShipModel();
diff --git a/src/render/Makefile.am b/src/render/Makefile.am
index 4041e1e..d9a8301 100644
--- a/src/render/Makefile.am
+++ b/src/render/Makefile.am
@@ -3,5 +3,5 @@ METASOURCES = AUTO
noinst_LTLIBRARIES = librender.la
librender_la_LDFLAGS = -avoid-version -no-undefined @GL_LIBS@
librender_la_LIBADD = $(top_builddir)/src/math/libmath.la
-librender_la_SOURCES = box.cc draw.cc gl.cc render.cc sphere.cc text.cc tga.cc
-noinst_HEADERS = box.h draw.h gl.h render.h sphere.h text.h tga.h
+librender_la_SOURCES = draw.cc gl.cc render.cc sphere.cc text.cc tga.cc
+noinst_HEADERS = draw.h gl.h render.h sphere.h text.h tga.h
diff --git a/src/render/box.cc b/src/render/box.cc
deleted file mode 100644
index d6f14b5..0000000
--- a/src/render/box.cc
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- render/box.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
-*/
-
-#include "render/box.h"
-
-namespace render {
-
-using math::Vector3f;
-using math::Color;
-
-Box::Box(Vector3f const & tl, Vector3f const &br) :
- topleft(tl), bottomright(br)
-{
- topcolor = Color::White();
- bottomcolor= Color::White() * 0.7f;
- radius = 1.0f;
-}
-
-Box::Box(const Box & other)
-{
- (*this) = other;
-}
-
-Box& Box::operator=(const Box &other)
-{
- bottomcolor = other.bottomcolor;
- topcolor = other.topcolor;
-
- topleft = other.topleft;
- bottomright = other.bottomright;
- return (*this);
-}
-
-void Box::draw()
-{
- using namespace gl;
-
- Vector3f v0(topleft.x, bottomright.y, bottomright.z);
- Vector3f v1(topleft.x, topleft.y, bottomright.z);
- Vector3f v2(topleft.x, topleft.y, topleft.z);
- Vector3f v3(topleft.x, bottomright.y, topleft.z);
-
- Vector3f v4(bottomright.x, bottomright.y, bottomright.z);
- Vector3f v5(bottomright.x, topleft.y, bottomright.z);
- Vector3f v6(bottomright.x, topleft.y, topleft.z);
- Vector3f v7(bottomright.x, bottomright.y, topleft.z);
-
- begin(Quads);
-
- // top
- color(topcolor);
- vertex(radius*v2);
- vertex(radius*v1);
- vertex(radius*v5);
- vertex(radius*v6);
-
- // sides
- color(bottomcolor);
- vertex(radius*v0);
- color(topcolor);
- vertex(radius*v1);
- vertex(radius*v2);
- color(bottomcolor);
- vertex(radius*v3);
-
- vertex(radius*v3);
- color(topcolor);
- vertex(radius*v2);
- vertex(radius*v6);
- color(bottomcolor);
- vertex(radius*v7);
-
- vertex(radius*v4);
- color(topcolor);
- vertex(radius*v5);
- vertex(radius*v1);
- color(bottomcolor);
- vertex(radius*v0);
-
- vertex(radius*v7);
- color(topcolor);
- vertex(radius*v6);
- vertex(radius*v5);
- color(bottomcolor);
- vertex(radius*v4);
-
- // bottom
- color(bottomcolor);
- vertex(radius*v4);
- vertex(radius*v0);
- vertex(radius*v3);
- vertex(radius*v7);
-
- end();
-
-}
-
-}
-
diff --git a/src/render/box.h b/src/render/box.h
deleted file mode 100644
index aa211e1..0000000
--- a/src/render/box.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- render/box.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
-*/
-
-#ifndef __INCLUDED_RENDER_BOX_H__
-#define __INCLUDED_RENDER_BOX_H__
-
-#include "render/render.h"
-#include "math/mathlib.h"
-
-namespace render {
-
-/// a drawable OpenGL block shape
-class Box
-{
-public:
- /// create a new standard cube with edge length 1
- Box(math::Vector3f const & tl, math::Vector3f const &br);
- /// copy constructor
- Box(const Box &other);
-
- /// assignment operator
- Box& operator=(const Box &other);
-
- /// top left vertex (1,1,1)
- math::Vector3f topleft;
- /// bottom right vertex (-1,-1,-1)
- math::Vector3f bottomright;
-
- /// draw the block
- void draw();
-
- /// Top color
- math::Color topcolor;
- /// bottom color
- math::Color bottomcolor;
-
- /// size factor
- float radius;
-};
-
-}
-
-#endif // __INCLUDED_RENDER_BOX_H__
-
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<math::Vector3f *>::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<unsigned int, core::Entity *>::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
diff --git a/src/render/draw.h b/src/render/draw.h
index f27818b..c1273aa 100644
--- a/src/render/draw.h
+++ b/src/render/draw.h
@@ -7,6 +7,8 @@
#ifndef __INCLUDED_RENDER_DRAW_H__
#define __INCLUDED_RENDER_DRAW_H__
+#include "math/vector3f.h"
+
namespace render
{
diff --git a/src/render/render.h b/src/render/render.h
index 306d340..c27b740 100644
--- a/src/render/render.h
+++ b/src/render/render.h
@@ -23,6 +23,7 @@ namespace render {
extern GLuint textures[32];
}
+#include "render/draw.h"
#include "render/gl.h"
#include "render/text.h"
#include "render/tga.h"
diff --git a/src/render/sphere.cc b/src/render/sphere.cc
index 1715263..616424e 100644
--- a/src/render/sphere.cc
+++ b/src/render/sphere.cc
@@ -14,15 +14,14 @@ namespace render {
const int segments = 33;
-Sphere::Sphere(Vector3f p , float r)
+Sphere::Sphere(float r)
{
- position = p;
radius = r;
// TODO make global sine-cosine lists
sintable = new float[segments];
costable = new float[segments];
- float d = 2 * M_PI / segments;
+ float d = 2 * M_PI / (segments-1);
for (int i=0; i < segments; i++) {
sintable[i] = sin( d * (float) i );
@@ -43,7 +42,7 @@ Sphere::Sphere(const Sphere &other)
Sphere& Sphere::operator=(const Sphere &other)
{
- position = other.position;
+ sphere_color = other.sphere_color;
radius = other.radius;
return (*this);
}
@@ -52,36 +51,72 @@ void Sphere::draw()
{
using namespace gl;
- // draw top
- // TODO upside-down
float r = radius*sintable[1];
- float h = radius*costable[1];
+ //float h = radius*costable[1];
+
+ gl::color(sphere_color);
- begin(LineLoop);
- //begin(Polygon);
- for (int i = segments-1; i >= 0; i--)
- vertex(r*costable[i], h, r*sintable[i]);
+ /*
+ // draw top
+ begin(Polygon);
+ normal(0, 1, 0);
+ for (int i = segments-1; i >= 0; i--) {
+ v = Vector3f(r*costable[i], h, r*sintable[i]);
+ n = v;
+ n.normalize();
+ normal(n);
+ vertex(v);
+ }
end();
// draw bottom
- // TODO upside-down
- begin(LineLoop);
- for (int i = 0; i< segments; i++)
- vertex(r*costable[i], -h, r*sintable[i]);
+ begin(Polygon);
+ normal(0, -1, 0);
+ for (int i = 0; i< segments; i++) {
+ //for (int i = segments-1; i >= 0; i--)
+ v = Vector3f(r*costable[i], -h, r*sintable[i]);
+ n = v;
+ n.normalize();
+ normal(n);
+ vertex(v);
+ }
end();
+ */
+
+ Vector3f v;
+ Vector3f n;
// draw body
- for (int j=1; j < segments-1; j++) {
+ for (int j=0; j < segments-1; j++) {
r = radius*sintable[j];
float r1 = radius*sintable[j+1];
begin(QuadStrip);
- vertex(r1, radius*costable[j+1], 0);
- vertex(r, radius*costable[j], 0);
+ v = Vector3f(r, radius*costable[j], 0);
+ n = v;
+ n.normalize();
+ normal(n);
+ vertex(v);
+
+ v = Vector3f(r1, radius*costable[j+1], 0);
+ n = v;
+ n.normalize();
+ normal(n);
+ vertex(v);
+
+ for (int i = segments-1; i >= 0; i--) {
+ v = Vector3f(r*costable[i], radius*costable[j], r*sintable[i]);
+ n = v;
+ n.normalize();
+ normal(n);
+ vertex(v);
+
+ v = Vector3f(r1*costable[i], radius*costable[j+1], r1*sintable[i]);
+ n = v;
+ n.normalize();
+ normal(n);
+ vertex(v);
- for (int i = segments-1; i >= 0; i--) {
- vertex(r1*costable[i], radius*costable[j+1], r1*sintable[i]);
- vertex(r*costable[i], radius*costable[j], r*sintable[i]);
//vertex(r*costable[i-1], radius*costable[j], r*sintable[i-1]);
//vertex(r1*costable[i-1], radius*costable[j+1], r1*sintable[i-1]);
}
diff --git a/src/render/sphere.h b/src/render/sphere.h
index b3ac826..73a2169 100644
--- a/src/render/sphere.h
+++ b/src/render/sphere.h
@@ -16,7 +16,7 @@ class Sphere
{
public:
/// create a new sphere
- Sphere(math::Vector3f p = math::Vector3f(), float r = 1.0f);
+ Sphere(float r = 1.0f);
/// copy constructor
Sphere(const Sphere &other);
@@ -30,16 +30,11 @@ public:
/// radius of the sphere
float radius;
- /// position of the sphere
- math::Vector3f position;
-
/// draw the sphere
void draw();
- /// Top color
- math::Color topcolor;
- /// bottom color
- math::Color bottomcolor;
+ /// color
+ math::Color sphere_color;
private:
float *sintable;