-
Notifications
You must be signed in to change notification settings - Fork 0
/
Translate.java
46 lines (39 loc) · 918 Bytes
/
Translate.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
import javax.vecmath.*;
// As each SDF object is centered at the origin, it would necessary to translate their SDF to move them around.
// This is actually done by moving the point inputted into the SDF towards the opposite direction.
public class Translate implements SDF
{
private final SDF sdf;
private final Vector3d trans;
public Translate(SDF sdf, Vector3d trans)
{
this.sdf = sdf;
this.trans = trans;
}
public Vector3d getTrans(Vector3d p)
{
var pTrans = new Vector3d(p);
pTrans.sub(trans);
return pTrans;
}
@Override
public double dist(Vector3d p)
{
return sdf.dist(getTrans(p));
}
@Override
public Vector3d getColor(Vector3d p)
{
return sdf.getColor(getTrans(p));
}
@Override
public double getDiffuseRatio(Vector3d p)
{
return sdf.getDiffuseRatio(getTrans(p));
}
@Override
public double getSpecularExp(Vector3d p)
{
return sdf.getSpecularExp(getTrans(p));
}
}