Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--osirion.kdevelop.pcsbin513360 -> 515566 bytes
-rw-r--r--osirion.kdevses12
-rw-r--r--src/client/view.cc2
-rw-r--r--src/core/entity.h2
-rw-r--r--src/core/model.cc24
-rw-r--r--src/core/model.h15
-rw-r--r--src/game/ship.cc2
-rw-r--r--src/game/star.cc2
-rw-r--r--src/math/vector3f.cc23
-rw-r--r--src/math/vector3f.h6
-rw-r--r--src/render/draw.cc90
-rw-r--r--src/render/render.cc4
-rw-r--r--src/render/render.h3
13 files changed, 110 insertions, 75 deletions
diff --git a/osirion.kdevelop.pcs b/osirion.kdevelop.pcs
index 17741ff..6961206 100644
--- a/osirion.kdevelop.pcs
+++ b/osirion.kdevelop.pcs
Binary files differ
diff --git a/osirion.kdevses b/osirion.kdevses
index 9262b0a..b1bd6ba 100644
--- a/osirion.kdevses
+++ b/osirion.kdevses
@@ -1,16 +1,10 @@
<?xml version = '1.0' encoding = 'UTF-8'?>
<!DOCTYPE KDevPrjSession>
<KDevPrjSession>
- <DocsAndViews NumberOfDocuments="3" >
- <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/player.h" >
- <View0 Encoding="" line="0" Type="Source" />
+ <DocsAndViews NumberOfDocuments="1" >
+ <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/input.cc" >
+ <View0 Encoding="" line="78" Type="Source" />
</Doc0>
- <Doc1 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/player.cc" >
- <View0 Encoding="" line="130" Type="Source" />
- </Doc1>
- <Doc2 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/entity.h" >
- <View0 Encoding="" line="11" Type="Source" />
- </Doc2>
</DocsAndViews>
<pluginList>
<kdevdebugger>
diff --git a/src/client/view.cc b/src/client/view.cc
index db7f3a3..466723f 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -70,7 +70,7 @@ void reset()
glMateriali(GL_FRONT, GL_SHININESS, 128); // shininess 1-128
gl::disable(GL_LIGHTING);
- gl::disable(GL_LIGHT0);
+ gl::enable(GL_LIGHT0);
gl::disable(GL_COLOR_MATERIAL);
// culling
diff --git a/src/core/entity.h b/src/core/entity.h
index 1f47640..323eec7 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -28,7 +28,7 @@ class Entity
{
public:
/// Entity flags
- enum Flags {Static=1, Solid=2};
+ enum Flags {Static=1, Solid=2, Bright=4};
/// Entity type constants
enum Type {Default=0, Dynamic=1, Controlable=2};
diff --git a/src/core/model.cc b/src/core/model.cc
index da179e5..88a1040 100644
--- a/src/core/model.cc
+++ b/src/core/model.cc
@@ -247,6 +247,11 @@ Model::Model(std::string const & name) :
ifs.close();
if (model_face.size()) {
+ if (model_maxbbox.lengthsquared() > model_minbbox.lengthsquared()) {
+ model_radius = model_maxbbox.length();
+ } else {
+ model_radius = model_minbbox.length();
+ }
model_valid = true;
}
con_debug << " maps/" << name << ".map " << model_face.size() << " polygons\n";
@@ -502,18 +507,17 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
Face *mf = new Face(face->normal()*-1, color);
for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
mf->add_vertex(*(*it) * model_scale);
- }
- add_face(mf);
- /*
- mf->add_vertex(*(*vn) * model_scale);
- mf->add_vertex(*(*v0) * model_scale);
- mf->add_vertex(*(*vn1) * model_scale);
- add_face(mf);
+
+ // bounding box
+ for (int i=0; i < 3; i++) {
+ if (model_maxbbox[i] < (*(*it))[i] * model_scale)
+ model_maxbbox[i] = (*(*it))[i] * model_scale;
- vl.pop_back();
+ if (model_minbbox[i] > (*(*it))[i] * model_scale)
+ model_minbbox[i] = (*(*it))[i] * model_scale;
+ }
}
- */
-
+ add_face(mf);
if (color) delete color;
} else {
con_debug << "Unresolved face!\n";
diff --git a/src/core/model.h b/src/core/model.h
index 013edcc..00c8a48 100644
--- a/src/core/model.h
+++ b/src/core/model.h
@@ -88,7 +88,16 @@ public:
{
return model_name;
}
+
+ /// maximum values of the bounding box
+ inline math::Vector3f const & maxbbox() const { return model_maxbbox; }
+ /// minimum values of the bounding box
+ inline math::Vector3f const & minbbox() const { return model_minbbox; }
+
+ /// radius
+ inline float radius() const { return model_radius; }
+
/// the Model registry
static std::map<std::string, Model*> registry;
@@ -114,7 +123,7 @@ public:
/// list of Lights
std::list<Light *> model_light;
-
+
private:
void make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes);
void add_engine(Engine *engine);
@@ -123,8 +132,12 @@ private:
std::string model_name;
+ float model_radius;
float model_scale;
bool model_valid;
+
+ math::Vector3f model_maxbbox;
+ math::Vector3f model_minbbox;
};
}
diff --git a/src/game/ship.cc b/src/game/ship.cc
index 1dd37bc..b82b7a8 100644
--- a/src/game/ship.cc
+++ b/src/game/ship.cc
@@ -23,6 +23,8 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) :
entity_modelname = "ships/" + shipmodel->modelname();
entity_name = shipmodel->name() + ": <" + owner->name() + ">";
ship_shipmodel = shipmodel;
+
+ entity_moduletypeid = ship_enttype;
}
Ship::~Ship()
diff --git a/src/game/star.cc b/src/game/star.cc
index 0bb8fb5..1d154fe 100644
--- a/src/game/star.cc
+++ b/src/game/star.cc
@@ -10,7 +10,7 @@
namespace game {
-Star::Star() : core::Entity(core::Entity::Static & core::Entity::Solid)
+Star::Star() : core::Entity(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
diff --git a/src/math/vector3f.cc b/src/math/vector3f.cc
index 3f1f4ac..a9e7e00 100644
--- a/src/math/vector3f.cc
+++ b/src/math/vector3f.cc
@@ -116,7 +116,7 @@ bool Vector3f::operator==(const Vector3f& other) const
float Vector3f::lengthsquared() const
{
- double r = 0;
+ float r = 0;
for (int i=0; i < 3; i++)
r += coord[i]*coord[i];
return ((float) r);
@@ -124,11 +124,11 @@ float Vector3f::lengthsquared() const
float Vector3f::length() const
{
- double r = 0;
+ float r = 0;
for (int i=0; i < 3; i++)
r += coord[i]*coord[i];
- return ((float) sqrt(r));
+ return (sqrtf(r));
}
void Vector3f::normalize()
@@ -171,4 +171,21 @@ float dotproduct(const Vector3f& first, const Vector3f& second)
return (r);
}
+float distance(const Vector3f& first, const Vector3f& second)
+{
+ float r = 0;
+ for (int i=0; i < 3; i++)
+ r += (first[i]-second[i])*(first[i]-second[i]);
+
+ return (sqrtf(r));
+}
+
+float distancesquared(const Vector3f& first, const Vector3f& second)
+{
+ float r = 0;
+ for (int i=0; i < 3; i++)
+ r += (first[i]-second[i])*(first[i]-second[i]);
+ return (r);
+}
+
} // namespace math
diff --git a/src/math/vector3f.h b/src/math/vector3f.h
index 5d1fa41..20e47f2 100644
--- a/src/math/vector3f.h
+++ b/src/math/vector3f.h
@@ -148,6 +148,12 @@ const Vector3f crossproduct(Vector3f const & first, Vector3f const & second);
/// vector dot product
float dotproduct(const Vector3f& first, const Vector3f& second);
+/// distance between two vectors
+float distance(const Vector3f& first, const Vector3f& second);
+
+/// distance between two vectors squared
+float distancesquared(const Vector3f& first, const Vector3f& second);
+
} // namespace math
#endif // __INCLUDED_MATH_VECTOR3F_H__
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 1d27631..9e1e5ea 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -6,13 +6,14 @@
#include "core/core.h"
#include "core/model.h"
+#include "render/render.h"
#include "render/draw.h"
#include "render/sphere.h"
namespace render
{
-render::Sphere sphere(1);
+Sphere sphere(1);
math::Vector3f v0(1, -1, 1);
math::Vector3f v1(1, 1, 1);
@@ -24,6 +25,8 @@ math::Vector3f v5(1, 1, -1);
math::Vector3f v6(-1, 1, -1);
math::Vector3f v7(-1, -1, -1);
+const float drawdistance = 128.0f;
+math::Vector3f camera_target;
float angle = 0;
void draw_model(core::Model *model, core::Entity *entity)
@@ -45,6 +48,15 @@ void draw_model(core::Model *model, core::Entity *entity)
}
gl::end();
}
+
+ if (r_drawradius && r_drawradius->value()) {
+ sphere.sphere_color = entity->color();
+ sphere.sphere_color.a = 0.25f;
+ sphere.radius = model->radius();
+ gl::enable(GL_BLEND); // enable alpha blending again
+ sphere.draw();
+ gl::disable(GL_BLEND);
+ }
}
void draw_model_engines(core::Model *model, core::EntityControlable *entity)
@@ -63,31 +75,23 @@ void draw_model_engines(core::Model *model, core::EntityControlable *entity)
}
-void draw_model_lights(math::Vector3f const & eye, math::Vector3f const & target)
+void draw_model_lights(core::Model *model, core::Entity *entity)
{
- glPointSize(10);
- gl::begin(gl::Points);
-
- std::map<unsigned int, core::Entity *>::iterator it;
- for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) {
- core::Model *model = 0;
- if ((*it).second->modelname().size())
- model = core::Model::get((*it).second->modelname());
-
- if (model) {
- for (std::list<core::Light *>::iterator lit = model->model_light.begin(); lit != model->model_light.end(); lit++) {
- math::Vector3f location = (*it).second->location() + (*lit)->location();
- math::Vector3f d = location-eye;
- if ((d.lengthsquared() < 16*16) && (dotproduct(d, eye-target) < 0)) {
- gl::color((*lit)->color());
- gl::vertex(location);
- }
- }
+ if (model->model_light.size()) {
+ gl::disable(GL_LIGHTING);
+ glPointSize(10);
+ gl::begin(gl::Points);
+
+ for (std::list<core::Light *>::iterator lit = model->model_light.begin(); lit != model->model_light.end(); lit++) {
+ math::Vector3f location = (*lit)->location();
+ gl::color((*lit)->color());
+ gl::vertex(location);
}
+
+ gl::end();
+ glPointSize(1);
+ gl::enable(GL_LIGHTING);
}
-
- gl::end();
- glPointSize(1);
}
void draw_entity_sphere(core::Entity *entity)
@@ -173,8 +177,13 @@ void draw_entity_default(core::Entity *entity)
using namespace render;
core::Model *model = 0;
- if (entity->modelname().size())
+ if (entity->modelname().size()) {
model = core::Model::get(entity->modelname());
+ }
+
+ if (model && math::distancesquared(camera_target, entity->location()) > drawdistance*drawdistance*model->radius())
+ return;
+
gl::push();
gl::translate(entity->location());
@@ -182,9 +191,10 @@ void draw_entity_default(core::Entity *entity)
if (model) {
draw_model(model, entity);
+ //draw_model_lights(model, entity);
} else {
- //gl::disable(GL_LIGHTING);
- //gl::disable(GL_LIGHT0);
+ if ((entity->flags() & core::Entity::Bright) == core::Entity::Bright)
+ gl::disable(GL_LIGHTING);
switch(entity->shape()) {
case core::Entity::Sphere:
@@ -204,8 +214,8 @@ void draw_entity_default(core::Entity *entity)
break;
}
- //gl::enable(GL_LIGHTING);
- //gl::enable(GL_LIGHT0); // disable camera light
+ if ((entity->flags() & core::Entity::Bright) == core::Entity::Bright)
+ gl::enable(GL_LIGHTING);
}
gl::pop();
@@ -222,9 +232,10 @@ void draw_entity_controlable(core::EntityControlable *entity)
gl::translate(entity->location());
gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f );
- if (model) {
+ if (model ) {
draw_model(model, entity);
draw_model_engines(model, entity);
+ //draw_model_lights(model, entity);
}
// shield rotation
@@ -301,6 +312,8 @@ void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds
angle -= 360.0f;
}
+ camera_target = target;
+
// draw entities
using namespace render;
@@ -308,7 +321,6 @@ void draw(math::Vector3f const &eye, 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);
gl::disable(GL_BLEND); // disbable alpha blending for world polys
@@ -326,29 +338,11 @@ void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds
}
}
- gl::disable(GL_LIGHT0); // disable camera light
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
- /*
- // DEBUG target lines
- gl::push();
- gl::color(0,1, 0, .7);
- //gl::translate(target*-1);
- gl::begin(gl::Lines);
- for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) {
- gl::vertex(eye);
- gl::vertex((*it).second->location());
- }
- gl::end();
- gl::pop();
-
- draw_model_lights(eye, target); // second pass - draw lights
- */
-
draw_spacegrid(target); // draw the blue spacegrid
gl::disable(GL_DEPTH_TEST); // disable depth buffer writing
diff --git a/src/render/render.cc b/src/render/render.cc
index 76f2373..b5afdf0 100644
--- a/src/render/render.cc
+++ b/src/render/render.cc
@@ -13,6 +13,8 @@ namespace render {
GLuint textures[32];
+core::Cvar *r_drawradius = 0;
+
void init()
{
con_print << "Initializing renderer..." << std::endl;
@@ -32,7 +34,7 @@ void init()
core::application()->shutdown();
}
-
+ r_drawradius = core::Cvar::get("r_drawradius", "0", core::Cvar::Archive);
}
void shutdown()
diff --git a/src/render/render.h b/src/render/render.h
index c27b740..7d26a3d 100644
--- a/src/render/render.h
+++ b/src/render/render.h
@@ -8,6 +8,7 @@
#define __INCLUDED_RENDER_H__
#include "GL/gl.h"
+#include "core/cvar.h"
namespace render {
@@ -21,6 +22,8 @@ namespace render {
void draw(float elapsed);
extern GLuint textures[32];
+
+ extern core::Cvar *r_drawradius;
}
#include "render/draw.h"