Normand Briere
2019-09-25 51e45bf615e1e2b4aca2edf9f7333b687c7d015e
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
//package comp557.a5;
 
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
 
public class Ray
{
 
    /** Originating point for the ray */
    public Point3d eyePoint = new Point3d(0, 0, 0);
    /** The direction of the ray */
    public Vector3d viewDirection = new Vector3d(0, 0, -1);
 
    /**
     * Default constructor.  Be careful not to use the ray before
     * setting the eye point and view direction!
     */
    public Ray()
    {
        // do nothing
    }
 
    /** 
     * Creates a new ray with the given eye point and view direction 
     * @param eyePoint
     * @param viewDirection
     */
    public Ray(Point3d eyePoint, Vector3d viewDirection)
    {
        this.eyePoint.set(eyePoint);
        this.viewDirection.set(viewDirection);
    }
 
    /**
     * Setup the ray.
     * @param eyePoint
     * @param viewDirection
     */
    public void set(Point3d eyePoint, Vector3d viewDirection)
    {
        this.eyePoint.set(eyePoint);
        this.viewDirection.set(viewDirection);
    }
 
    /**
     * Computes the location of a point along the ray using parameter t.
     * @param t
     * @param p
     */
    public void getPoint(double t, Point3d p)    // After the intersection, you will call this method to get the intersection point
    {
        p.scale(t, viewDirection);
        p.add(eyePoint);
    }
}