/
ScreenToWorldSpaceNode.hx
74 lines (67 loc) · 1.6 KB
/
ScreenToWorldSpaceNode.hx
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
package armory.logicnode;
import iron.math.Vec4;
import iron.math.RayCaster;
class ScreenToWorldSpaceNode extends LogicNode {
public var property0: Bool; // Separator Out
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
var vInput: Vec4 = new Vec4();
vInput.x = inputs[0].get();
vInput.y = inputs[1].get();
var cam = iron.Scene.active.camera;
if (cam == null) return null;
// Separator Out
if (property0) {
switch (from) {
// World
case 0: {
return RayCaster.getRay(vInput.x, vInput.y, cam).origin;
}
// World X
case 1: {
return RayCaster.getRay(vInput.x, vInput.y, cam).origin.x;
}
// World Y
case 2: {
return RayCaster.getRay(vInput.x, vInput.y, cam).origin.y;
}
// World Z
case 3: {
return RayCaster.getRay(vInput.x, vInput.y, cam).origin.z;
}
// Direction
case 4: {
return RayCaster.getRay(vInput.x, vInput.y, cam).direction.normalize();
}
// Direction X
case 5: {
return RayCaster.getRay(vInput.x, vInput.y, cam).direction.normalize().x;
}
// Direction Y
case 6: {
return RayCaster.getRay(vInput.x, vInput.y, cam).direction.normalize().y;
}
// Direction Z
case 7: {
return RayCaster.getRay(vInput.x, vInput.y, cam).direction.normalize().z;
}
}
}
else
{
switch (from) {
// World
case 0: {
return RayCaster.getRay(vInput.x, vInput.y, cam).origin;
}
// Direction
case 1: {
return RayCaster.getRay(vInput.x, vInput.y, cam).direction.normalize();
}
}
}
return null;
}
}