Sphere.h

00001 
00006 #ifndef SPHERE_H
00007 #define SPHERE_H 
00008 
00009 /*
00010 ** ---------------------------------------------------------------
00011 ** Includes:
00012 */
00013 #include <iostream>
00014 #include "Vector3.h"
00015 #include "AffineTransform.h"
00016 
00017 /*
00018 ** ---------------------------------------------------------------
00019 ** Definitions:
00020 */
00021 
00022 #define SPHERE 16
00023 
00024 using namespace std;
00025 
00027 
00033 class Sphere : public PrimitiveRep {
00034 
00035 
00036 public:
00038         Sphere();
00040         Sphere(const Vector3 &c, double  r)
00042         void ~Sphere() 
00043 
00044         
00045         const Vector3 &center() const;
00047         double radius() const;
00048 
00050         static Val parse(int c, Pval *pl);
00051 
00052 
00054         int id(PrimitiveRep *p) const 
00056         Box3d bbox() const 
00058         virtual int classify( Vector3 q) const 
00060         virtual Vector3 point( Real u, Real v) const 
00062         virtual Vector3 normal( Real u, Real v) const 
00064         virtual Vector3 gradient( const Vector3 &q) const 
00066         virtual Inode *intersect( const Ray &r) const 
00068         virtual Polygon *uv_decomp( Real level) const;
00070         virtual Vector3 texc( Real u, Real v) const 
00072         virtual Vector3 du( Real u, Real v) const 
00074         virtual Vector3 dv( Real u, Real v) const 
00076         virtual AffineTransform local(PrimitiveRep *p) const 
00077 
00078         virtual ofstream &operator<<(ofstream &out) 
00079 
00080 private :
00081 
00083         Vector3 &c;
00085         double  r;
00086 
00087 
00088 
00089 };
00090 
00092 inline ostream &operator<<(ostream &os, const Sphere3 &sphere);
00093 
00094 
00095 
00096 inline const Vector3 &
00097 Sphere::center() const 
00098 {
00099         return c;
00100 }
00101 
00102 inline double 
00103 Sphere::radius() const 
00104 {
00105         return r;
00106 }
00107 
00108 inline int 
00109 Sphere::id()
00110 {
00111         return SPHERE;
00112 }
00113 
00114 inline Vector3 
00115 Sphere::texc( Real u, Real v)
00116 {
00117         return Vector3((u - UMIN)/ULEN, (v - VMIN)/VLEN, 0);
00118 }
00119 
00120 inline Vector3 
00121 Sphere::du( Real u, Real v)
00122 {
00123         return Vector3(- sin(u) * cos(v), cos(u) * cos(v), 0);
00124 }
00125 
00126 inline Vector3 
00127 Sphere::dv( Real u, Real v)
00128 {
00129         return Vector3(- cos(u) * sin(v), - sin(u) * sin(v), cos(v));
00130 }
00131 
00132 inline AffineTransform 
00133 Sphere::local()
00134 {
00135         return ti;
00136 }
00137 
00138 inline Val 
00139 Sphere::parse(int pass, Pval *pl)
00140 {
00141         Val v = {V_NULL, 0};
00142         
00143         if (pass == T_EXEC) {
00144         Vector3 c = pvl_get_v3(pl, "center", Vector3(0,0,0));
00145         double r = pvl_get_num(pl, "radius", 1);
00146         v.type = V_PRIM;
00147         set(v.u.v = instance(&funcs), c, r);
00148         }
00149         return v;
00150 }
00151 
00152 inline ostream &
00153 Sphere::operator<<(ostream &os, const Sphere3 &sphere)
00154 {
00155         return out << "sphere { \n") << 
00156         "\t\t center = {%g, %g, %g},\n",sphere.c.x,sphere.c.y,sphere.c.z) <<
00157         "\t\t radius = %g \n}\n",sphere.r);
00158 }
00159 
00160 #endif //SPHERE_H

Generated on Thu Jul 5 00:16:33 2007 for S3D by  doxygen 1.4.6