|
| 1 | +import * as THREE from './build/three.module.js' |
| 2 | +class PlayerInInventory |
| 3 | + constructor:(options)-> |
| 4 | + @canvas=options.canvas |
| 5 | + @al=options.al |
| 6 | + @renderer=new THREE.WebGLRenderer { |
| 7 | + canvas:@canvas |
| 8 | + PixelRatio:window.devicePixelRatio |
| 9 | + } |
| 10 | + @scene=new THREE.Scene |
| 11 | + @scene.background = new THREE.Color "black" |
| 12 | + light = new THREE.AmbientLight( 0xffffff ) |
| 13 | + @scene.add( light ); |
| 14 | + |
| 15 | + player=@al.get "player" |
| 16 | + playerTex=@al.get "playerTex" |
| 17 | + |
| 18 | + playerTex.magFilter=THREE.NearestFilter; |
| 19 | + player.children[0].material.map=playerTex; |
| 20 | + @scene.add( player ) |
| 21 | + @camera = new THREE.PerspectiveCamera 70, 140/204, 0.1, 1000 |
| 22 | + @camera.rotation.order="YXZ" |
| 23 | + @camera.position.z = 210 |
| 24 | + @camera.position.y = 120 |
| 25 | + $(window).mousemove (z)-> |
| 26 | + xoff=z.pageX-window.innerWidth/2+112 |
| 27 | + yoff=z.pageY-window.innerHeight/2+170 |
| 28 | + left=xoff/(window.innerWidth/2-112) |
| 29 | + right=xoff/(window.innerWidth/2+112) |
| 30 | + top=yoff/(window.innerHeight/2-170) |
| 31 | + bottom=yoff/(window.innerHeight/2+170) |
| 32 | + wych_x=Math.PI/3 |
| 33 | + wych_y=Math.PI/4 |
| 34 | + if xoff>0 |
| 35 | + player.rotation.y=wych_x*right |
| 36 | + else |
| 37 | + player.rotation.y=wych_x*left |
| 38 | + if yoff>0 |
| 39 | + player.children[1].children[0].children[2].children[0].children[0].rotation.x=wych_y*bottom |
| 40 | + else |
| 41 | + player.children[1].children[0].children[2].children[0].children[0].rotation.x=wych_y*top |
| 42 | + render:()-> |
| 43 | + @renderer.render @scene, @camera |
| 44 | + show:()-> |
| 45 | + @canvas.style.display="block" |
| 46 | + hide:()-> |
| 47 | + @canvas.style.display="none" |
| 48 | +export {PlayerInInventory} |
0 commit comments