27 /* axis-aligned bounding box */ |
27 /* axis-aligned bounding box */ |
28 class BBox |
28 class BBox |
29 { |
29 { |
30 public: |
30 public: |
31 Vector3 L; |
31 Vector3 L; |
32 Vector3 R; |
32 Vector3 H; |
33 BBox(): L(), R() {}; |
33 BBox(): L(), H() {}; |
34 float w() { return R.x-L.x; }; |
34 BBox(const Vector3 aL, const Vector3 aH): L(aL), H(aH) {}; |
35 float h() { return R.y-L.y; }; |
35 float w() { return H.x-L.x; }; |
36 float d() { return R.z-L.z; }; |
36 float h() { return H.y-L.y; }; |
|
37 float d() { return H.z-L.z; }; |
37 bool intersect(const Ray &ray, float &a, float &b); |
38 bool intersect(const Ray &ray, float &a, float &b); |
38 }; |
39 }; |
39 |
40 |
40 class Light |
41 class Light |
41 { |
42 { |
116 bool intersect_all(const Ray &ray, float dist, vector<float> &allts); |
117 bool intersect_all(const Ray &ray, float dist, vector<float> &allts); |
117 Vector3 normal(Vector3 &P) { return (P - center) * inv_radius; }; |
118 Vector3 normal(Vector3 &P) { return (P - center) * inv_radius; }; |
118 BBox get_bbox(); |
119 BBox get_bbox(); |
119 }; |
120 }; |
120 |
121 |
121 class Plane: public Shape |
122 class Box: public Shape |
122 { |
123 { |
|
124 Vector3 L; |
|
125 Vector3 H; |
123 public: |
126 public: |
124 Vector3 N; |
127 Box(const Vector3 &aL, const Vector3 &aH, Material *amaterial): L(aL), H(aH) |
125 float d; |
128 { |
126 |
129 for (int i = 0; i < 3; i++) |
127 Plane(const Vector3 &normal, const float ad, Material *amaterial): |
130 if (L.cell[i] > H.cell[i]) |
128 N(normal), d(ad) { material = amaterial; }; |
131 swap(L.cell[i], H.cell[i]); |
129 Plane(const Vector3 &normal, const Vector3 &point): |
132 material = amaterial; |
130 N(normal), d(0) { /*TODO*/}; |
133 }; |
131 bool intersect(const Ray &ray, float &dist); |
134 bool intersect(const Ray &ray, float &dist); |
132 bool intersect_all(const Ray &ray, float dist, vector<float> &allts) {return false;}; |
135 bool intersect_all(const Ray &ray, float dist, vector<float> &allts) {return false;}; |
133 Vector3 normal(Vector3 &) { return N; }; |
136 Vector3 normal(Vector3 &P); |
134 BBox get_bbox(); |
137 BBox get_bbox() { return BBox(L, H); }; |
135 }; |
138 }; |
136 |
139 |
137 class Triangle: public Shape |
140 class Triangle: public Shape |
138 { |
141 { |
139 int k; // dominant axis |
142 int k; // dominant axis |