-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRay.java
47 lines (38 loc) · 1.16 KB
/
Ray.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
package rayCast;
public class Ray {
private Vector vector;
private Vector point;
public int rec=0;
public Ray(Vector vector, Vector point){
this.vector = vector.norm();
this.point = point;
}
public Ray(Vector vector, Vector point,int rec){
this(vector,point);
this.rec = rec;
}
public Ray(Camera camera, double i, double j,int w,int h){
double d = camera.getScreenDist();
double wTheta = camera.getWTheat();
double hTheta = camera.getHTheta();
Vector forwared = camera.getDirection();
Vector up = camera.getUpDirection();
Vector right = forwared.cross(up);
Vector p1 = forwared.MultScalar(d);
double dtant =d*Math.tan(wTheta);
double dtanth =d*Math.tan(hTheta);
p1 =p1.sub(right.MultScalar(dtant));
p1=p1.add(up.MultScalar(dtanth));
Vector dir = p1.add(right.MultScalar(((double)i/(0.5*(double)w) -0.5 )*2*dtant));
dir = dir.sub(up.MultScalar(((double)j/(0.5*(double)h) -0.5)*2*dtanth));
dir = dir.norm();
this.vector = dir;
this.point = camera.getEye();
}
public Vector getStartPoint(){
return this.point;
}
public Vector getDirection(){
return this.vector;
}
}