00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "shape.h"
00025
00026
00027 namespace lux
00028 {
00029
00030 class Cylinder: public Shape {
00031 public:
00032
00033 Cylinder(const Transform &o2w, bool ro, float rad,
00034 float zmin, float zmax, float phiMax);
00035 virtual ~Cylinder() { }
00036 virtual BBox ObjectBound() const;
00037 virtual bool Intersect(const Ray &ray, float *tHit,
00038 DifferentialGeometry *dg) const;
00039 virtual bool IntersectP(const Ray &ray) const;
00040 virtual float Area() const;
00041 virtual Point Sample(float u1, float u2, float u3,
00042 Normal *Ns) const {
00043 float z = Lerp(u1, zmin, zmax);
00044 float t = u2 * phiMax;
00045 Point p = Point(radius * cosf(t), radius * sinf(t), z);
00046 *Ns = Normalize(ObjectToWorld(Normal(p.x, p.y, 0.)));
00047 if (reverseOrientation) *Ns *= -1.f;
00048 return ObjectToWorld(p);
00049 }
00050
00051 static Shape* CreateShape(const Transform &o2w, bool reverseOrientation, const ParamSet ¶ms);
00052 protected:
00053
00054 float radius;
00055 float zmin, zmax;
00056 float phiMax;
00057 };
00058
00059 }