-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlane.java
More file actions
112 lines (100 loc) · 2.83 KB
/
Plane.java
File metadata and controls
112 lines (100 loc) · 2.83 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import java.awt.Color;
import java.util.ArrayList;
/**
* Object3D that is a plane parallel to the XY, YZ, or XZ axis.
*/
public class Plane implements Object3D {
private Vector normal;
private Vertex onPlane;
private Material material;
/**
* Constructor that creates a plane with the given normal and point on the
* plane. The normal must in the direction of the X, Y, or Z axis.
*
* @param normal
* The normal vector to the plane.
* @param onPlane
* A point on the plane.
*/
public Plane(Vector normal, Vertex onPlane) {
this.normal = normal;
this.onPlane = onPlane;
}
/**
* Calculates the distance between the plane and the given vertex.
*
* @param vertex
* The vertex to calculate the distance from.
* @return The distance.
*/
@Override
public double distanceFrom(Vertex vertex) {
if (normal.getX() * Math.abs(vertex.getX() - onPlane.getX())
+ normal.getY() * Math.abs(vertex.getY() - onPlane.getY())
+ normal.getZ() * Math.abs(vertex.getZ() - onPlane.getZ()) < 0.01) {
return 0;
}
return normal.getX() * Math.abs(vertex.getX() - onPlane.getX())
+ normal.getY() * Math.abs(vertex.getY() - onPlane.getY())
+ normal.getZ() * Math.abs(vertex.getZ() - onPlane.getZ());
}
/**
* Translates the plane by some amount in the X, Y, and Z.
*
* @param xAmt
* The amount to translate along the X axis.
* @param yAmt
* The amount to translate along the Y axis.
* @param zAmt
* The amount to translate along the Z axis.
*/
@Override
public void translateXYZ(double xAmt, double yAmt, double zAmt) {
onPlane.setPosition(onPlane.getX() + xAmt, onPlane.getY() + yAmt, onPlane.getZ() + zAmt);
}
/**
* Gets the color at a point on the plane based on the material assigned to the
* plane.
*
* @param toColor
* The position on the plane to get the color of.
* @param position
* The position of the camera.
* @param lightSource
* The position of the light source.
* @param objects
* The ArrayList of object3ds in the scene.
* @return The color for the vertex toColor.
*/
public Color getColor(Vertex toColor, Vertex position, Vertex lightSource, ArrayList<Object3D> objects) {
return material.getColor(toColor, position, lightSource, objects, normal);
}
/**
* Gets the normal vector.
*
* @return The normal vector.
*/
public Vector getNormal() {
return normal;
}
/**
* Gets a point on the plane.
*
* @return The point on the plane.
*/
public Vertex getVertex() {
return onPlane;
}
@Override
public void rotate(Vector a, double angle) {
}
/**
* Sets the material of the plane.
*
* @param material
* The material the plane is set to.
*/
public void setMaterial(Material material) {
this.material = material;
}
}