Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--osirion.kdevelop2
-rw-r--r--osirion.kdevelop.pcsbin714707 -> 720726 bytes
-rw-r--r--osirion.kdevses9
-rw-r--r--src/core/entity.h2
-rw-r--r--src/game/Makefile.am4
-rw-r--r--src/game/game.cc23
-rw-r--r--src/game/game.h4
-rw-r--r--src/game/star.cc1
-rw-r--r--src/model/vertexarray.cc55
-rw-r--r--src/model/vertexarray.h4
-rw-r--r--src/render/draw.cc155
11 files changed, 119 insertions, 140 deletions
diff --git a/osirion.kdevelop b/osirion.kdevelop
index 466b3db..82878a1 100644
--- a/osirion.kdevelop
+++ b/osirion.kdevelop
@@ -21,7 +21,7 @@
</general>
<kdevautoproject>
<general>
- <activetarget>src/audio/libaudio.la</activetarget>
+ <activetarget>src/game/libgame.la</activetarget>
<useconfiguration>debug</useconfiguration>
</general>
<run>
diff --git a/osirion.kdevelop.pcs b/osirion.kdevelop.pcs
index ca71239..f8f5974 100644
--- a/osirion.kdevelop.pcs
+++ b/osirion.kdevelop.pcs
Binary files differ
diff --git a/osirion.kdevses b/osirion.kdevses
index c1fb79c..e8415d1 100644
--- a/osirion.kdevses
+++ b/osirion.kdevses
@@ -1,14 +1,7 @@
<?xml version = '1.0' encoding = 'UTF-8'?>
<!DOCTYPE KDevPrjSession>
<KDevPrjSession>
- <DocsAndViews NumberOfDocuments="2" >
- <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/view.cc" >
- <View0 Encoding="" line="47" Type="Source" />
- </Doc0>
- <Doc1 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/chat.cc" >
- <View0 Encoding="" line="0" Type="Source" />
- </Doc1>
- </DocsAndViews>
+ <DocsAndViews NumberOfDocuments="0" />
<pluginList>
<kdevdebugger>
<breakpointList/>
diff --git a/src/core/entity.h b/src/core/entity.h
index 287157b..c93d059 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -316,6 +316,8 @@ public:
virtual void serialize(std::ostream & os) const;
+ inline const std::string &texture() const { return entity_texture; }
+
/*----- inspectors ------------------------------------------------ */
/// core type id
diff --git a/src/game/Makefile.am b/src/game/Makefile.am
index e9f8d0b..394e209 100644
--- a/src/game/Makefile.am
+++ b/src/game/Makefile.am
@@ -2,7 +2,7 @@ INCLUDES = -I$(top_srcdir)/src
METASOURCES = AUTO
libgame_la_LDFLAGS = -avoid-version
-libgame_la_SOURCES = game.cc ship.cc shipmodel.cc star.cc
+libgame_la_SOURCES = game.cc planet.cc ship.cc shipmodel.cc star.cc
noinst_LTLIBRARIES = libgame.la
-noinst_HEADERS = game.h ship.h shipmodel.h star.h
+noinst_HEADERS = game.h planet.h ship.h shipmodel.h star.h
diff --git a/src/game/game.cc b/src/game/game.cc
index 4a77d7d..15ae029 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -11,6 +11,7 @@
#include "filesystem/filesystem.h"
#include "filesystem/inifile.h"
#include "game/game.h"
+#include "game/planet.h"
#include "game/ship.h"
#include "game/star.h"
#include "math/mathlib.h"
@@ -156,6 +157,7 @@ void Game::init()
return;
}
+ Planet *planet = 0;
Star *star = 0;
core::Entity *entity = 0;
@@ -168,12 +170,26 @@ void Game::init()
if (worldini.section().compare("star") == 0) {
if (worldini.got_key_string("name", star->entity_name))
continue;
- else if (worldini.got_key_string("model", star->entity_modelname))
- continue;
else if (worldini.got_key_vector3f("location", star->entity_location ))
continue;
else if (worldini.got_key_color("color", star->entity_color))
continue;
+ else if (worldini.got_key_angle("radius", star->entity_radius))
+ continue;
+ else
+ con_warn << worldini.name() << " unknown key '" << worldini.key() << "' at line " << worldini.line() << std::endl;
+
+ } else if (worldini.section().compare("planet") == 0) {
+ if (worldini.got_key_string("name", planet->entity_name))
+ continue;
+ else if (worldini.got_key_string("texture", planet->entity_texture))
+ continue;
+ else if (worldini.got_key_vector3f("location", planet->entity_location ))
+ continue;
+ else if (worldini.got_key_color("color", planet->entity_color))
+ continue;
+ else if (worldini.got_key_angle("radius", planet->entity_radius))
+ continue;
else
con_warn << worldini.name() << " unknown key '" << worldini.key() << "' at line " << worldini.line() << std::endl;
@@ -219,6 +235,9 @@ void Game::init()
} else if (worldini.got_section("star")) {
star = new Star();
+ } else if (worldini.got_section("planet")) {
+ planet = new Planet();
+
} else if (worldini.got_section("entity")) {
entity = new core::Entity();
entity->entity_flags += core::Entity::Static;
diff --git a/src/game/game.h b/src/game/game.h
index 811de84..89889a0 100644
--- a/src/game/game.h
+++ b/src/game/game.h
@@ -26,9 +26,7 @@ namespace game
// entity type constants
const unsigned int ship_enttype = 256;
const unsigned int star_enttype = 257;
-const unsigned int cube_enttype = 258;
-const unsigned int sphere_enttype = 259;
-const unsigned int axis_enttype = 260;
+const unsigned int planet_enttype = 258;
class Game : public core::Module {
public:
diff --git a/src/game/star.cc b/src/game/star.cc
index 0a12593..367054f 100644
--- a/src/game/star.cc
+++ b/src/game/star.cc
@@ -12,7 +12,6 @@ namespace game {
Star::Star() : core::EntityGlobe(core::Entity::Static | core::Entity::Solid | core::Entity::Bright)
{
- entity_shape = core::Entity::Sphere; // a star is a sphere
entity_color = math::Color(1,1,1,1); // white
entity_radius = 48; // 48 game units
diff --git a/src/model/vertexarray.cc b/src/model/vertexarray.cc
index d13fc0c..da9c3d2 100644
--- a/src/model/vertexarray.cc
+++ b/src/model/vertexarray.cc
@@ -74,47 +74,45 @@ void VertexArray::add_sphere()
math::Color white(1.0f, 1.0f, 1.0f);
math::Vector3f v;
math::Vector3f n;
+ math::Vector3f tex;
int count;
- for (int j=0; j < SPHERESEGMENTS-1; j++) {
+ //float h = (float) (SPHERESEGMENTS-1) / 2 -1;
+ for (int j=0; j < (SPHERESEGMENTS-1) / 2; j++) {
+
float r = sintable[j];
float r1 = sintable[j+1];
- // glBegin
- v = math::Vector3f(r, 0, costable[j]);
+/* v.assign(r, 0, costable[j]);
n = v;
n.normalize();
- //normal(n);
- //vertex(v);
- add_vertex(v, n, white);
+ tex.assign(1, (float)(SPHERESEGMENTS-1-j) / (float)(SPHERESEGMENTS-1), 0);
+ add_vertex(v, n, white, tex);
v = math::Vector3f(r1, 0, costable[j+1]);
n = v;
n.normalize();
- //normal(n);
- //vertex(v);
- add_vertex(v, n, white);
+ tex.assign(1, (float) (SPHERESEGMENTS-2-j) / (float)(SPHERESEGMENTS-1), 0 );
+ add_vertex(v, n, white, tex);
count =2;
-
- for (int i = SPHERESEGMENTS-1; i >= 0; i--) {
+*/
+ for (int i = 0; i < SPHERESEGMENTS; i++) {
v = math::Vector3f(r*costable[i], r*sintable[i], costable[j]);
n = v;
n.normalize();
- //normal(n);
- //vertex(v);
- add_vertex(v, n, white);
+ //tex.assign((float)i/(float)(SPHERESEGMENTS), (float) (j) / h, 0);
+ tex.assign((float)i/(float)(SPHERESEGMENTS-1), -costable[j]/2 + 0.5f , 0);
+ add_vertex(v, n, white, tex);
v = math::Vector3f(r1*costable[i], r1*sintable[i], costable[j+1]);
n = v;
- n.normalize();
- //normal(n);
- //vertex(v);
- add_vertex(v, n, white);
+ n.normalize();
+ tex.assign((float)i/(float)(SPHERESEGMENTS-1), -costable[j+1]/2 + 0.5f, 0);
+ add_vertex(v, n, white, tex);
count +=2;
}
- // glEnd
}
@@ -140,5 +138,24 @@ void VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, m
vertex_index += 3;
}
+void VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color, math::Vector3f const &tex) {
+ if (vertex_index + 3 >= vertex_size) {
+ con_warn << "VertexArray overflow!" << std::endl;
+ return;
+ }
+
+ for (int i = 0; i < 3; i ++) {
+ vertex_vertex[vertex_index+i] = v[i];
+ vertex_normal[vertex_index+i] = n[i];
+ vertex_texture[vertex_index+i] = tex[i];
+ }
+
+ vertex_color[vertex_index] = color.r;
+ vertex_color[vertex_index+1] = color.g;
+ vertex_color[vertex_index+2] = color.b;
+
+ vertex_index += 3;
+}
+
}
diff --git a/src/model/vertexarray.h b/src/model/vertexarray.h
index 6145659..6ff32bc 100644
--- a/src/model/vertexarray.h
+++ b/src/model/vertexarray.h
@@ -12,7 +12,7 @@
namespace model {
-const int SPHERESEGMENTS=33;
+const int SPHERESEGMENTS=65;
/// global vertex array
class VertexArray
@@ -25,7 +25,7 @@ public:
void clear();
void add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color);
-
+ void add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color, math::Vector3f const &tex);
inline float *vertex() { return vertex_vertex; }
inline float *color() { return vertex_color; }
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 4295330..f84abe7 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -58,10 +58,10 @@ void draw_sphere(math::Color const & color, float radius)
gl::color(color);
size_t index = 0;
- size_t count = (model::SPHERESEGMENTS+1)*2;
+ size_t count = (model::SPHERESEGMENTS)*2;
// draw body
- for (int j=0; j < model::SPHERESEGMENTS-1; j++) {
+ for (int j=0; j < (model::SPHERESEGMENTS-1)/2; j++) {
glDrawArrays(gl::QuadStrip, index, count);
index += count;
Stats::quads += count/2-1;
@@ -72,11 +72,23 @@ void draw_sphere(math::Color const & color, float radius)
void draw_entity_sphere(core::Entity *entity)
{
- if (entity->type() == core::Entity::Globe) {
- gl::disable(GL_LIGHT0);
+ if ((entity->type() == core::Entity::Globe) && !flag_is_set(entity->flags(), core::Entity::Bright)) {
+ gl::disable(GL_LIGHT0); // disable camera light, level light only
+
+ core::EntityGlobe *globe = (core::EntityGlobe *)entity;
+ if (globe->render_texture) {
+ Textures::bind(globe->render_texture);
+ gl::enable(GL_TEXTURE_2D);
+ }
}
+
draw_sphere(entity->color(), entity->radius());
- if (entity->type() == core::Entity::Globe) {
+
+ if ((entity->type() == core::Entity::Globe) && !flag_is_set(entity->flags(), core::Entity::Bright)) {
+ core::EntityGlobe *globe = (core::EntityGlobe *)entity;
+ if (globe->render_texture) {
+ gl::disable(GL_TEXTURE_2D);
+ }
gl::enable(GL_LIGHT0);
}
}
@@ -197,61 +209,6 @@ void draw_model_evertex(core::Entity *entity)
}
}
-/*
-void draw_model_engines(core::EntityControlable *entity)
-{
- model::Model *model = entity->model();
-
- if (model->model_engine.size() && entity->thrust()) {
- gl::color(1.0f, 0.0f ,0.0f, 1.0f);
- gl::begin(gl::Lines);
-
- for (std::list<model::Engine *>::iterator eit = model->model_engine.begin(); eit != model->model_engine.end(); eit++) {
- math::Vector3f const & v = (*eit)->location();
- gl::vertex(v);
- gl::vertex(v.x - 0.0625f*entity->thrust(), v.y, v.z);
- }
- gl::end();
- }
-
-}
-
-void draw_model_shield(core::EntityControlable *entity)
-{
- // shield rotation
- //gl::push();
- gl::rotate(angle, 0.0f, 0.0f, 1.0f );
- gl::scale(entity->model()->radius(), entity->model()->radius(), entity->model()->radius());
-
- // draw the shield
- gl::color(math::Color(0.0f, 1.0f ,0.0f));
-
- gl::begin(gl::LineLoop);
-// gl::normal(0, 0.5, 0.5);
- gl::vertex(v1);
-// gl::normal(0, -0.5, 0.5);
- gl::vertex(v0);
-// gl::normal(0, -0.5, -0.5);
- gl::vertex(v4);
-// gl::normal(0, 0.5, -0.5);
- 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::vertex(v7);
-
- gl::end();
-
- //gl::pop();
-}
-*/
/* ----- Render passes --------------------------------------------- */
@@ -277,6 +234,7 @@ void pass_prepare(float seconds)
model::Light *light = (*lit);
// load flare texture
+ // FIXME optimize
std::stringstream flarename;
flarename << "bitmaps/fx/flare" << std::setfill('0') << std::setw(2) << light->flare();
light->render_texture = Textures::load(flarename.str());
@@ -308,26 +266,39 @@ void pass_prepare(float seconds)
}
} else {
- if ((entity->type() == core::Entity::Globe) && flag_is_set(entity->flags(), core::Entity::Bright)) {
+ if (entity->type() == core::Entity::Globe) {
+ core::EntityGlobe *globe = (core::EntityGlobe *) entity;
- // bright globes set level light
- GLfloat light_position[4];
- GLfloat diffuse_light[4];
- GLfloat ambient_light[] = { 0.0f, 0.0f, 0.0f, 1.0f };
- GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
+ if (flag_is_set(globe->flags(), core::Entity::Bright)) {
- for (size_t i=0; i <3; i++) {
- light_position[i] = entity->location()[i];
- diffuse_light[i] = entity->color()[i] * 0.4;
+ // bright globes set level light
+ GLfloat light_position[4];
+ GLfloat diffuse_light[4];
+ GLfloat ambient_light[] = { 0.0f, 0.0f, 0.0f, 1.0f };
+ GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
+
+ for (size_t i=0; i <3; i++) {
+ light_position[i] = globe->location()[i];
+ diffuse_light[i] = globe->color()[i] * 0.4;
+ }
+ light_position[3] = 1.0f;
+ diffuse_light[3] = 1.0f;
+
+ glLightfv(GL_LIGHT1, GL_POSITION, light_position);
+ glLightfv(GL_LIGHT1, GL_AMBIENT, ambient_light);
+ glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_light);
+ glLightfv(GL_LIGHT1, GL_SPECULAR, specular_light);
+ gl::enable(GL_LIGHT1);
+ } else {
+
+ // load globe textures
+ // FIXME optimize
+ if (globe->texture().size()) {
+ std::stringstream texname;
+ texname << "textures/" << globe->texture();
+ globe->render_texture = Textures::load(texname.str());
+ }
}
- light_position[3] = 1.0f;
- diffuse_light[3] = 1.0f;
-
- glLightfv(GL_LIGHT1, GL_POSITION, light_position);
- glLightfv(GL_LIGHT1, GL_AMBIENT, ambient_light);
- glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_light);
- glLightfv(GL_LIGHT1, GL_SPECULAR, specular_light);
- gl::enable(GL_LIGHT1);
}
}
@@ -374,7 +345,9 @@ void draw_pass_default()
}
gl::pop();
+
} else if (r_bbox->value()) {
+
// draw bounding box if requested
model::Model *model = entity->model();
gl::color(entity->color());
@@ -456,31 +429,6 @@ void draw_pass_model_evertex()
}
}
-/* Draw model shields */
-/*
-void draw_pass_model_shields() {
-
- for (std::map<unsigned int, core::Entity *>::iterator it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) {
-
- core::Entity *entity = (*it).second;
-
- if (entity->model() && entity->state()->detailvisible()) {
-
-
- if (entity->type() == core::Entity::Controlable) {
- gl::push();
- gl::translate(entity->state()->location());
- gl::multmatrix(entity->state()->axis());
-
- draw_model_shield((core::EntityControlable *)entity);
- gl::pop();
- }
-
- }
- }
-}
-*/
-
/* draw model lights and engines */
void draw_pass_model_fx()
{
@@ -667,10 +615,12 @@ void draw(math::Axis const &axis, math::Vector3f const &eye, math::Vector3f cons
glVertexPointer(3, GL_FLOAT, 0, vertexarray->vertex());
glNormalPointer(GL_FLOAT, 0, vertexarray->normal());
glColorPointer(3, GL_FLOAT, 0, vertexarray->color());
+ glTexCoordPointer(3, GL_FLOAT, 0, vertexarray->texture());
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (r_wireframe && r_wireframe->value()) {
glPolygonMode(GL_FRONT, GL_LINE);
@@ -703,6 +653,7 @@ void draw(math::Axis const &axis, math::Vector3f const &eye, math::Vector3f cons
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
gl::disable(GL_RESCALE_NORMAL);
gl::disable(GL_LIGHTING);