forked from phu004/JavaRTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTurn2DTo3DFactory.java
More file actions
75 lines (52 loc) · 1.4 KB
/
Copy pathTurn2DTo3DFactory.java
File metadata and controls
75 lines (52 loc) · 1.4 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
package core;
//takes a pixel position from a rasterized polygon and find its 3D location in world space
public class Turn2DTo3DFactory {
public vector O, U, V, W, A, B, C;
public vector location3D;
public float X, Y;
public void init(){
O = new vector(0,0,0);
U = new vector(0,0,0);
V = new vector(0,0,0);
W = new vector(0,0,0);
A = new vector(0,0,0);
B = new vector(0,0,0);
C = new vector(0,0,0);
location3D = new vector(0,0,0);
}
public vector get3DLocation(polygon3D poly, int x, int y){
O.set(poly.origin);
O.subtract(camera.position);
O.rotate_XZ(camera.XZ_angle);
O.rotate_YZ(camera.YZ_angle);
U.set(poly.rightEnd);
U.subtract(camera.position);
U.rotate_XZ(camera.XZ_angle);
U.rotate_YZ(camera.YZ_angle);
V.set(poly.bottomEnd);
V.subtract(camera.position);
V.rotate_XZ(camera.XZ_angle);
V.rotate_YZ(camera.YZ_angle);
U.subtract(O);
U.unit();
V.subtract(O);
V.unit();
A.cross(V,O);
B.cross(O,U);
C.cross(U,V);
W.set(x-384, -y + 256, 650);
X = A.dot(W)/C.dot(W);
Y = B.dot(W)/C.dot(W);
O.set(poly.origin);
U.set(poly.rightEnd);
V.set(poly.bottomEnd);
U.subtract(O);
V.subtract(O);
X/=(U.getLength());
Y/=(V.getLength());
location3D.set(O);
location3D.add(U, X);
location3D.add(V, Y);
return location3D;
}
}