Skip to content

Commit

Permalink
all javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
nevcohen committed May 17, 2021
1 parent ff6c268 commit 58eab4a
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 58 deletions.
4 changes: 2 additions & 2 deletions cameraproject/src/elements/AmbientLight.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
15 changes: 15 additions & 0 deletions cameraproject/src/elements/DirectionalLight.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
27 changes: 24 additions & 3 deletions cameraproject/src/elements/FlashLight.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions cameraproject/src/elements/Light.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import primitives.Color;

/**
*
* An abstract class to provide the base of a light source
*/
abstract class Light {
/**
Expand All @@ -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;
Expand Down
15 changes: 14 additions & 1 deletion cameraproject/src/elements/LightSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
31 changes: 29 additions & 2 deletions cameraproject/src/elements/PointLight.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
12 changes: 11 additions & 1 deletion cameraproject/src/elements/SpotLight.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
17 changes: 9 additions & 8 deletions cameraproject/src/geometries/Geometry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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)
Expand All @@ -47,18 +48,18 @@ 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;
return this;
}

/**
* 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
Expand Down
25 changes: 23 additions & 2 deletions cameraproject/src/primitives/Material.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,6 +29,8 @@ public Material() {
}

/**
* Sets diffuse coefficient.
*
* @param kD the kD to set
*/
public Material setKd(double kD) {
Expand All @@ -22,6 +39,8 @@ public Material setKd(double kD) {
}

/**
* Sets specular coefficient.
*
* @param kS the kS to set
*/
public Material setKs(double kS) {
Expand All @@ -30,6 +49,8 @@ public Material setKs(double kS) {
}

/**
* Sets shininess coefficient.
*
* @param nShininess the nShininess to set
*/
public Material setShininess(int nShininess) {
Expand Down
43 changes: 24 additions & 19 deletions cameraproject/src/renderer/RayTracerBasic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down
Loading

0 comments on commit 58eab4a

Please sign in to comment.