-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sphere.java
52 lines (43 loc) · 885 Bytes
/
Sphere.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import javax.vecmath.*;
public class Sphere implements SDF
{
private final double r;
private final Vector3d color;
private final double diffuseRatio;
private final double specularExp;
public Sphere(double r)
{
this.r = r;
this.color = new Vector3d(1.0, 1.0, 1.0);
this.diffuseRatio = 1.0;
this.specularExp = 0.0;
}
public Sphere(double r, Vector3d color, double diffuseRatio, double specularExp)
{
this.r = r;
this.color = color;
this.diffuseRatio = diffuseRatio;
this.specularExp = specularExp;
}
@Override
public double dist(Vector3d p)
{
var d = new Vector3d(p);
return d.length() - r;
}
@Override
public Vector3d getColor(Vector3d p)
{
return new Vector3d(color);
}
@Override
public double getDiffuseRatio(Vector3d p)
{
return diffuseRatio;
}
@Override
public double getSpecularExp(Vector3d p)
{
return specularExp;
}
}