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
68 lines (63 loc) · 1.95 KB
/
PlayerInInventory.js
File metadata and controls
68 lines (63 loc) · 1.95 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
import {
WebGLRenderer,
Scene,
Color,
AmbientLight,
NearestFilter,
PerspectiveCamera
} from 'three'
import $ from 'jquery'
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 wychX = Math.PI / 3
const wychY = Math.PI / 4
if (xoff > 0) {
player.rotation.y = wychX * right
} else {
player.rotation.y = wychY * left
}
if (yoff > 0) {
return (player.children[1].children[0].children[2].children[0].children[0].rotation.x =
wychY * bottom)
} else {
return (player.children[1].children[0].children[2].children[0].children[0].rotation.x =
wychX * 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 }