forked from michaljaz/webmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerInInventory.js
More file actions
61 lines (56 loc) · 2.16 KB
/
PlayerInInventory.js
File metadata and controls
61 lines (56 loc) · 2.16 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
import * as THREE from "three";
class PlayerInInventory {
constructor(game) {
this.game = game;
this.renderer = new THREE.WebGLRenderer({
canvas: this.game.pcanvas,
PixelRatio: window.devicePixelRatio,
});
this.scene = new THREE.Scene();
this.scene.background = new THREE.Color("black");
var light = new THREE.AmbientLight(0xffffff);
this.scene.add(light);
var player = this.game.al.get("player");
var playerTex = this.game.al.get("playerTex");
playerTex.magFilter = THREE.NearestFilter;
player.children[0].material.map = playerTex;
this.scene.add(player);
this.camera = new THREE.PerspectiveCamera(70, 140 / 204, 0.1, 1000);
this.camera.rotation.order = "YXZ";
this.camera.position.z = 210;
this.camera.position.y = 120;
$(window).mousemove(function (z) {
var bottom, left, right, top, wych_x, wych_y, xoff, yoff;
xoff = z.pageX - window.innerWidth / 2 + 112;
yoff = z.pageY - window.innerHeight / 2 + 170;
left = xoff / (window.innerWidth / 2 - 112);
right = xoff / (window.innerWidth / 2 + 112);
top = yoff / (window.innerHeight / 2 - 170);
bottom = yoff / (window.innerHeight / 2 + 170);
wych_x = Math.PI / 3;
wych_y = Math.PI / 4;
if (xoff > 0) {
player.rotation.y = wych_x * right;
} else {
player.rotation.y = wych_x * left;
}
if (yoff > 0) {
return (player.children[1].children[0].children[2].children[0].children[0].rotation.x =
wych_y * bottom);
} else {
return (player.children[1].children[0].children[2].children[0].children[0].rotation.x =
wych_y * top);
}
});
}
render() {
return this.renderer.render(this.scene, this.camera);
}
show() {
return (this.game.pcanvas.style.display = "block");
}
hide() {
return (this.game.pcanvas.style.display = "none");
}
}
export { PlayerInInventory };