Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/sphere.cc')
-rw-r--r--src/render/sphere.cc77
1 files changed, 56 insertions, 21 deletions
diff --git a/src/render/sphere.cc b/src/render/sphere.cc
index 1715263..616424e 100644
--- a/src/render/sphere.cc
+++ b/src/render/sphere.cc
@@ -14,15 +14,14 @@ namespace render {
const int segments = 33;
-Sphere::Sphere(Vector3f p , float r)
+Sphere::Sphere(float r)
{
- position = p;
radius = r;
// TODO make global sine-cosine lists
sintable = new float[segments];
costable = new float[segments];
- float d = 2 * M_PI / segments;
+ float d = 2 * M_PI / (segments-1);
for (int i=0; i < segments; i++) {
sintable[i] = sin( d * (float) i );
@@ -43,7 +42,7 @@ Sphere::Sphere(const Sphere &other)
Sphere& Sphere::operator=(const Sphere &other)
{
- position = other.position;
+ sphere_color = other.sphere_color;
radius = other.radius;
return (*this);
}
@@ -52,36 +51,72 @@ void Sphere::draw()
{
using namespace gl;
- // draw top
- // TODO upside-down
float r = radius*sintable[1];
- float h = radius*costable[1];
+ //float h = radius*costable[1];
+
+ gl::color(sphere_color);
- begin(LineLoop);
- //begin(Polygon);
- for (int i = segments-1; i >= 0; i--)
- vertex(r*costable[i], h, r*sintable[i]);
+ /*
+ // draw top
+ begin(Polygon);
+ normal(0, 1, 0);
+ for (int i = segments-1; i >= 0; i--) {
+ v = Vector3f(r*costable[i], h, r*sintable[i]);
+ n = v;
+ n.normalize();
+ normal(n);
+ vertex(v);
+ }
end();
// draw bottom
- // TODO upside-down
- begin(LineLoop);
- for (int i = 0; i< segments; i++)
- vertex(r*costable[i], -h, r*sintable[i]);
+ begin(Polygon);
+ normal(0, -1, 0);
+ for (int i = 0; i< segments; i++) {
+ //for (int i = segments-1; i >= 0; i--)
+ v = Vector3f(r*costable[i], -h, r*sintable[i]);
+ n = v;
+ n.normalize();
+ normal(n);
+ vertex(v);
+ }
end();
+ */
+
+ Vector3f v;
+ Vector3f n;
// draw body
- for (int j=1; j < segments-1; j++) {
+ for (int j=0; j < segments-1; j++) {
r = radius*sintable[j];
float r1 = radius*sintable[j+1];
begin(QuadStrip);
- vertex(r1, radius*costable[j+1], 0);
- vertex(r, radius*costable[j], 0);
+ v = Vector3f(r, radius*costable[j], 0);
+ n = v;
+ n.normalize();
+ normal(n);
+ vertex(v);
+
+ v = Vector3f(r1, radius*costable[j+1], 0);
+ n = v;
+ n.normalize();
+ normal(n);
+ vertex(v);
+
+ for (int i = segments-1; i >= 0; i--) {
+ v = Vector3f(r*costable[i], radius*costable[j], r*sintable[i]);
+ n = v;
+ n.normalize();
+ normal(n);
+ vertex(v);
+
+ v = Vector3f(r1*costable[i], radius*costable[j+1], r1*sintable[i]);
+ n = v;
+ n.normalize();
+ normal(n);
+ vertex(v);
- for (int i = segments-1; i >= 0; i--) {
- vertex(r1*costable[i], radius*costable[j+1], r1*sintable[i]);
- vertex(r*costable[i], radius*costable[j], r*sintable[i]);
//vertex(r*costable[i-1], radius*costable[j], r*sintable[i-1]);
//vertex(r1*costable[i-1], radius*costable[j+1], r1*sintable[i-1]);
}