-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera3D.java
More file actions
103 lines (73 loc) · 2.28 KB
/
Copy pathCamera3D.java
File metadata and controls
103 lines (73 loc) · 2.28 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
package display3D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.util.Arrays;
/**
* projects a three dimensional point onto an orthographic 'billboard' surface
* @author Luke
*
*/
public class Camera3D {
//where the camera is in space
private Vect camLocation = new Vect(new double[]{ 1 , 1 , 1 });
//the point in space the camera is looking at
private Vect camFocus = new Vect(new double[]{ 0,0, 0});
//multiplier
private double multiplier = 100;
public double[] getDisplayCoords( double [] r ){
return this.getDisplayCoords(new Vect(r));
}
public double[] getDisplayCoords( Vect r ){
//offset by focus
r = r.sub( camFocus );
//two vectors orthogonal to the camera location based on the roll angle
//get cam X by z cross r
Vect camXVector = new Vect(0,0,1).cross( camLocation );
Vect camYVector = camLocation.cross( camXVector );
//normalise the camera vectors
camXVector = camXVector.normalise();
camYVector = camYVector.normalise();
double viewX = r.dot( camXVector );
double viewY = r.dot( camYVector );
return new double[]{ viewX*multiplier , viewY*multiplier };
}
public Vect[] getCamXYVectors(){
Vect camX = new Vect(0,0,1).cross( camLocation ).normalise();
Vect camY = camLocation.cross( camX ).normalise();
return new Vect[]{ camX , camY };
}
public Vect getLocation(){
return new Vect( camLocation );
}
public Vect getFocus(){
return new Vect( camFocus );
}
public double getZoom( ){
return multiplier;
}
public void setZoom( double multiplier ){
this.multiplier = multiplier;
}
public void setLocation( double ... location ){
if( location.length != 3 )
throw new IllegalArgumentException();
this.camLocation = new Vect(location);
}
public void setLocation( Vect location ){
this.camLocation = new Vect(location);
}
public void setFocus( double ... focus ){
if( focus.length != 3 )
throw new IllegalArgumentException();
this.camFocus = new Vect(focus);
}
public void setFocus( Vect focus ){
this.camFocus = new Vect(focus);
}
public void rotateTheta( double deltaTheta ){
setLocation( camLocation.rotateTheta(deltaTheta) );
}
public void rotatePhi( double deltaPhi ){
setLocation( camLocation.rotatePhi(deltaPhi) );
}
}