// Considering deleting this method and using only RayToObjectSpace method in RayObject class /// <summary> /// Takes a RayObject's tranformMatrix inverts it and /// returns a new ray with an update origin position Point /// </summary> /// <param name="obj"></param> /// <returns></returns> public Ray ApplyObjectTransform(RayObject obj) { Ray temp = new Ray(new Point(), new Vector3()); temp = this * obj.Transform.Invert(); return(temp); }
/// <summary> /// Uses PatternAt() method to return Color value. /// Converting world space to object to apply pattern to each RayObject independently. /// aka stripe_at_object(Rayobject,Point) from book /// </summary> /// <param name="obj"></param> /// <param name="pointWorld"></param> /// <returns></returns> public Color PatternAtObject(RayObject RayObject, Point pointWorld) { // Converts world space to pattern space through objectspace Point objectPoint = RayObject.Transform.Invert() * pointWorld; //Point patternPoint = this.Transform.Invert() * objectPoint; return(this.PatternAt(objectPoint)); }
/// <summary> /// Add a Rayobject to scene /// </summary> /// <param name="rayObject"></param> public void AddObject(RayObject rayObject) { this.objects.Add(rayObject); }
public void AddChild(RayObject obj) { obj.parent = this; childern.Add(obj); }
// Get/Set methods // Constructors public Intersection(float t, RayObject rayObject) { this.t = t; this.rayObject = rayObject; }
/// <summary> /// Old Lighting method. Uses bool type for determining if in shadow. /// Doesn't adjust shadow darkness based on transparency of object blocking light /// Legacy method. Will Remove eventually. /// </summary> /// <param name="material"></param> /// <param name="rayObject"></param> /// <param name="light"></param> /// <param name="point"></param> /// <param name="eyeV"></param> /// <param name="normalV"></param> /// <param name="inShadow"></param> /// <returns></returns> public Color Lighting(Material material, RayObject rayObject, Light light, Point point, Vector3 eyeV, Vector3 normalV, bool inShadow) // LEGACY // CONSIDER removing material from parameter list. Already getting data from self. Also CONSIDER moving RayObject call. { Color ambient = Color.White; Color diffuse = Color.White; Color specular = Color.White; Color effect_color; if (pattern != null) { // Combines surface pattern color with light's color/intensity if a pattern exist effect_color = pattern.PatternAtObject(rayObject, point) * light.Intensity; } else { // Combines surface color with light's color/intensity effect_color = material.mColor * light.Intensity; } // find the direction to the light source Vector3 lightV = (light.Position - point).Normalized(); // Compute the ambient contribution ambient = effect_color * material.Ambient; // If in shadow just return the ambient color AND // if object that the ray hits on the way to the light source is completely non-transparent // skip diffuse and specular calculations return ambient color. if (inShadow) { return(ambient); } // lighDotNormal represents the cosine of the angle between the // light vector and the normal vector. A negative number means the // light is on the other side of the surface. float lighDotNormal = Vector3.Dot(lightV, normalV); if (lighDotNormal < 0) { diffuse = Color.Black; specular = Color.Black; } else { // Compute the diffuse contribution diffuse = effect_color * material.Diffuse * lighDotNormal; // reflectDotEye represents the cosine of the angle between the // reflection vector and the eye vector. A negative number means the // light reflects away from the eye. Vector3 reflectV = Vector3.Reflection(-lightV, normalV); float reflectDotEye = Vector3.Dot(reflectV, eyeV); // if reflection is away from eye if (reflectDotEye <= 0) { specular = Color.Black; } else { // compute the specular contribution float factor = (float)Math.Pow(reflectDotEye, material.Shininess); specular = light.Intensity * material.Specular * factor; } } /* * Console.WriteLine("Ambient: " + ambient.ToString()); * Console.WriteLine("Diffuse: " + diffuse.ToString()); * Console.WriteLine("Specular: " + specular.ToString()); */ // Add the three contributions together to get the final shading return(ambient + diffuse + specular); }