-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
158 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ target/ | |
!**/src/test/**/target/ | ||
|
||
image.ppm | ||
image.png | ||
|
||
### IntelliJ IDEA ### | ||
.idea/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
src/main/java/util/camera/BlurCamera.java → src/main/java/camera/BlurCamera.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/util/camera/Camera.java → src/main/java/camera/Camera.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package util.camera; | ||
package camera; | ||
|
||
import math.Ray; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/main/java/util/camera/ClearCamera.java → src/main/java/camera/ClearCamera.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package util.camera; | ||
package camera; | ||
|
||
import math.Point; | ||
import math.Ray; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package camera; | ||
|
||
import math.Ray; | ||
|
||
public class MotionBlurCamera implements Camera{ | ||
private final Camera camera; | ||
private final double shutterOpeningMoment; | ||
private final double shutterClosingMoment; | ||
|
||
public MotionBlurCamera(Camera camera, double shutterOpeningMoment, double shutterClosingMoment) { | ||
if(shutterClosingMoment < shutterOpeningMoment){ | ||
throw new IllegalArgumentException("shutterClosingMoment can`t be less then shutterOpeningMoment"); | ||
} | ||
this.camera = camera; | ||
this.shutterOpeningMoment = shutterOpeningMoment; | ||
this.shutterClosingMoment = shutterClosingMoment; | ||
} | ||
|
||
@Override | ||
public Ray getRay(double s, double t) { | ||
double shutterOpenMoment = (Math.random() * (shutterClosingMoment - shutterOpeningMoment)) + shutterOpeningMoment; | ||
return camera.getRay(s, t).setTimeMoment(shutterOpenMoment); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/java/util/material/Material.java → src/main/java/material/Material.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package util; | ||
package math; | ||
|
||
import java.util.Objects; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/java/util/Hittable.java → src/main/java/objects/Hittable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package objects; | ||
|
||
import math.Point; | ||
import math.Ray; | ||
import math.Vector; | ||
import math.Vectors; | ||
import util.HitRecord; | ||
import material.Material; | ||
|
||
public class MovingSphere implements Hittable{ | ||
private final Point centerStart; | ||
private final Point centerFinish; | ||
private final double timeStart; | ||
private final double timeFinish; | ||
private final double radius; | ||
private final Material material; | ||
|
||
public MovingSphere(Point centerStart, Point centerFinish, double radius, double timeStart, double timeFinish, Material material) { | ||
this.centerStart = centerStart; | ||
this.centerFinish = centerFinish; | ||
this.timeStart = timeStart; | ||
this.timeFinish = timeFinish; | ||
this.radius = radius; | ||
this.material = material; | ||
} | ||
|
||
@Override | ||
public boolean hit(Ray r, double tMin, double tMax, HitRecord rec) { | ||
Vector oc = new Vector(center(r.getTimeMoment()), r.getOrigin()); | ||
double A = r.getDirection().lengthSquared(); | ||
double halfB = Vectors.dot(oc, r.getDirection()); | ||
double C = oc.lengthSquared() - radius*radius; | ||
double discriminant = halfB*halfB - A*C; | ||
if(discriminant < 0d){ | ||
return false; | ||
} | ||
double sqrtd = Math.sqrt(discriminant); | ||
double root = (-halfB - sqrtd) / A; | ||
if (root < tMin || tMax < root) { | ||
root = (-halfB + sqrtd) / A; | ||
if (root < tMin || tMax < root) | ||
return false; | ||
} | ||
|
||
rec.setT(root); | ||
rec.setPoint(r.at(rec.getT())); | ||
Vector outwardNormal = new Vector(center(r.getTimeMoment()), rec.getPoint()).divide(radius); | ||
rec.setFaceNormal(r, outwardNormal); | ||
rec.setMaterial(this.material); | ||
return true; | ||
} | ||
|
||
private Point center(double time){ | ||
if(Math.abs(timeFinish - timeStart) <= 1e-10){ | ||
return centerStart; | ||
} | ||
return centerStart.move(new Vector(centerStart, centerFinish).multiply((time - timeStart)/(timeFinish - timeStart))); | ||
} | ||
|
||
} |
5 changes: 3 additions & 2 deletions
5
src/main/java/util/Sphere.java → src/main/java/objects/Sphere.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.