]> Dogcows Code - chaz/rasterize/blobdiff - sphere.hh
added texturing
[chaz/rasterize] / sphere.hh
index cbacac9e5fedf590f9e66c0bdf3d1e4d04c696d4..5ee9d0fe1dc376cc3077506d305c8113f1f736ac 100644 (file)
--- a/sphere.hh
+++ b/sphere.hh
@@ -8,7 +8,6 @@
 #ifndef _SPHERE_HH_
 #define _SPHERE_HH_
 
-#include "color.hh"
 #include "element.hh"
 
 
@@ -20,14 +19,13 @@ namespace rt {
  */
 class sphere : public element
 {
-public:
-
-    color_t material;
     vec_t   origin;
     scal_t  radius;
 
-    sphere(vec_t o, scal_t r = S(1.0), color_t color = COLOR_WHITE) :
-        origin(o), radius(r), material(color)
+public:
+
+    sphere(vec_t o, scal_t r = S(1.0)) :
+        origin(o), radius(r)
     {}
 
     virtual ~sphere()
@@ -61,9 +59,17 @@ public:
                return true;
     }
 
-    virtual color_t color(vec_t point) const
+    virtual vec_t txcoord(vec_t point) const
     {
-        return material;
+        vec_t uv = VEC_ZERO;
+
+        scal_t theta = scal_atan2(point.z, point.x);
+        scal_t phi = asin(point.y / radius);
+
+        uv.x = theta / (S(2.0) * M_PI) + S(0.5);
+        uv.y = phi / M_PI + S(0.5);
+
+        return uv;
     }
 };
 
This page took 0.023039 seconds and 4 git commands to generate.