Skip to content
Snippets Groups Projects
Verified Commit 3de9dcfd authored by Tóth Miklós Tibor's avatar Tóth Miklós Tibor :shrug:
Browse files

majdnem chips

parent db19d4ec
Branches
Tags
No related merge requests found
......@@ -160,6 +160,53 @@ struct Sphere : public Intersectable {
}
};
class Chips: public Sphere {
float a = 1.1, b = 1.2, c = 1.3;
public:
explicit Chips(Material* material): Sphere(0, 0.3, material) {
}
Hit intersect(const Ray& ray) override {
auto hit = Sphere::intersect(ray);
if (hit.t < 0) {
return hit;
}
auto _a = a * ray.dir.x * ray.dir.x + b * ray.dir.y * ray.dir.y;
auto _b = a * 2 * ray.start.x * ray.dir.x + b * 2 * ray.start.y * ray.dir.y - c * ray.dir.z;
auto _c = a * ray.start.x * ray.start.x + b * ray.start.y * ray.start.y - c * ray.start.z;
auto discriminant = _b*_b - 4*_a*_c;
auto s_disc = sqrt(discriminant);
if (s_disc < 0) {
return hit;
}
auto t1 = (-_b+s_disc)/(2*_a);
auto t2 = (-_b-s_disc)/(2*_a);
auto t = t1;
if (t2 < t){
t = t2;
}
hit.t = t;
hit.position = ray.start + ray.dir*t;
hit.normal.x = 2.0f*a*hit.position.x;
hit.normal.y = 2.0f*b*hit.position.y;
hit.normal.z = -c;
hit.normal = hit.position+hit.normal;
hit.normal = normalize(hit.normal);
// TODO: félúton szublimál
return hit;
}
};
struct Pentagon : public Intersectable {
vec3 r1;
vec3 r2;
......@@ -287,7 +334,7 @@ public:
vec3 n(.17, .35, 1.5);
vec3 kappa(3.1, 2.7, 1.9);
Material* gold = new ReflectiveMaterial(n, kappa);
objects.push_back(new Sphere(vec3(0, 0, 0), .25f, gold));
objects.push_back(new Chips(gold));
//objects.push_back(new Pentagon(vec3(0.03, -.01, 0), vec3(0, .37, 0), vec3(-.47, .49, 0), vec3(-.73, .08, 0), vec3(-.414, -0.288, 0), dodekaMat));
vec3 kd(0.3f, 0.3f, .3f), ks(2, 2, 2);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment