public Colour RefractedColour(Computation comps, int remaining) { if (remaining <= 0) { return(ColourFactory.Black); } if (DoubleUtils.DoubleEquals(comps.Object.Material.Transparency, 0)) { return(ColourFactory.Black); } var nRatio = comps.N1 / comps.N2; var cosI = comps.EyeV.Dot(comps.NormalV); var sin2T = Math.Pow(nRatio, 2) * (1 - Math.Pow(cosI, 2)); if (sin2T > 1) { return(ColourFactory.Black); } var cosT = Math.Sqrt(1.0 - sin2T); var direction = (comps.NormalV.Multiply(nRatio * cosI - cosT) - comps.EyeV.Multiply(nRatio)).ToVector(); var refractRay = new Ray(comps.UnderPoint, direction); var colour = ColourAt(refractRay, remaining - 1).Multiply(comps.Object.Material.Transparency); return(colour); }
public Intersection[] Intersects(Ray ray) { var allIntersections = new List <Intersection>(); foreach (var sceneObject in SceneObjects) { allIntersections.AddRange(sceneObject.Intersects(ray)); } allIntersections.Sort((x, y) => { if (DoubleUtils.DoubleEquals(x.T, y.T)) { return(0); } if (x.T > y.T) { return(1); } return(-1); }); return(allIntersections.ToArray()); }
public override bool Equals(object?obj) { if (obj == null) { return(false); } if (obj is Matrix compareTo) { if (this.RowCount == compareTo.RowCount && this.ColCount == compareTo.ColCount) { for (var row = 0; row < this.RowCount; row++) { for (var col = 0; col < this.ColCount; col++) { if (!DoubleUtils.DoubleEquals(Get(row, col), compareTo.Get(row, col))) { return(false); } } } return(true); } } return(false); }
public override bool Equals(object obj) { if (obj != null) { if (obj is Colour compareColour) { return(DoubleUtils.DoubleEquals(this.R, compareColour.R) && DoubleUtils.DoubleEquals(this.G, compareColour.G) && DoubleUtils.DoubleEquals(this.B, compareColour.B)); } } return(false); }
public override bool Equals(object obj) { if (obj != null) { if (obj is RtTuple compareTuple) { return(DoubleUtils.DoubleEquals(this.X, compareTuple.X) && DoubleUtils.DoubleEquals(this.Y, compareTuple.Y) && DoubleUtils.DoubleEquals(this.Z, compareTuple.Z) && DoubleUtils.DoubleEquals(this.W, compareTuple.W)); } } return(false); }
public Colour ReflectedColour(Computation comps, int remaining = 5) { if (remaining <= 0) { return(ColourFactory.Black); } if (DoubleUtils.DoubleEquals(comps.Object.Material.Reflective, 0)) { return(ColourFactory.Black); } var reflectedRay = new Ray(comps.OverPoint, comps.ReflectV); var colour = ColourAt(reflectedRay, remaining - 1); return(colour.Multiply(comps.Object.Material.Reflective)); }
public override bool Equals(object?obj) { if (obj != null) { if (obj is Material objMaterial) { return(this.Colour.Equals(objMaterial.Colour) && DoubleUtils.DoubleEquals(this.Ambient, objMaterial.Ambient) && DoubleUtils.DoubleEquals(this.Diffuse, objMaterial.Diffuse) && DoubleUtils.DoubleEquals(this.Specular, objMaterial.Specular) && DoubleUtils.DoubleEquals(this.Shininess, objMaterial.Shininess) && DoubleUtils.DoubleEquals(this.Reflective, objMaterial.Reflective) && DoubleUtils.DoubleEquals(this.Transparency, objMaterial.Transparency) && DoubleUtils.DoubleEquals(this.RefractiveIndex, objMaterial.RefractiveIndex)); } } return(false); }
public static bool IsInvertible(double determinant) { return(!DoubleUtils.DoubleEquals(0.0, determinant)); }