public bool Hit(Ray r, float t0, float t1, ref Hit_Record rec) { var t = (k - r.Origin.Z) / r.Direction.Z; if (t < t0 || t > t1) { return(false); } var x = r.Origin.X + t * r.Direction.X; var y = r.Origin.Y + t * r.Direction.Y; if (x < x0 || x > x1 || y < y0 || y > y1) { return(false); } rec.U = (x - x0) / (x1 - x0); rec.V = (y - y0) / (y1 - y0); rec.T = t; var outward_normal = new Vector3(0, 0, 1); rec.Set_Face_Normal(r, outward_normal); rec.Mat_ptr = mp; rec.P = r.At(t); return(true); }
public bool Hit(Ray r, float t0, float t1, ref Hit_Record rec) { var t = (k - r.Origin.X) / r.Direction.X; if (t < t0 || t > t1) { return(false); } var y = r.Origin.Y + t * r.Direction.Y; var z = r.Origin.Z + t * r.Direction.Z; if (y < y0 || y > y1 || z < z0 || z > z1) { return(false); } rec.U = (y - y0) / (y1 - y0); rec.V = (z - z0) / (z1 - z0); rec.T = t; var outward_normal = new Vector3(1, 0, 0); rec.Set_Face_Normal(r, outward_normal); rec.Mat_ptr = mp; rec.P = r.At(t); return(true); }
public bool Hit(Ray r, float t_min, float t_max, ref Hit_Record rec) { Vector3 oc = r.Origin - this.Center(r.Time); var a = r.Direction.LengthSquared(); var half_b = Vector3.Dot(oc, r.Direction); var c = oc.LengthSquared() - radius * radius; var discriminant = half_b * half_b - a * c; if (discriminant > 0) { var root = (float)Math.Sqrt(discriminant); var temp = (-half_b - root) / a; if (temp < t_max && temp > t_min) { rec.T = temp; rec.P = r.At(rec.T); var outward_normal = (rec.P - this.Center(r.Time)) / radius; rec.Set_Face_Normal(r, outward_normal); rec.Mat_ptr = mat_ptr; return(true); } temp = (-half_b + root) / a; if (temp < t_max && temp > t_min) { rec.T = temp; rec.P = r.At(rec.T); var outward_normal = (rec.P - this.Center(r.Time)) / radius; rec.Set_Face_Normal(r, outward_normal); rec.Mat_ptr = mat_ptr; return(true); } } return(false); }
public bool Hit(Ray r, float t_min, float t_max, ref Hit_Record rec) { Vector3 oc = r.Origin - this.Center; float a = r.Direction.LengthSquared(); float half_b = Vector3.Dot(oc, r.Direction); float c = oc.LengthSquared() - this.Radius * this.Radius; float discriminant = half_b * half_b - a * c; if (discriminant > 0) { float root = (float)Math.Sqrt(discriminant); float temp = (-half_b - root) / a; if (temp < t_max && temp > t_min) { rec.T = temp; rec.P = r.At(rec.T); Vector3 outward_normal = (rec.P - this.Center) / this.Radius; rec.Set_Face_Normal(r, outward_normal); rec.Mat_ptr = Material; this.Get_sphere_uv((rec.P - this.Center) / this.Radius, out rec.U, out rec.V); return(true); } temp = (-half_b + root) / a; if (temp < t_max && temp > t_min) { rec.T = temp; rec.P = r.At(rec.T); Vector3 outward_normal = (rec.P - this.Center) / this.Radius; rec.Set_Face_Normal(r, outward_normal); rec.Mat_ptr = Material; this.Get_sphere_uv((rec.P - this.Center) / this.Radius, out rec.U, out rec.V); return(true); } } return(false); }