Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-10 17:54:53 +0000
committerStijn Buys <ingar@osirion.org>2008-02-10 17:54:53 +0000
commit825d5a44bd312772c53fdaa8924e4009cfb320a3 (patch)
treea222232dee96bfe391eba819b1a18693db5bb3a4
parent31959bc355c471c573828bf63932850e46c4b5bc (diff)
more entity updates
-rw-r--r--src/client/draw.cc124
-rw-r--r--src/client/draw.h6
-rw-r--r--src/client/view.cc59
-rw-r--r--src/core/entity.cc7
-rw-r--r--src/core/entity.h17
-rw-r--r--src/game/game.cc27
-rw-r--r--src/game/star.cc7
-rw-r--r--src/game/star.h5
-rw-r--r--src/render/box.cc49
-rw-r--r--src/render/box.h3
-rw-r--r--src/render/tga.cc2
11 files changed, 192 insertions, 114 deletions
diff --git a/src/client/draw.cc b/src/client/draw.cc
index f907267..1e3e5b0 100644
--- a/src/client/draw.cc
+++ b/src/client/draw.cc
@@ -9,20 +9,75 @@
#include "render/sphere.h"
#include "render/box.h"
#include "client/client.h"
+#include "client/camera.h"
#include "client/draw.h"
namespace client
{
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));
-void draw_star(game::Star *star, float elapsed)
+void draw_entity_sphere(core::Entity *entity)
{
- render::gl::color(star->color);
- sphere.radius = star->radius;
+ render::gl::color(entity->base_color);
+ sphere.radius = entity->base_radius;
sphere.draw();
}
+void draw_entity_cube(core::Entity *entity)
+{
+ cube.topcolor = entity->base_color;
+ cube.bottomcolor = entity->base_color * 0.7f;
+ cube.radius = entity->base_radius;
+ cube.draw();
+}
+
+
+void draw_entity_diamond(core::Entity *entity)
+{
+ using namespace render;
+ float r = entity->base_radius;
+ gl::begin(gl::Lines);
+ gl::color(1.0f, 0.0f, 0.0f);
+ gl::vertex(r,0.0f,0.0f);
+ gl::color(entity->base_color);
+ gl::vertex(-r,0.0f,0.0f);
+
+ gl::vertex(0.0f,0.0f,r/2);
+ gl::vertex(0.0f,0.0f,-r/2);
+
+ gl::vertex(0.0f,r,0.0f);
+ gl::vertex(0.0f,-r, 0.0f);
+ gl::end();
+}
+
+// draw an entity of type core::entity::Default
+void draw_entity_default(core::Entity *entity)
+{
+ render::gl::push();
+ render::gl::translate(entity->location);
+
+ switch(entity->base_shape) {
+ case core::entity::Sphere:
+ draw_entity_sphere(entity);
+ break;
+
+ case core::entity::Diamond:
+ draw_entity_diamond(entity);
+ break;
+
+ case core::entity::Cube:
+
+ default:
+ draw_entity_cube(entity);
+ break;
+ }
+
+ render::gl::pop();
+}
+
+
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);
@@ -82,11 +137,7 @@ void draw_ship(game::Ship *ship, float elapsed)
// shield rotation
gl::rotate(angle, 0.0f, 1.0f, 0.0f );
- angle += 180.0f * elapsed;
- if( angle > 360.0f ) {
- angle -= 360.0f;
- }
-
+
// draw the shield
gl::color(Color(0.0f, 1.0f ,0.0f , 0.5f));
@@ -107,9 +158,59 @@ void draw_ship(game::Ship *ship, float elapsed)
gl::end();
}
+void draw_spacegrid()
+{
+ using namespace render::gl;
+
+ translate(camera::target);
+
+ int gridsize = 32;
+ float s = 1.0f / gridsize;
+ float y = -4.0f;
+
+ float dx = camera::target.x - floorf(camera::target.x);
+ float dz = camera::target.z - floorf(camera::target.z);
+
+ color(0,0, 1.0f);
+ begin(Lines);
+ for (int i=-gridsize; i <= gridsize; i++) {
+ color(0,0, 0, 0);
+ vertex(i-dx, y, -gridsize-dz);
+ color(0,0, (gridsize-abs(i))*s, (gridsize-abs(i))*s);
+ vertex(i-dx, y, -dz);
+ vertex(i-dx, y, -dz);
+ color(0,0, 0, 0);
+ vertex(i-dx, y, gridsize-dz);
+
+ vertex(-gridsize-dx, y, i-dz);
+ color(0,0, (gridsize-abs(i))*s, (gridsize-abs(i))*s);
+ vertex(-dx, y, i-dz);
+ vertex(-dx, y, i-dz);
+ color(0,0, 0, 0);
+ vertex(gridsize-dx, y, i-dz);
+ }
+ end();
+}
+
void draw_world(float elapsed)
{
+ angle += 180.0f * elapsed;
+ if( angle > 360.0f ) {
+ angle -= 360.0f;
+ }
+
+ // draw entities
using namespace render;
+ std::vector<core::Entity *>::iterator it;
+ for (it=core::entity::registry.begin(); it != core::entity::registry.end(); it++) {
+ switch ( (*it)->type) {
+ case core::entity::Default:
+ draw_entity_default((*it));
+ break;
+ default:
+ break;
+ }
+ }
// draw the ship
gl::push();
@@ -118,11 +219,8 @@ void draw_world(float elapsed)
draw_ship(game.ship, elapsed);
gl::pop();
- // draw the star
- gl::push();
- gl::translate(game.star->location);
- draw_star(game.star, elapsed);
- gl::pop();
+ // draw the background grid
+ draw_spacegrid();
}
}
diff --git a/src/client/draw.h b/src/client/draw.h
index d019216..a0e65eb 100644
--- a/src/client/draw.h
+++ b/src/client/draw.h
@@ -9,12 +9,6 @@
namespace client
{
-/// draw a star
-void draw_star(game::Star *star, float elapsed);
-
-/// draw a ship
-void draw_ship(game::Ship *ship, float elapsed);
-
/// draw the world
void draw_world(float elapsed);
diff --git a/src/client/view.cc b/src/client/view.cc
index 4627d26..b6ef28a 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -10,6 +10,7 @@
#include "client/video.h"
#include "client/draw.h"
#include "render/render.h"
+#include "core/core.h"
#include "game/game.h"
#include "sys/sys.h"
#include "math/mathlib.h"
@@ -61,54 +62,6 @@ void reset()
gl::disable(GL_CULL_FACE);
}
-void draw_background(float elapsed)
-{
- using namespace render::gl;
-
- // galactic axis
- begin(Lines);
- color(0.9f, 0.5f, 0.0f);
- vertex(-2,0,0);
- color(1.0f, 1.0f, 0.0f);
- vertex(2,0,0);
-
- vertex(0,0,-0.5);
- vertex(0,0,0.5);
-
- vertex(0,1.0f,0);
- vertex(0,-1, 0);
- end();
-
- translate(camera::target);
-
- int gridsize = 32;
- float s = 1.0f / gridsize;
- float y = -4.0f;
-
- float dx = camera::target.x - floorf(camera::target.x);
- float dz = camera::target.z - floorf(camera::target.z);
-
- color(0,0, 1.0f);
- begin(Lines);
- for (int i=-gridsize; i <= gridsize; i++) {
- color(0,0, 0, 0);
- vertex(i-dx, y, -gridsize-dz);
- color(0,0, (gridsize-abs(i))*s, (gridsize-abs(i))*s);
- vertex(i-dx, y, -dz);
- vertex(i-dx, y, -dz);
- color(0,0, 0, 0);
- vertex(i-dx, y, gridsize-dz);
-
- vertex(-gridsize-dx, y, i-dz);
- color(0,0, (gridsize-abs(i))*s, (gridsize-abs(i))*s);
- vertex(-dx, y, i-dz);
- vertex(-dx, y, i-dz);
- color(0,0, 0, 0);
- vertex(gridsize-dx, y, i-dz);
- }
- end();
-}
-
void draw_loader()
{
using namespace render;
@@ -161,7 +114,7 @@ void draw_status()
status << " time " << std::setfill('0') << std::setw(2) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds;
status << " fps " << std::setw(4) << fps;
- draw_text(0, 4, status);
+ draw_text(CHARWIDTH, 4, status);
// print the version number in the upper right corner
gl::color(0.0f, 1.0f, 0.0f, 1.0f);
@@ -204,14 +157,11 @@ void frame(float seconds)
gl::enable(GL_DEPTH_TEST); // enable depth buffer writing
gl::enable(GL_CULL_FACE); // enable culling
+ gl::enable(GL_BLEND); // enable alpha blending
draw_world(seconds); // draw the world
gl::disable(GL_CULL_FACE); // disable culling
- gl::enable(GL_BLEND); // enable alpha blending
-
- draw_background(seconds); // draw the spacegrid
-
gl::disable(GL_DEPTH_TEST); // disable depth buffer writing
}
@@ -234,8 +184,9 @@ void frame(float seconds)
// draw the status line
draw_status();
-
+
gl::disable(GL_BLEND);
+
}
} //namespace view
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 7f23213..3854fd0 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -18,7 +18,12 @@ Entity::Entity(unsigned int entity_flags, unsigned int entity_type)
flags = entity_flags;
type = entity_type;
+ base_shape = entity::Diamond;
+ base_color = math::Color(1.0f, 1.0f, 1.0f);
+ base_radius = 1.0f;
+
core::entity::add(this);
+
}
Entity::~Entity()
@@ -86,7 +91,7 @@ void list()
std::vector<Entity *>::iterator it;
for (it=registry.begin(); it != registry.end(); it++) {
con_print << " id " << std::setw(3) << (*it)->id
- << " type " << std::setw(2) << (*it)->type
+ << " type " << std::setw(3) << (*it)->type
<< " " << (*it)->label << std::endl;
}
con_print << registry.size() << " registered entities" << std::endl;
diff --git a/src/core/entity.h b/src/core/entity.h
index 8efb2aa..518166b 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -19,10 +19,13 @@ namespace entity
{
/// Entity flags
-enum Flags {Static=1};
+enum Flags {Static=1, Solid=2};
/// Entity type constants
-enum Type {None = 0, Dynamic = 1, Controlable = 2};
+enum Type {Default = 0, Dynamic = 1, Controlable = 2};
+
+/// Entity shaoe constants
+enum Shape {Diamond=0, Sphere=1, Cube=2};
}
@@ -31,7 +34,7 @@ class Entity
{
public:
/// create a new entity and add it to the registry
- Entity(unsigned int entity_flags = 0, unsigned int entity_type = entity::None);
+ Entity(unsigned int entity_flags = 0, unsigned int entity_type = entity::Default);
virtual ~Entity();
/// id of the entity
@@ -44,10 +47,13 @@ public:
unsigned int type;
/// base shape
- unsigned int base_shape;
+ entity::Shape base_shape;
/// base color
math::Color base_color;
+
+ /// base radius
+ float base_radius;
/// label
std::string label;
@@ -84,9 +90,6 @@ public:
namespace entity
{
-/// base entity shapes
-enum Shapes {Diamond=0, Cube=1, Sphere=2};
-
/// the entity registry
extern std::vector<Entity*> registry;
diff --git a/src/game/game.cc b/src/game/game.cc
index 8a50e33..197700f 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -21,6 +21,7 @@ namespace game
bool Game::init()
{
using math::Vector3f;
+ using math::Color;
//using filesystem::IniFile;
con_print << "Initializing game..." << std::endl;
@@ -101,9 +102,35 @@ bool Game::init()
star->location = Vector3f(256.0f, 0.0f, 256.0f);
star->label = "star: Sabishi Hoshi";
+
ship = new Ship();
ship->location = Vector3f(0,0,0);
ship->label = "ship: Micron Vector";
+
+ core::Entity *cube = new core::Entity(core::entity::Solid & core::entity::Static);
+ cube->base_shape = core::entity::Cube;
+ cube->base_color = Color(0.0f, 0.8f, 0.0f);
+ cube->location = Vector3f(24.0f, 0.0f, -24.0f);
+ cube->label ="cube: Borg cube green";
+
+ cube = new core::Entity(core::entity::Solid & core::entity::Static);
+ cube->base_shape = core::entity::Cube;
+ cube->base_color = Color(1.0f, 0.0f, 0.0f);
+ cube->location = Vector3f(16.0f, 0.0f, -16.0f);
+ cube->label ="cube: Borg cube red";
+
+ core::Entity *sphere = new core::Entity(core::entity::Solid & core::entity::Static);
+ sphere->base_shape = core::entity::Sphere;
+ sphere->base_color = Color(0.8f, 0.8f, 0.0f);
+ sphere->location = Vector3f(0.0f, 0.0f, -32.0f);
+ sphere->label ="sphere: The Sphere";
+
+ core::Entity *axis = new core::Entity(core::entity::Static);
+ axis->base_shape = core::entity::Diamond;
+ axis->base_color = Color(1.0f, 1.0f, 0.0f);
+ axis->location = Vector3f(0, 0, 0);
+ axis->label = "axis: Origin";
+
return true;
}
diff --git a/src/game/star.cc b/src/game/star.cc
index 4ef22de..5fed82a 100644
--- a/src/game/star.cc
+++ b/src/game/star.cc
@@ -10,10 +10,11 @@
namespace game {
-Star::Star() : core::Entity(0, star_enttype),
- color(1,1,1,1)
+Star::Star() : core::Entity(core::entity::Static & core::entity::Solid)
{
- radius = 48;
+ base_shape = core::entity::Sphere; // a star is a sphere
+ base_color = math::Color(1,1,1,1); // white
+ base_radius = 48; // 48 game units
}
Star::~Star()
diff --git a/src/game/star.h b/src/game/star.h
index 7a087d0..e953f3c 100644
--- a/src/game/star.h
+++ b/src/game/star.h
@@ -21,11 +21,6 @@ class Star : public core::Entity {
public:
Star();
~Star();
-
- math::Color color;
- float radius;
-
- std::string name;
};
}
diff --git a/src/render/box.cc b/src/render/box.cc
index 8819a40..79f62f7 100644
--- a/src/render/box.cc
+++ b/src/render/box.cc
@@ -17,6 +17,7 @@ Box::Box(Vector3f const & tl, Vector3f const &br) :
{
topcolor = Color::White();
bottomcolor= Color::White() * 0.7f;
+ radius = 1.0f;
}
Box::Box(const Box & other)
@@ -52,47 +53,47 @@ void Box::draw()
// top
color(topcolor);
- vertex(v2);
- vertex(v1);
- vertex(v5);
- vertex(v6);
+ vertex(radius*v2);
+ vertex(radius*v1);
+ vertex(radius*v5);
+ vertex(radius*v6);
// sides
color(bottomcolor);
- vertex(v0);
+ vertex(radius*v0);
color(topcolor);
- vertex(v1);
- vertex(v2);
+ vertex(radius*v1);
+ vertex(radius*v2);
color(bottomcolor);
- vertex(v3);
+ vertex(radius*v3);
- vertex(v3);
+ vertex(radius*v3);
color(topcolor);
- vertex(v2);
- vertex(v6);
+ vertex(radius*v2);
+ vertex(radius*v6);
color(bottomcolor);
- vertex(v7);
+ vertex(radius*v7);
- vertex(v4);
+ vertex(radius*v4);
color(topcolor);
- vertex(v5);
- vertex(v1);
+ vertex(radius*v5);
+ vertex(radius*v1);
color(bottomcolor);
- vertex(v0);
+ vertex(radius*v0);
- vertex(v7);
+ vertex(radius*v7);
color(topcolor);
- vertex(v6);
- vertex(v5);
+ vertex(radius*v6);
+ vertex(radius*v5);
color(bottomcolor);
- vertex(v4);
+ vertex(radius*v4);
// bottom
color(bottomcolor);
- vertex(v4);
- vertex(v0);
- vertex(v3);
- vertex(v7);
+ 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
index 9552b78..ceab8ec 100644
--- a/src/render/box.h
+++ b/src/render/box.h
@@ -36,6 +36,9 @@ public:
math::Color topcolor;
/// bottom color
math::Color bottomcolor;
+
+ /// size factor
+ float radius;
};
}
diff --git a/src/render/tga.cc b/src/render/tga.cc
index 18236fa..5802edf 100644
--- a/src/render/tga.cc
+++ b/src/render/tga.cc
@@ -168,7 +168,7 @@ TGA::image *TGA::load(const char *filename)
}
}
}
- delete[] pColors;
+ delete pColors;
}
filesystem::close(f);