From b32c086a9b9deed4c34ade6e2447861a9c4bfc46 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 24 Mar 2008 12:35:48 +0000 Subject: moved the sphere into the vertex array --- src/core/model.cc | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++---- src/core/model.h | 4 +++ 2 files changed, 81 insertions(+), 5 deletions(-) (limited to 'src/core') 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 <