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
67 lines (62 loc) · 2.2 KB
/
PlayerInInventory.js
File metadata and controls
67 lines (62 loc) · 2.2 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
import {
WebGLRenderer,
Scene,
Color,
AmbientLight,
NearestFilter,
PerspectiveCamera,
} from "three";
class PlayerInInventory {
constructor(game) {
this.game = game;
this.renderer = new WebGLRenderer({
canvas: this.game.pcanvas,
PixelRatio: window.devicePixelRatio,
});
this.scene = new Scene();
this.scene.background = new Color("black");
const light = new AmbientLight(0xffffff);
this.scene.add(light);
const player = this.game.al.get("player");
const playerTex = this.game.al.get("playerTex");
playerTex.magFilter = NearestFilter;
player.children[0].material.map = playerTex;
this.scene.add(player);
this.camera = new 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) {
const xoff = z.pageX - window.innerWidth / 2 + 112;
const yoff = z.pageY - window.innerHeight / 2 + 170;
const left = xoff / (window.innerWidth / 2 - 112);
const right = xoff / (window.innerWidth / 2 + 112);
const top = yoff / (window.innerHeight / 2 - 170);
const bottom = yoff / (window.innerHeight / 2 + 170);
const wych_x = Math.PI / 3;
const 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 };