From 36e52bc178b2ba25ecc1b3fc13e03f2aee1e8efa Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 25 May 2008 15:06:09 +0000 Subject: planet updates --- src/model/vertexarray.cc | 55 +++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'src/model/vertexarray.cc') diff --git a/src/model/vertexarray.cc b/src/model/vertexarray.cc index d13fc0c..da9c3d2 100644 --- a/src/model/vertexarray.cc +++ b/src/model/vertexarray.cc @@ -74,47 +74,45 @@ void VertexArray::add_sphere() math::Color white(1.0f, 1.0f, 1.0f); math::Vector3f v; math::Vector3f n; + math::Vector3f tex; int count; - for (int j=0; j < SPHERESEGMENTS-1; j++) { + //float h = (float) (SPHERESEGMENTS-1) / 2 -1; + for (int j=0; j < (SPHERESEGMENTS-1) / 2; j++) { + float r = sintable[j]; float r1 = sintable[j+1]; - // glBegin - v = math::Vector3f(r, 0, costable[j]); +/* v.assign(r, 0, costable[j]); n = v; n.normalize(); - //normal(n); - //vertex(v); - add_vertex(v, n, white); + tex.assign(1, (float)(SPHERESEGMENTS-1-j) / (float)(SPHERESEGMENTS-1), 0); + add_vertex(v, n, white, tex); v = math::Vector3f(r1, 0, costable[j+1]); n = v; n.normalize(); - //normal(n); - //vertex(v); - add_vertex(v, n, white); + tex.assign(1, (float) (SPHERESEGMENTS-2-j) / (float)(SPHERESEGMENTS-1), 0 ); + add_vertex(v, n, white, tex); count =2; - - for (int i = SPHERESEGMENTS-1; i >= 0; i--) { +*/ + for (int i = 0; i < SPHERESEGMENTS; 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); + //tex.assign((float)i/(float)(SPHERESEGMENTS), (float) (j) / h, 0); + tex.assign((float)i/(float)(SPHERESEGMENTS-1), -costable[j]/2 + 0.5f , 0); + add_vertex(v, n, white, tex); 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); + n.normalize(); + tex.assign((float)i/(float)(SPHERESEGMENTS-1), -costable[j+1]/2 + 0.5f, 0); + add_vertex(v, n, white, tex); count +=2; } - // glEnd } @@ -140,5 +138,24 @@ void VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, m vertex_index += 3; } +void VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color, math::Vector3f const &tex) { + 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_texture[vertex_index+i] = tex[i]; + } + + vertex_color[vertex_index] = color.r; + vertex_color[vertex_index+1] = color.g; + vertex_color[vertex_index+2] = color.b; + + vertex_index += 3; +} + } -- cgit v1.2.3