-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpotLight.java
More file actions
41 lines (30 loc) · 993 Bytes
/
Copy pathSpotLight.java
File metadata and controls
41 lines (30 loc) · 993 Bytes
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
package elements;
import primitives.Color;
import primitives.Point_3D;
import primitives.Vector;
public class SpotLight extends PointLight {
private Vector _direction;
// ***************** Constructors ********************** //
public SpotLight(Color color, Point_3D position, double kc, double kl, double kq, Vector direction) {
super(color, position, kc, kl, kq);
_direction = direction.normalize();
}
// ***************** Getters/Setters ********************** //
public Color color(){
return _color;
}
// ***************** Operations ******************** //
@Override
public Color getIntensity(Point_3D point) {
double angle = getD(point).dotProduct(getL(point));
return (angle < 0) ? new Color() : super.getIntensity(point).scale(angle);
}
@Override
public Vector getL(Point_3D point) {
return point.subtract(_position).normalize();
}
@Override
public Vector getD(Point_3D point) {
return _direction;
}
}