-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRelativeCameraAPI.js
More file actions
173 lines (153 loc) · 5.17 KB
/
RelativeCameraAPI.js
File metadata and controls
173 lines (153 loc) · 5.17 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
* <RELATIVE SCENES API>
* <VERSION: 1.0>
* <Git: https://github.com/Evanechecssss/RelativeScenesAPI>
*
* Author: ⚘'Ivan'⚘
* License: GNU General Public License v3
* Thanks:
* - McHorse for his mods
* - Creman for help with trigonometry
* - Oshi for everything
*/
var Math = Java.type("java.lang.Math");
var Vector3f = Java.type("javax.vecmath.Vector3f");
var Matrix3f = Java.type("javax.vecmath.Matrix3f");
var Camera = Java.type("mchorse.aperture.capabilities.camera.Camera");
var CameraUtils = Java.type("mchorse.aperture.camera.CameraUtils");
/**
* @param {java.lang.String} name
* @param {net.minecraft.entity.player.EntityPlayer} player
*/
function RunCamera(name, player) {
CameraUtils.sendProfileToPlayer(name, player, true, true);
}
function CameraMove(fixtures, params) {
return FixturesMove(fixtures, params.x, params.y, params.z);
}
function CameraRotate(fixtures, params) {
return FixturesRotate(fixtures, params.yaw, params.pitch);
}
function CameraCopy(fixtures, params) {
return fixtures;
}
function ChangeCamera(profileName, saveName, fun, params) {
var profile = JSON.parse(CameraUtils.readCameraProfile(profileName));
var fixtures = profile.fixtures;
profile.fixtures = fun(fixtures, params);
CameraUtils.writeCameraProfile(saveName, JSON.stringify(profile, null, 2));
}
function RotatePoint(root, offset, yaw, pitch) {
var point = new Vector3f(root);
var vector = _rotate(offset, yaw, pitch);
point.x += vector.x;
point.y += vector.y;
point.z += vector.z;
return point;
}
function _rotate(vector, yaw, pitch) {
var a = new Matrix3f();
var b = new Matrix3f();
a.rotY(yaw / 180 * Math.PI);
b.rotX(pitch / 180 * Math.PI);
a.mul(b);
a.transform(vector);
return vector;
}
function FixturesRotate(fixtures, yaw, pitch) {
var root = null;
var callback = [];
for (var i = 0; i < fixtures.length; i++) {
var fixture = fixtures[i];
var points = extractPoints(fixture);
for (var j = 0; j < points.length; j++) {
var point = points[j];
if (root != null) {
var delta = new Vector3f(point.x - root.x, point.y - root.y, point.z - root.z);
var rootv = new Vector3f(root.x, root.y, root.z);
var rotated = RotatePoint(rootv, delta, yaw, pitch);
point.x = rotated.x;
point.y = rotated.y;
point.z = rotated.z;
}
root = setRootPoint(root, point);
}
callback.push(insertPoints(fixture, points));
}
return callback;
}
function FixturesMove(fixtures, x, y, z) {
var root = null;
var callback = [];
for (var i = 0; i < fixtures.length; i++) {
var fixture = fixtures[i];
var points = extractPoints(fixture);
for (var j = 0; j < points.length; j++) {
var point = points[j];
root = setRootPoint(root, point);
point.x = x + (point.x - root.x);
point.y = y + (point.y - root.y);
point.z = z + (point.z - root.z);
}
callback.push(insertPoints(fixture, points));
}
return callback;
}
function extractPoints(fixture) {
var points = [];
var type = fixture.type;
if (type === "path") {
for (var i = 0; i < fixture.points.length; i++) {
var rawpoint = fixture.points[i];
var point = rawpoint.point;
points.push(new Vector3f(point.x, point.y, point.z));
}
} else if (type === "idle") {
var point = fixture.position.point;
points.push(new Vector3f(point.x, point.y, point.z));
} else if (type === "circular") {
var point = fixture.start;
points.push(new Vector3f(point.x, point.y, point.z));
} else if (type === "dolly") {
var point = fixture.position.point;
points.push(new Vector3f(point.x, point.y, point.z));
}
return points;
}
function insertPoints(fixture, points) {
var type = fixture.type;
if (type === "path") {
for (var i = 0; i < fixture.points.length && i < points.length; i++) {
fixture.points[i].point.x = points[i].x;
fixture.points[i].point.y = points[i].y;
fixture.points[i].point.z = points[i].z;
}
} else if (type === "idle") {
fixture.position.point.x = points[0].x;
fixture.position.point.y = points[0].y;
fixture.position.point.z = points[0].z;
} else if (type === "circular") {
fixture.start.x = points[0].x;
fixture.start.y = points[0].y;
fixture.start.z = points[0].z;
} else if (type === "dolly") {
fixture.position.point.x = points[0].x;
fixture.position.point.y = points[0].y;
fixture.position.point.z = points[0].z;
}
return fixture;
}
function ClearCash(name, players) {
for (var i in players) {
var camera = Camera.get(players[i]);
camera.setCurrentProfile(name);
camera.setCurrentProfileTimestamp(-1);
CameraUtils.sendProfileToPlayer(name, players[i], false, false);
}
}
function setRootPoint(root, point) {
if (root == null) {
root = new Vector3f(point.x, point.y, point.z);
}
return root;
}