-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rotate.java
59 lines (50 loc) · 1.46 KB
/
Rotate.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
53
54
55
56
57
58
59
import javax.vecmath.*;
// Rotate around three axes by three angles counterclockwise.
public class Rotate implements SDF
{
public final SDF sdf;
private final Matrix3d rot;
public Rotate(SDF sdf, Vector3d by)
{
this.sdf = sdf;
by.scale(-1); // Reverse the rotation angle, as we are rotating the world coordinates when calculating the distance
var rotX = new Matrix3d(new double[] {1, 0, 0,
0, Math.cos(by.x), -Math.sin(by.x),
0, Math.sin(by.x), Math.cos(by.x)});
var rotY = new Matrix3d(new double[] {Math.cos(by.y), 0, Math.sin(by.y),
0, 1, 0,
-Math.sin(by.y), 0, Math.cos(by.y)});
var rotZ = new Matrix3d(new double[] {Math.cos(by.z), -Math.sin(by.z), 0,
Math.sin(by.z), Math.cos(by.z), 0,
0, 0, 1});
rot = rotX;
rot.mul(rotY);
rot.mul(rotZ);
}
public Vector3d getRot(Vector3d p)
{
var pRot = new Vector3d(p);
rot.transform(pRot);
return pRot;
}
@Override
public double dist(Vector3d p)
{
return sdf.dist(getRot(p));
}
@Override
public Vector3d getColor(Vector3d p)
{
return sdf.getColor(getRot(p));
}
@Override
public double getDiffuseRatio(Vector3d p)
{
return sdf.getDiffuseRatio(getRot(p));
}
@Override
public double getSpecularExp(Vector3d p)
{
return sdf.getSpecularExp(getRot(p));
}
}