Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/model')
-rw-r--r--src/model/vertexarray.cc55
-rw-r--r--src/model/vertexarray.h4
2 files changed, 38 insertions, 21 deletions
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;
+}
+
}
diff --git a/src/model/vertexarray.h b/src/model/vertexarray.h
index 6145659..6ff32bc 100644
--- a/src/model/vertexarray.h
+++ b/src/model/vertexarray.h
@@ -12,7 +12,7 @@
namespace model {
-const int SPHERESEGMENTS=33;
+const int SPHERESEGMENTS=65;
/// global vertex array
class VertexArray
@@ -25,7 +25,7 @@ public:
void clear();
void add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color);
-
+ void add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color, math::Vector3f const &tex);
inline float *vertex() { return vertex_vertex; }
inline float *color() { return vertex_color; }