Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-03-24 12:35:48 +0000
committerStijn Buys <ingar@osirion.org>2008-03-24 12:35:48 +0000
commitb32c086a9b9deed4c34ade6e2447861a9c4bfc46 (patch)
treef3213a8f4b1ffd15df28aa6bd82b9fe6c1bb979d /src/core
parent80ad7e99b738f367eb045768d054cf74347ee1b4 (diff)
moved the sphere into the vertex array
Diffstat (limited to 'src/core')
-rw-r--r--src/core/model.cc82
-rw-r--r--src/core/model.h4
2 files changed, 81 insertions, 5 deletions
diff --git a/src/core/model.cc b/src/core/model.cc
index 9f135b4..6a82989 100644
--- a/src/core/model.cc
+++ b/src/core/model.cc
@@ -19,7 +19,9 @@
namespace core
{
-const float MAX_BOUNDS = 8192;
+//const float MAX_BOUNDS = 8192;
+const float MAX_BOUNDS = 16384;
+
const float delta = 10e-10;
/* ---------- core::VertexArray ------------------------------------ */
@@ -36,18 +38,88 @@ size_t VertexArray::vertex_index;
void VertexArray::clear()
{
+ vertex_index = 0;
+
// The VertexArray is only used by the client
if (!(Cvar::sv_dedicated && Cvar::sv_dedicated->value())) {
memset(vertex, 0, sizeof(vertex));
memset(vertex_color, 0, sizeof(vertex_color));
memset(vertex_normal, 0, sizeof(vertex_normal));
- //memset(evertex, 0, sizeof(evertex));
- //memset(evertex_normal, 0, sizeof(evertex_normal));
+ add_sphere();
}
- vertex_index = 0;
- //evertex_index = 0;
+
+}
+
+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
+
+ }
+
+ con_debug << "SPhere segment count " << count <<std::endl;
+ delete[] sintable;
+ delete[] costable;
}
void VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color) {
diff --git a/src/core/model.h b/src/core/model.h
index 51e9ca7..4fc4d97 100644
--- a/src/core/model.h
+++ b/src/core/model.h
@@ -25,6 +25,7 @@ namespace core
/// size of the global vertex array - 32M
const size_t VERTEXARRAYSIZE=65536*512;
+const int SPHERESEGMENTS=33;
/// global vertex array
class VertexArray
@@ -40,6 +41,9 @@ public:
static void clear();
static void add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color);
+
+private:
+ static void add_sphere();
};
/// a model triangle