diff --git a/cameraproject/src/elements/AmbientLight.java b/cameraproject/src/elements/AmbientLight.java index 2580838..e09217d 100644 --- a/cameraproject/src/elements/AmbientLight.java +++ b/cameraproject/src/elements/AmbientLight.java @@ -18,8 +18,8 @@ public AmbientLight() { * Constructor that receives the color that the body produces and promotes the * attenuation of light * - * @param intensity Light intensity according to RGB components - * @param kA The attenuation coefficient of light + * @param intensity - Light intensity according to RGB components + * @param kA - The attenuation coefficient of light */ public AmbientLight(Color intensity, double kA) { super(intensity.scale(kA)); diff --git a/cameraproject/src/elements/DirectionalLight.java b/cameraproject/src/elements/DirectionalLight.java index 0c2620f..9392c2a 100644 --- a/cameraproject/src/elements/DirectionalLight.java +++ b/cameraproject/src/elements/DirectionalLight.java @@ -4,9 +4,24 @@ import primitives.Point3D; import primitives.Vector; +/** + * A class to hold a directional light, aka a light source from a given + * direction that doesn't attenuate. + */ public class DirectionalLight extends Light implements LightSource { + + /** + * The direction the light comes from + */ private Vector direction; + /** + * Constructor for the class directional light, sets the intensity and the + * direction of the light source. + * + * @param intensity of the light source + * @param direction of the light source + */ public DirectionalLight(Color intensity, Vector direction) { super(intensity); this.direction = direction.normalized(); diff --git a/cameraproject/src/elements/FlashLight.java b/cameraproject/src/elements/FlashLight.java index 87f531c..705595a 100644 --- a/cameraproject/src/elements/FlashLight.java +++ b/cameraproject/src/elements/FlashLight.java @@ -4,18 +4,39 @@ import primitives.Point3D; import primitives.Vector; +/** + * Flashlight is a light source that has a beam, which attenuates from the light + * source and the distance from the source. + */ public class FlashLight extends PointLight implements LightSource { + /** + * Direction of the lights' beam + */ private Vector direction; + /** + * The exponent of the attenuation of the beam. As we get farther from the beam, + * the attenuation of the light will follow, until 0 in which there will be no + * light. + */ private int exp; + /** + * Constructor that gets the intensity of the light, its' origins, the direction + * it goes at, and the exponent of the attenuation of the beam. + * + * @param intensity of the beam + * @param position of the beam + * @param direction of the beam + * @param exp of the beam + */ public FlashLight(Color intensity, Point3D position, Vector direction, int exp) { super(intensity, position); - if(exp<1) - throw new IllegalArgumentException("exp less then 1"); this.direction = direction.normalized(); this.exp = exp; - + if (exp < 1) // There is an assumption here, that a flash light narrows the beam. However, + // this is malleable. + throw new IllegalArgumentException("exp less then 1"); } @Override diff --git a/cameraproject/src/elements/Light.java b/cameraproject/src/elements/Light.java index beadf63..32139a4 100644 --- a/cameraproject/src/elements/Light.java +++ b/cameraproject/src/elements/Light.java @@ -6,7 +6,7 @@ import primitives.Color; /** - * + * An abstract class to provide the base of a light source */ abstract class Light { /** @@ -15,7 +15,9 @@ abstract class Light { private Color intensity; /** - * @param intensity + * Constructor to set the intensity of the light source + * + * @param intensity - The strength\intensity of the light */ protected Light(Color intensity) { this.intensity = intensity; diff --git a/cameraproject/src/elements/LightSource.java b/cameraproject/src/elements/LightSource.java index b63a671..5279f95 100644 --- a/cameraproject/src/elements/LightSource.java +++ b/cameraproject/src/elements/LightSource.java @@ -8,11 +8,24 @@ import primitives.Vector; /** - * + * An interface to have functions regarding the intensity of the light source + * and the vector it sends. */ public interface LightSource { + /** + * A function to return the lights intensity at a given point. + * + * @param p - The point we want the light's intensity of. + * @return the intensity of the light source at the given point + */ public Color getIntensity(Point3D p); + /** + * A function that returns a vector in which a light hits a given point. + * + * @param p - The point we want to know the vector of, as the light hits it. + * @return the vector of the light as it hits the given point. + */ public Vector getL(Point3D p); } diff --git a/cameraproject/src/elements/PointLight.java b/cameraproject/src/elements/PointLight.java index 62f6721..72328ee 100644 --- a/cameraproject/src/elements/PointLight.java +++ b/cameraproject/src/elements/PointLight.java @@ -8,13 +8,34 @@ import primitives.Vector; /** - * + * A class to hold a light source that originates at a given point. */ public class PointLight extends Light implements LightSource { + /** + * The position in which the light originates. + */ private Point3D position; - private double kC, kL, kQ; + /** + * The constant attenuation of the light. + */ + private double kC; + /** + * The linear attenuation of the light. + */ + private double kL; + /** + * The squared attenuation of the light. + */ + private double kQ; + /** + * A constructor that gets a base point, and assumes a constant attenuation of + * 1, at a given intensity. + * + * @param intensity of the light + * @param position in which the light originates + */ public PointLight(Color intensity, Point3D position) { super(intensity); this.position = position; @@ -24,6 +45,8 @@ public PointLight(Color intensity, Point3D position) { } /** + * Set the value of the constant attenuation variable (builder) + * * @param kC the kC to set */ public PointLight setKc(double kC) { @@ -32,6 +55,8 @@ public PointLight setKc(double kC) { } /** + * Set the value of the linear attenuation variable (builder) + * * @param kL the kL to set */ public PointLight setKl(double kL) { @@ -40,6 +65,8 @@ public PointLight setKl(double kL) { } /** + * Set the value of the squared attenuation variable (builder) + * * @param kQ the kQ to set */ public PointLight setKq(double kQ) { diff --git a/cameraproject/src/elements/SpotLight.java b/cameraproject/src/elements/SpotLight.java index a4c1a1e..5135d70 100644 --- a/cameraproject/src/elements/SpotLight.java +++ b/cameraproject/src/elements/SpotLight.java @@ -8,10 +8,20 @@ import primitives.Vector; /** - * + * A type of flashlight in which the light source is not affected by the + * attenuation from the beam itself, having the exponent of the beams + * attenuation 1. */ public class SpotLight extends FlashLight implements LightSource { + /** + * A constructor that gets the lights' intensity, location, and the general + * direction. + * + * @param intensity of the light + * @param position of the light + * @param direction of the light + */ public SpotLight(Color intensity, Point3D position, Vector direction) { super(intensity, position, direction, 1); } diff --git a/cameraproject/src/geometries/Geometry.java b/cameraproject/src/geometries/Geometry.java index 86df909..5122145 100644 --- a/cameraproject/src/geometries/Geometry.java +++ b/cameraproject/src/geometries/Geometry.java @@ -13,7 +13,7 @@ public abstract class Geometry implements Intersectable { private Color emission = Color.BLACK; /** - * ----------------- + * The material of which the object consists. */ private Material material = new Material(); @@ -27,16 +27,17 @@ public Color getEmission() { } /** - * ----------------------- + * Getter designed to convey the coefficients of the material which make the + * geometry. * - * @return + * @return the material of which the geometry consists */ public Material getMaterial() { return material; } /** - * Setter for the color of the geometric shape (builder) + * Setter for the color of the geometric shape (builder). * * @param emmission of the specific geometry * @return The object itself (the geometric shape) @@ -47,10 +48,10 @@ public Geometry setEmission(Color emission) { } /** - * --------------------------- + * Sets the material of which the geometry consists (builder). * - * @param material - * @return + * @param material in which the geometry consists + * @return The object itself (the geometric shape) */ public Geometry setMaterial(Material material) { this.material = material; @@ -58,7 +59,7 @@ public Geometry setMaterial(Material material) { } /** - * Get the normal to the surface + * Get the normal to the surface. * * @param point - A point3D on the geometric body * @return A normal vector to the body at this point diff --git a/cameraproject/src/primitives/Material.java b/cameraproject/src/primitives/Material.java index 175abf7..0f00c04 100644 --- a/cameraproject/src/primitives/Material.java +++ b/cameraproject/src/primitives/Material.java @@ -1,11 +1,26 @@ package primitives; +/** + * The material in which the object is made of, may effect the lighting of the + * scene. + */ public class Material { - public double kD, kS; + + /** + * The diffuse coefficient. + */ + public double kD; + /** + * The specular coefficient. + */ + public double kS; + /** + * The shininess coefficient. + */ public int nShininess; /** - * + * Constructor that sets the various coefficients to 0. */ public Material() { this.kD = 0; @@ -14,6 +29,8 @@ public Material() { } /** + * Sets diffuse coefficient. + * * @param kD the kD to set */ public Material setKd(double kD) { @@ -22,6 +39,8 @@ public Material setKd(double kD) { } /** + * Sets specular coefficient. + * * @param kS the kS to set */ public Material setKs(double kS) { @@ -30,6 +49,8 @@ public Material setKs(double kS) { } /** + * Sets shininess coefficient. + * * @param nShininess the nShininess to set */ public Material setShininess(int nShininess) { diff --git a/cameraproject/src/renderer/RayTracerBasic.java b/cameraproject/src/renderer/RayTracerBasic.java index c983837..73d8a26 100644 --- a/cameraproject/src/renderer/RayTracerBasic.java +++ b/cameraproject/src/renderer/RayTracerBasic.java @@ -26,22 +26,24 @@ public RayTracerBasic(Scene scene) { } /** - * Function to calculate the color of a point in the scene + * Function to calculate the color of a point in the scene. * * @param intersection - A point in the scene, which is on a geometric shape * @param ray - The ray from the camera that hit the above point * @return Color at the given point */ private Color calcColor(GeoPoint intersection, Ray ray) { - return scene.ambientLight.getIntensity().add(intersection.geometry.getEmission()).add(calcLocalEffects(intersection, ray)); + return scene.ambientLight.getIntensity().add(intersection.geometry.getEmission()) + .add(calcLocalEffects(intersection, ray)); } /** - * Add calculated light contribution from all light sources - * ------------------ - * @param intersection - * @param ray - * @return + * Add calculated light contribution from all light sources. + * + * @param intersection - A point in the scene, which is on a geometric shape + * @param ray - The ray from the camera that hit the above point + * @return The color of the geometry according to the local variables, such as + * the material and the light sources. */ private Color calcLocalEffects(GeoPoint intersection, Ray ray) { @@ -70,14 +72,15 @@ private Color calcLocalEffects(GeoPoint intersection, Ray ray) { } /** - * ----------------- + * Calculating the Color of the specular component of the object for the Phong + * model. * - * @param kS - * @param r - * @param v - * @param nShininess - * @param lightIntensity - * @return + * @param kS - The specular coefficient + * @param r - The reflection of the light + * @param v - The direction of the camera + * @param nShininess - The shininess of the object + * @param lightIntensity - The intensity of the light + * @return The total specular component of the current object. */ private Color calcSpecular(double kS, Vector r, Vector v, int nShininess, Color lightIntensity) { double vr = alignZero(0 - v.dotProduct(r)); @@ -88,12 +91,14 @@ private Color calcSpecular(double kS, Vector r, Vector v, int nShininess, Color } /** - * -------------------- + * Calculating the Color of the diffuse component of the object for the Phong + * model. * - * @param kD - * @param ln - * @param lightIntensity - * @return + * @param kD - The diffuse coefficient + * @param ln - The dot product of the lights' vector with the normal + * of the body + * @param lightIntensity - The intensity of the light + * @return The final diffuse component of the given object for the phong model. */ private Color calcDiffusive(double kD, double ln, Color lightIntensity) { return lightIntensity.scale(kD * Math.abs(ln)); diff --git a/cameraproject/src/scene/Scene.java b/cameraproject/src/scene/Scene.java index 76d35b8..1accb3c 100644 --- a/cameraproject/src/scene/Scene.java +++ b/cameraproject/src/scene/Scene.java @@ -32,7 +32,7 @@ public class Scene { */ public Geometries geometries; /** - * ------------------------------- + * List of all of the different light sources that are in the area of the scene. */ public List lights = new LinkedList(); @@ -81,10 +81,10 @@ public Scene setGeometries(Geometries geometries) { } /** - * ------------------------ + * Sets the various different lightings that may effect the scene. * - * @param lights - * @return + * @param lights - The lights that may effect the scene + * @return the scene, but with different lights. */ public Scene setLights(List lights) { this.lights = lights; diff --git a/cameraproject/src/unittests/elements/LightTests.java b/cameraproject/src/unittests/elements/LightTests.java index 0a7395c..861b77e 100644 --- a/cameraproject/src/unittests/elements/LightTests.java +++ b/cameraproject/src/unittests/elements/LightTests.java @@ -84,7 +84,7 @@ public void sphereSpot() { render.renderImage(); render.writeToImage(); } - + /** * Produce a picture of a sphere lighted by a flash light */ @@ -139,8 +139,6 @@ public void trianglesPoint() { render.renderImage(); render.writeToImage(); } - - /** * Produce a picture of a two triangles lighted by a spot light @@ -160,7 +158,7 @@ public void trianglesSpot() { render.renderImage(); render.writeToImage(); } - + /** * Produce a picture of a two triangles lighted by a flash light */ @@ -168,8 +166,9 @@ public void trianglesSpot() { public void trianglesFlash() { scene2.geometries.add(triangle1.setMaterial(new Material().setKd(0.5).setKs(0.5).setShininess(300)), triangle2.setMaterial(new Material().setKd(0.5).setKs(0.5).setShininess(300))); - scene2.lights.add(new FlashLight(new Color(500, 250, 250), new Point3D(10, -10, -130), new Vector(-2, -2, -1), 3) // - .setKl(0.0001).setKq(0.000005)); + scene2.lights + .add(new FlashLight(new Color(500, 250, 250), new Point3D(10, -10, -130), new Vector(-2, -2, -1), 3) // + .setKl(0.0001).setKq(0.000005)); ImageWriter imageWriter = new ImageWriter("lightTrianglesFlash", 500, 500); Render render = new Render()// @@ -179,21 +178,20 @@ public void trianglesFlash() { render.renderImage(); render.writeToImage(); } - + /** - * + * Produce a picture of a sphere lighted by multiple lights */ @Test public void sphereMultipleLightSources() { scene1.geometries.add(sphere); - + scene1.lights.add(new PointLight(new Color(500, 300, 0), new Point3D(-20, 50, -10))// .setKl(0.00001).setKq(0.000001)); scene1.lights.add(new DirectionalLight(new Color(450, 250, 300), new Vector(-1, 0, -1))); scene1.lights.add(new SpotLight(new Color(500, 300, 0), new Point3D(-20, -50, -10), new Vector(-2, 2, -1)) // .setKl(0.00001).setKq(0.00000001)); - - + ImageWriter imageWriter = new ImageWriter("sphereMultipleLightSources", 500, 500); Render render = new Render()// .setImageWriter(imageWriter) // @@ -202,15 +200,15 @@ public void sphereMultipleLightSources() { render.renderImage(); render.writeToImage(); } - + /** - * + * Produce a picture of a two triangles lighted by multiple lights */ @Test public void trianglesMultipleLightSources() { scene2.geometries.add(triangle1.setMaterial(new Material().setKd(0.5).setKs(0.5).setShininess(300)), triangle2.setMaterial(new Material().setKd(0.5).setKs(0.5).setShininess(300))); - + scene2.lights.add(new SpotLight(new Color(500, 250, 250), new Point3D(10, -10, -130), new Vector(-2, -2, -1)) // .setKl(0.0001).setKq(0.000005)); scene2.lights.add(new PointLight(new Color(500, 250, 250), new Point3D(50, 60, -130)) //