Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.in4
-rw-r--r--osirion.kdevelop10
-rw-r--r--osirion.kdevelop.pcsbin597984 -> 603120 bytes
-rw-r--r--osirion.kdevses21
-rw-r--r--src/Makefile.am33
-rw-r--r--src/core/Makefile.am8
-rw-r--r--src/core/entity.h13
-rw-r--r--src/core/gameinterface.cc8
-rw-r--r--src/model/Makefile.am9
-rw-r--r--src/model/light.cc27
-rw-r--r--src/model/light.h63
-rw-r--r--src/model/model.cc (renamed from src/core/model.cc)154
-rw-r--r--src/model/model.h (renamed from src/core/model.h)103
-rw-r--r--src/model/vertexarray.cc144
-rw-r--r--src/model/vertexarray.h57
-rw-r--r--src/render/draw.cc18
-rw-r--r--src/render/render.cc8
-rw-r--r--src/render/render.h4
18 files changed, 368 insertions, 316 deletions
diff --git a/configure.in b/configure.in
index 6b97f21..2abddaa 100644
--- a/configure.in
+++ b/configure.in
@@ -185,8 +185,8 @@ dnl ---------------------------------------------------------------
dnl Write makefiles and config.h
AC_OUTPUT(Makefile src/Makefile src/client/Makefile src/core/Makefile \
- src/filesystem/Makefile src/game/Makefile src/math/Makefile src/render/Makefile src/server/Makefile \
- src/sys/Makefile)
+ src/filesystem/Makefile src/game/Makefile src/math/Makefile src/model/Makefile src/render/Makefile \
+ src/server/Makefile src/sys/Makefile)
dnl ---------------------------------------------------------------
dnl Configuration summary
diff --git a/osirion.kdevelop b/osirion.kdevelop
index 58a8bfc..48a4540 100644
--- a/osirion.kdevelop
+++ b/osirion.kdevelop
@@ -21,7 +21,7 @@
</general>
<kdevautoproject>
<general>
- <activetarget>src/client/libclient.la</activetarget>
+ <activetarget>src/model/libmodel.la</activetarget>
<useconfiguration>debug</useconfiguration>
</general>
<run>
@@ -29,12 +29,12 @@
<terminal>true</terminal>
<directoryradio>executable</directoryradio>
<runarguments>
- <osirion/>
- <osiriond/>
+ <osirion></osirion>
+ <osiriond></osiriond>
</runarguments>
<debugarguments>
- <osiriond/>
- <osirion/>
+ <osiriond></osiriond>
+ <osirion></osirion>
</debugarguments>
<cwd>
<osiriond>/home/ingar/projects/osirion/osirion-work/debug/src/</osiriond>
diff --git a/osirion.kdevelop.pcs b/osirion.kdevelop.pcs
index 6b67d1f..7ca5240 100644
--- a/osirion.kdevelop.pcs
+++ b/osirion.kdevelop.pcs
Binary files differ
diff --git a/osirion.kdevses b/osirion.kdevses
index db2bc64..6985dbb 100644
--- a/osirion.kdevses
+++ b/osirion.kdevses
@@ -1,25 +1,10 @@
<?xml version = '1.0' encoding = 'UTF-8'?>
<!DOCTYPE KDevPrjSession>
<KDevPrjSession>
- <DocsAndViews NumberOfDocuments="6" >
- <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/model.cc" >
- <View0 Encoding="" line="316" Type="Source" />
+ <DocsAndViews NumberOfDocuments="1" >
+ <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/draw.cc" >
+ <View0 Encoding="" line="418" Type="Source" />
</Doc0>
- <Doc1 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/model.h" >
- <View0 Encoding="" line="150" Type="Source" />
- </Doc1>
- <Doc2 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/draw.cc" >
- <View0 Encoding="" line="275" Type="Source" />
- </Doc2>
- <Doc3 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/view.cc" >
- <View0 Encoding="" line="209" Type="Source" />
- </Doc3>
- <Doc4 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/textures.h" >
- <View0 Encoding="" line="39" Type="Source" />
- </Doc4>
- <Doc5 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/textures.cc" >
- <View0 Encoding="" line="127" Type="Source" />
- </Doc5>
</DocsAndViews>
<pluginList>
<kdevdebugger>
diff --git a/src/Makefile.am b/src/Makefile.am
index 74a31e3..19ad3be 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,33 +4,34 @@ SUFFIXES = .rc
.rc.o:
windres $< -o $@
-SUBDIRS = math sys filesystem core server render client game
+SUBDIRS = sys math filesystem model core render server client game
noinst_HEADERS = config.h
bin_PROGRAMS = osiriond osirion
# dedicated server
osiriond_SOURCES = osiriond.cc
EXTRA_osiriond_SOURCES = osiriond-res.rc
-osiriond_DEPENDENCIES = $(ICON_SERVER) $(top_builddir)/src/game/libgame.la \
- $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/math/libmath.la \
- $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/core/libcore.la \
- $(top_builddir)/src/server/libserver.la
+osiriond_DEPENDENCIES = $(ICON_SERVER) $(top_builddir)/src/core/libcore.la \
+ $(top_builddir)/src/model/libmodel.la $(top_builddir)/src/filesystem/libfilesystem.la \
+ $(top_builddir)/src/game/libgame.la $(top_builddir)/src/math/libmath.la \
+ $(top_builddir)/src/server/libserver.la $(top_builddir)/src/sys/libsys.la
osiriond_LDADD = $(top_builddir)/src/game/libgame.la \
- $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/math/libmath.la \
- $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/core/libcore.la \
- $(top_builddir)/src/server/libserver.la $(HOST_LIBS) $(ICON_SERVER)
+ $(top_builddir)/src/core/libcore.la $(top_builddir)/src/filesystem/libfilesystem.la \
+ $(top_builddir)/src/model/libmodel.la $(top_builddir)/src/math/libmath.la \
+ $(top_builddir)/src/server/libserver.la $(top_builddir)/src/sys/libsys.la $(HOST_LIBS) $(ICON_SERVER)
# client
osirion_SOURCES = osirion.cc
EXTRA_osirion_SOURCES = osirion-res.rc
-osirion_DEPENDENCIES = $(ICON_CLIENT) $(top_builddir)/src/game/libgame.la \
- $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/math/libmath.la \
- $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/core/libcore.la \
- $(top_builddir)/src/render/librender.la $(top_builddir)/src/client/libclient.la
+osirion_DEPENDENCIES = $(ICON_CLIENT) $(top_builddir)/src/client/libclient.la \
+ $(top_builddir)/src/core/libcore.la $(top_builddir)/src/filesystem/libfilesystem.la \
+ $(top_builddir)/src/game/libgame.la $(top_builddir)/src/math/libmath.la $(ICON_CLIENT) \
+ $(top_builddir)/src/model/libmodel.la $(top_builddir)/src/render/librender.la \
+ $(top_builddir)/src/sys/libsys.la
osirion_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS) $(GLUT_CFLAGS)
osirion_LDADD = $(top_builddir)/src/game/libgame.la \
- $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/math/libmath.la \
- $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/core/libcore.la \
- $(top_builddir)/src/render/librender.la $(top_builddir)/src/client/libclient.la $(GL_LIBS) $(HOST_LIBS) \
- $(ICON_CLIENT)
+ $(top_builddir)/src/client/libclient.la $(top_builddir)/src/core/libcore.la \
+ $(top_builddir)/src/model/libmodel.la $(top_builddir)/src/filesystem/libfilesystem.la \
+ $(top_builddir)/src/math/libmath.la $(top_builddir)/src/render/librender.la \
+ $(top_builddir)/src/sys/libsys.la $(GL_LIBS) $(HOST_LIBS) $(ICON_CLIENT)
osirion_LDFLAGS = $(LIBSDL_LIBS)
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index e9091f2..33b4c44 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -2,11 +2,11 @@ METASOURCES = AUTO
INCLUDES = -I$(top_srcdir)/src
libcore_la_SOURCES = application.cc commandbuffer.cc core.cc cvar.cc entity.cc \
- func.cc gameconnection.cc gameinterface.cc gameserver.cc model.cc module.cc \
- netclient.cc netconnection.cc netserver.cc player.cc
+ func.cc gameconnection.cc gameinterface.cc gameserver.cc module.cc netclient.cc \
+ netconnection.cc netserver.cc player.cc
libcore_la_LDFLAGS = -avoid-version -no-undefined
-libcore_la_LIBADD = $(top_builddir)/src/math/libmath.la \
- $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/filesystem/libfilesystem.la
+libcore_la_LIBADD = $(top_builddir)/src/filesystem/libfilesystem.la \
+ $(top_builddir)/src/math/libmath.la $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/model/libmodel.la
noinst_LTLIBRARIES = libcore.la
noinst_HEADERS = application.h commandbuffer.h core.h cvar.h entity.h func.h \
diff --git a/src/core/entity.h b/src/core/entity.h
index 7e6493a..ba86c53 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -7,16 +7,19 @@
#ifndef __INCLUDED_CORE_ENTITY_H__
#define __INCLUDED_CORE_ENTITY_H__
+#include "model/model.h"
+#include "math/axis.h"
+#include "math/mathlib.h"
+
namespace core
{
+
class Entity;
class EntityControlable;
+
}
-#include "core/model.h"
#include "core/player.h"
-#include "math/axis.h"
-#include "math/mathlib.h"
#include <iostream>
#include <string>
@@ -77,7 +80,7 @@ public:
inline std::string const & modelname() { return entity_modelname; }
/// pointer to the model, is used client-side
- inline Model * model() { return entity_model; }
+ inline model::Model * model() { return entity_model; }
/// dirty flag
inline bool dirty() const { return entity_dirty; }
@@ -145,7 +148,7 @@ public:
float entity_radius;
std::string entity_name;
std::string entity_modelname;
- Model *entity_model;
+ model::Model *entity_model;
Shape entity_shape;
math::Color entity_color;
unsigned int entity_moduletypeid;
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index a739eb2..5789592 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -7,20 +7,20 @@
#include <stdlib.h>
#include <iostream>
-#include "sys/sys.h"
#include "core/application.h"
#include "core/cvar.h"
#include "core/func.h"
#include "core/gameinterface.h"
-#include "core/model.h"
#include "core/player.h"
+#include "model/model.h"
+#include "sys/sys.h"
namespace core
{
void func_list_model(std::string const &args)
{
- Model::list();
+ model::Model::list();
}
Player GameInterface::game_localplayer;
@@ -90,7 +90,7 @@ void GameInterface::clear()
}
// remove all models
- Model::clear();
+ model::Model::clear();
}
diff --git a/src/model/Makefile.am b/src/model/Makefile.am
new file mode 100644
index 0000000..1490bfc
--- /dev/null
+++ b/src/model/Makefile.am
@@ -0,0 +1,9 @@
+METASOURCES = AUTO
+
+libmodel_la_SOURCES = light.cc model.cc vertexarray.cc
+libmodel_la_LDFLAGS = -avoid-version -no-undefined -lm
+
+noinst_LTLIBRARIES = libmodel.la
+noinst_HEADERS = light.h model.h vertexarray.h
+
+INCLUDES = -I$(top_srcdir)/src
diff --git a/src/model/light.cc b/src/model/light.cc
new file mode 100644
index 0000000..83a0cb8
--- /dev/null
+++ b/src/model/light.cc
@@ -0,0 +1,27 @@
+/*
+ model/light.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "model/light.h"
+
+namespace model {
+
+Light::Light(math::Vector3f const & location, math::Color const & color, bool strobe) :
+ light_location(location),
+ light_color(color)
+{
+ light_strobe = strobe;
+ light_radius = 1.0f;
+ light_frequency = 1.0f;
+ light_offset = 0.0f;
+ light_time = 0.5f;
+ light_flare = 0;
+ render_texture = 0;
+}
+
+Light::~Light()
+{}
+
+}
diff --git a/src/model/light.h b/src/model/light.h
new file mode 100644
index 0000000..e202d21
--- /dev/null
+++ b/src/model/light.h
@@ -0,0 +1,63 @@
+/*
+ model/light.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_MODEL_LIGHT_H__
+#define __INCLUDED_MODEL_LIGHT_H__
+
+#include "math/vector3f.h"
+#include "math/color.h"
+
+namespace model {
+
+/// an exterior light
+class Light
+{
+public:
+ Light(math::Vector3f const & location, math::Color const & color, bool strobe=false);
+ ~Light();
+
+ inline math::Vector3f const & location() const { return light_location; }
+
+ inline math::Color const & color() const { return light_color; };
+
+ /// true if this is a strobe light
+ inline bool strobe() const { return light_strobe; }
+
+ /// size if the light, default is 1.0f
+ inline float radius() const { return light_radius; }
+
+ /// strobe time offset, in seconds
+ inline float offset() const { return light_offset; }
+
+ /// frequency in strobes per second
+ inline float frequency() const { return light_frequency; }
+
+ /// fraction a strobe light will be on, default is 0.5f
+ inline float time() const { return light_time; }
+
+ /// flare texture number
+ inline size_t flare() const { return light_flare; }
+
+ /// render texture number
+ inline size_t texture() const { return render_texture; }
+
+ math::Vector3f light_location;
+ math::Color light_color;
+ bool light_strobe;
+ float light_radius;
+ float light_frequency;
+ float light_offset;
+ float light_time;
+
+ size_t light_flare;
+
+ size_t render_texture;
+};
+
+}
+
+#endif // __INCLUDED_MODEL_LIGHT_H__
+
diff --git a/src/core/model.cc b/src/model/model.cc
index c6f5dde..b3c8b03 100644
--- a/src/core/model.cc
+++ b/src/model/model.cc
@@ -12,148 +12,15 @@
#include <vector>
#include <list>
-#include "core/cvar.h"
-#include "core/model.h"
+#include "model/model.h"
#include "filesystem/filesystem.h"
-namespace core
+namespace model
{
const float MAX_BOUNDS = 16384;
const float delta = 10e-10;
-/* ---------- core::VertexArray ------------------------------------ */
-
-VertexArray *VertexArray::vertex_instance = 0 ;
-
-VertexArray::VertexArray(size_t size)
-{
- vertex_instance = this;
- vertex_size = size * 1024*1024; // megabytes
- vertex_size = vertex_size / sizeof(float); // sizeof float
- vertex_size = vertex_size / 4; // 4 arrays
-
- vertex_vertex = (float *) malloc(vertex_size * sizeof(float));
- vertex_color = (float *) malloc(vertex_size * sizeof(float));
- vertex_normal = (float *) malloc(vertex_size * sizeof(float));
- vertex_texture = (float *) malloc(vertex_size * sizeof(float));
-
- con_print << "Initializing vertex array..." << std::endl;
- con_debug << " " << size << " Mb allocated" << std::endl;
-
- clear();
-}
-
-VertexArray::~VertexArray()
-{
- free(vertex_vertex);
- free(vertex_normal);
- free(vertex_color);
- free(vertex_texture);
-
- vertex_instance = 0 ;
-}
-
-void VertexArray::clear()
-{
- vertex_index = 0;
-
- memset(vertex_vertex, 0, sizeof(vertex_vertex));
- memset(vertex_color, 0, sizeof(vertex_color));
- memset(vertex_normal, 0, sizeof(vertex_normal));
- memset(vertex_texture, 0, sizeof(vertex_normal));
-
- add_sphere();
-}
-
-void VertexArray::add_sphere()
-{
- // load sphere vertices into the VertexArray
-
- // build sin/cos table
- float *sintable;
- float *costable;
-
- sintable = new float[SPHERESEGMENTS];
- costable = new float[SPHERESEGMENTS];
- float d = 2 * M_PI / (SPHERESEGMENTS-1);
-
- for (int i=0; i < SPHERESEGMENTS; i++) {
- sintable[i] = sin( d * (float) i );
- costable[i] = cos ( d * (float) i );
- }
-
- // draw body
- math::Color white(1.0f, 1.0f, 1.0f);
- math::Vector3f v;
- math::Vector3f n;
-
- int count;
-
- for (int j=0; j < SPHERESEGMENTS-1; j++) {
- float r = sintable[j];
- float r1 = sintable[j+1];
-
- // glBegin
- v = math::Vector3f(r, 0, costable[j]);
- n = v;
- n.normalize();
- //normal(n);
- //vertex(v);
- add_vertex(v, n, white);
-
- v = math::Vector3f(r1, 0, costable[j+1]);
- n = v;
- n.normalize();
- //normal(n);
- //vertex(v);
- add_vertex(v, n, white);
-
- count =2;
-
- for (int i = SPHERESEGMENTS-1; i >= 0; 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);
-
- 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);
- count +=2;
- }
- // glEnd
-
- }
-
- delete[] sintable;
- delete[] costable;
-}
-
-void VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color) {
- 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_color[vertex_index] = color.r;
- vertex_color[vertex_index+1] = color.g;
- vertex_color[vertex_index+2] = color.b;
-
- vertex_index += 3;
-}
-
-
/* ---------- core::Triangle --------------------------------------- */
Triangle::Triangle(math::Vector3f const &v0, math::Vector3f const &v1, math::Vector3f const &v2, math::Vector3f const &n, math::Color *color, bool detail) :
triangle_v0(v0),
@@ -174,23 +41,6 @@ Triangle::~Triangle()
{
}
-/* ---------- core::Light ------------------------------------------ */
-
-Light::Light(math::Vector3f const & location, math::Color const & color, bool strobe) :
- light_location(location),
- light_color(color)
-{
- light_strobe = strobe;
- light_radius = 1.0f;
- light_frequency = 1.0f;
- light_offset = 0.0f;
- light_time = 0.5f;
- light_flare = 0;
- render_texture = 0;
-}
-
-Light::~Light()
-{}
/* ---------- core::Engine ------------------------------------------ */
diff --git a/src/core/model.h b/src/model/model.h
index e9b3de4..95f84cc 100644
--- a/src/core/model.h
+++ b/src/model/model.h
@@ -1,16 +1,11 @@
/*
- render/model.h
+ model/model.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_CORE_MODEL_H__
-#define __INCLUDED_CORE_MODEL_H__
-
-namespace core
-{
-class Model;
-}
+#ifndef __INCLUDED_MODEL_MODEL_H__
+#define __INCLUDED_MODEL_MODEL_H__
#include <vector>
#include <map>
@@ -18,52 +13,12 @@ class Model;
#include "math/mathlib.h"
#include "math/plane3f.h"
-#include "core/entity.h"
+#include "model/light.h"
+#include "model/vertexarray.h"
-namespace core
+namespace model
{
-/// global vertex array
-
-const int SPHERESEGMENTS=33;
-
-class VertexArray
-{
-public:
- /// Create a new VertexArray with size in Mb
- VertexArray(size_t size);
- ~VertexArray();
-
- void clear();
-
- void add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color);
-
-
- inline float *vertex() { return vertex_vertex; }
- inline float *color() { return vertex_color; }
- inline float *normal() { return vertex_normal; }
- inline float *texture() { return vertex_texture; }
-
- inline size_t size() const { return vertex_size; }
- inline size_t index() const { return vertex_index; }
-
- static inline VertexArray *instance() { return vertex_instance; }
-
-private:
- /// model vertices
- float *vertex_vertex;
- float *vertex_color;
- float *vertex_normal;
- float *vertex_texture;
-
- size_t vertex_index;
- size_t vertex_size;
-
- void add_sphere();
-
- static VertexArray *vertex_instance;
-};
-
/// a model triangle
class Triangle
{
@@ -108,50 +63,6 @@ public:
math::Vector3f engine_location;
};
-/// an exterior light
-class Light
-{
-public:
- Light(math::Vector3f const & location, math::Color const & color, bool strobe=false);
- ~Light();
-
- inline math::Vector3f const & location() const { return light_location; }
-
- inline math::Color const & color() const { return light_color; };
-
- /// true if this is a strobe light
- inline bool strobe() const { return light_strobe; }
-
- /// size if the light, default is 1.0f
- inline float radius() const { return light_radius; }
-
- /// strobe time offset, in seconds
- inline float offset() const { return light_offset; }
-
- /// frequency in strobes per second
- inline float frequency() const { return light_frequency; }
-
- /// fraction a strobe light will be on, default is 0.5f
- inline float time() const { return light_time; }
-
- /// flare texture number
- inline size_t flare() const { return light_flare; }
-
- /// render texture number
- inline size_t texture() const { return render_texture; }
-
- math::Vector3f light_location;
- math::Color light_color;
- bool light_strobe;
- float light_radius;
- float light_frequency;
- float light_offset;
- float light_time;
-
- size_t light_flare;
-
- size_t render_texture;
-};
/// a 3D model contains a list of faces
@@ -255,5 +166,5 @@ private:
}
-#endif // __INCLUDED_RENDER_MODEL_H__
+#endif // __INCLUDED_MODEL_MODEL_H__
diff --git a/src/model/vertexarray.cc b/src/model/vertexarray.cc
new file mode 100644
index 0000000..420e816
--- /dev/null
+++ b/src/model/vertexarray.cc
@@ -0,0 +1,144 @@
+
+/*
+ model/vertexarray.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "math/mathlib.h"
+#include "model/vertexarray.h"
+#include "sys/sys.h"
+
+namespace model {
+
+VertexArray *VertexArray::vertex_instance = 0 ;
+
+VertexArray::VertexArray(size_t size)
+{
+ vertex_instance = this;
+ vertex_size = size * 1024*1024; // megabytes
+ vertex_size = vertex_size / sizeof(float); // sizeof float
+ vertex_size = vertex_size / 4; // 4 arrays
+
+ vertex_vertex = (float *) malloc(vertex_size * sizeof(float));
+ vertex_color = (float *) malloc(vertex_size * sizeof(float));
+ vertex_normal = (float *) malloc(vertex_size * sizeof(float));
+ vertex_texture = (float *) malloc(vertex_size * sizeof(float));
+
+ con_print << "Initializing vertex array..." << std::endl;
+ con_debug << " " << size << " Mb allocated" << std::endl;
+
+ clear();
+}
+
+VertexArray::~VertexArray()
+{
+ free(vertex_vertex);
+ free(vertex_normal);
+ free(vertex_color);
+ free(vertex_texture);
+
+ vertex_instance = 0 ;
+}
+
+void VertexArray::clear()
+{
+ vertex_index = 0;
+
+ memset(vertex_vertex, 0, sizeof(vertex_vertex));
+ memset(vertex_color, 0, sizeof(vertex_color));
+ memset(vertex_normal, 0, sizeof(vertex_normal));
+ memset(vertex_texture, 0, sizeof(vertex_normal));
+
+ add_sphere();
+}
+
+void VertexArray::add_sphere()
+{
+ // load sphere vertices into the VertexArray
+
+ // build sin/cos table
+ float *sintable;
+ float *costable;
+
+ sintable = new float[SPHERESEGMENTS];
+ costable = new float[SPHERESEGMENTS];
+ float d = 2 * M_PI / (SPHERESEGMENTS-1);
+
+ for (int i=0; i < SPHERESEGMENTS; i++) {
+ sintable[i] = sin( d * (float) i );
+ costable[i] = cos ( d * (float) i );
+ }
+
+ // draw body
+ math::Color white(1.0f, 1.0f, 1.0f);
+ math::Vector3f v;
+ math::Vector3f n;
+
+ int count;
+
+ for (int j=0; j < SPHERESEGMENTS-1; j++) {
+ float r = sintable[j];
+ float r1 = sintable[j+1];
+
+ // glBegin
+ v = math::Vector3f(r, 0, costable[j]);
+ n = v;
+ n.normalize();
+ //normal(n);
+ //vertex(v);
+ add_vertex(v, n, white);
+
+ v = math::Vector3f(r1, 0, costable[j+1]);
+ n = v;
+ n.normalize();
+ //normal(n);
+ //vertex(v);
+ add_vertex(v, n, white);
+
+ count =2;
+
+ for (int i = SPHERESEGMENTS-1; i >= 0; 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);
+
+ 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);
+ count +=2;
+ }
+ // glEnd
+
+ }
+
+ delete[] sintable;
+ delete[] costable;
+}
+
+void VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color) {
+ 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_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
new file mode 100644
index 0000000..6145659
--- /dev/null
+++ b/src/model/vertexarray.h
@@ -0,0 +1,57 @@
+/*
+ model/vertexarray.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_MODEL_VERTEXARRAY_H__
+#define __INCLUDED_MODEL_VERTEXARRAY_H__
+
+#include "math/color.h"
+#include "math/vector3f.h"
+
+namespace model {
+
+const int SPHERESEGMENTS=33;
+
+/// global vertex array
+class VertexArray
+{
+public:
+ /// create a new VertexArray with size in Mb
+ VertexArray(size_t size);
+ ~VertexArray();
+
+ void clear();
+
+ void add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color);
+
+
+ inline float *vertex() { return vertex_vertex; }
+ inline float *color() { return vertex_color; }
+ inline float *normal() { return vertex_normal; }
+ inline float *texture() { return vertex_texture; }
+
+ inline size_t size() const { return vertex_size; }
+ inline size_t index() const { return vertex_index; }
+
+ static inline VertexArray *instance() { return vertex_instance; }
+
+private:
+ /// model vertices
+ float *vertex_vertex;
+ float *vertex_color;
+ float *vertex_normal;
+ float *vertex_texture;
+
+ size_t vertex_index;
+ size_t vertex_size;
+
+ void add_sphere();
+
+ static VertexArray *vertex_instance;
+};
+
+}
+
+#endif // __INCLUDED_MODEL_VERTEXARRAY_H__
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 2938442..5627ac6 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -8,7 +8,7 @@
#include <iomanip>
#include "core/core.h"
-#include "core/model.h"
+#include "model/model.h"
#include "render/render.h"
#include "render/textures.h"
#include "render/draw.h"
@@ -67,10 +67,10 @@ void draw_sphere(math::Color const & color, float radius)
gl::color(color);
size_t index = 0;
- size_t count = (core::SPHERESEGMENTS+1)*2;
+ size_t count = (model::SPHERESEGMENTS+1)*2;
// draw body
- for (int j=0; j < core::SPHERESEGMENTS-1; j++) {
+ for (int j=0; j < model::SPHERESEGMENTS-1; j++) {
glDrawArrays(gl::QuadStrip, index, count);
index += count;
Stats::quads += count/2-1;
@@ -186,13 +186,13 @@ void draw_model_evertex(core::Entity *entity)
void draw_model_engines(core::EntityControlable *entity)
{
- core::Model *model = entity->model();
+ 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<core::Engine *>::iterator eit = model->model_engine.begin(); eit != model->model_engine.end(); eit++) {
+ 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);
@@ -260,13 +260,13 @@ void pass_visibility()
// load entity models if necessary
if (!entity->model() && entity->modelname().size()) {
- entity->entity_model = core::Model::get(entity->modelname());
+ entity->entity_model = model::Model::get(entity->modelname());
if (!entity->model()) {
entity->entity_modelname.clear();
} else {
- for (std::list<core::Light *>::iterator lit = entity->model()->model_light.begin(); lit != entity->model()->model_light.end(); lit++) {
- core::Light *light = (*lit);
+ for (std::list<model::Light *>::iterator lit = entity->model()->model_light.begin(); lit != entity->model()->model_light.end(); lit++) {
+ model::Light *light = (*lit);
// load flare texture
std::stringstream flarename;
@@ -408,7 +408,7 @@ void draw_pass_model_lights()
if (test_drawfx_distance(entity) && (entity->model()->model_light.size())) {
- for (std::list<core::Light *>::iterator lit = entity->model()->model_light.begin(); lit != entity->model()->model_light.end(); lit++) {
+ for (std::list<model::Light *>::iterator lit = entity->model()->model_light.begin(); lit != entity->model()->model_light.end(); lit++) {
// strobe frequency
float t = 1.0f;
if ((*lit)->strobe())
diff --git a/src/render/render.cc b/src/render/render.cc
index 589dce3..8c4f0fb 100644
--- a/src/render/render.cc
+++ b/src/render/render.cc
@@ -26,7 +26,9 @@ core::Cvar *r_radius = 0;
core::Cvar *r_wireframe = 0;
core::Cvar * r_arraysize = 0;
-core::VertexArray *vertexarray = 0;
+using model::VertexArray;
+
+VertexArray *vertexarray = 0;
bool texture(const char *filename, size_t id)
{
@@ -72,7 +74,7 @@ void init()
if (mb > 256)
mb = 256;
(*r_arraysize) = (float) mb;
- vertexarray = new core::VertexArray(mb);
+ vertexarray = new VertexArray(mb);
r_radius = core::Cvar::get("r_radius", "0", core::Cvar::Archive);
r_radius->set_info("[bool] render entity radius");
@@ -95,7 +97,7 @@ void shutdown()
}
// clear models
- core::Model::clear();
+ model::Model::clear();
// clear vertex array
delete vertexarray;
diff --git a/src/render/render.h b/src/render/render.h
index ce638bb..0bde634 100644
--- a/src/render/render.h
+++ b/src/render/render.h
@@ -9,7 +9,7 @@
#include "GL/gl.h"
#include "core/cvar.h"
-#include "core/model.h"
+#include "model/model.h"
namespace render {
@@ -25,7 +25,7 @@ namespace render {
extern core::Cvar *r_wireframe;
extern core::Cvar *r_arraysize;
- extern core::VertexArray *vertexarray;
+ extern model::VertexArray *vertexarray;
}
#include "render/draw.h"