@@ -110,8 +110,6 @@ <h3>Gra zatrzymana</h3>
110110import { BufferGeometryUtils } from 'https://threejs.org/examples/jsm/utils/BufferGeometryUtils.js' ;
111111import Stats from 'https://threejs.org/examples/jsm/libs/stats.module.js' ;
112112import { FBXLoader } from 'https://threejs.org/examples/jsm/loaders/FBXLoader.js' ;
113- import { FirstPersonControls } from './js/fpc.module.js?123' ;
114-
115113
116114class Terrain {
117115 constructor ( options ) {
@@ -498,6 +496,67 @@ <h3>Gra zatrzymana</h3>
498496 }
499497}
500498
499+ class FirstPersonControls {
500+ constructor ( options ) {
501+ this . kc = {
502+ "w" : 87 ,
503+ "s" : 83 ,
504+ "a" : 65 ,
505+ "d" : 68 ,
506+ "space" : 32 ,
507+ "shift" : 16
508+ } ;
509+ this . keys = { }
510+ this . canvas = options . canvas
511+ this . camera = options . camera ;
512+ this . micromove = options . micromove
513+ }
514+ ac ( qx , qy , qa , qf ) {
515+ var m_x = - Math . sin ( qa ) * qf ;
516+ var m_y = - Math . cos ( qa ) * qf ;
517+ var r_x = qx - m_x ;
518+ var r_y = qy - m_y ;
519+ return {
520+ x : r_x ,
521+ y : r_y
522+ } ;
523+ }
524+ degtorad ( deg ) {
525+ return deg * Math . PI / 180 ;
526+ }
527+ radtodeg ( rad ) {
528+ return rad * 180 / Math . PI ;
529+ }
530+ camMicroMove ( ) {
531+ // console.log(this.micromove)
532+ if ( this . keys [ this . kc [ "w" ] ] ) {
533+ this . camera . position . x = this . ac ( this . camera . position . x , this . camera . position . z , this . camera . rotation . y + this . degtorad ( 180 ) , this . micromove ) . x ;
534+ this . camera . position . z = this . ac ( this . camera . position . x , this . camera . position . z , this . camera . rotation . y + this . degtorad ( 180 ) , this . micromove ) . y ;
535+ }
536+ if ( this . keys [ this . kc [ "s" ] ] ) {
537+ this . camera . position . x = this . ac ( this . camera . position . x , this . camera . position . z , this . camera . rotation . y , this . micromove ) . x ;
538+ this . camera . position . z = this . ac ( this . camera . position . x , this . camera . position . z , this . camera . rotation . y , this . micromove ) . y ;
539+ }
540+ if ( this . keys [ this . kc [ "a" ] ] ) {
541+ this . camera . position . x = this . ac ( this . camera . position . x , this . camera . position . z , this . camera . rotation . y - this . degtorad ( 90 ) , this . micromove ) . x ;
542+ this . camera . position . z = this . ac ( this . camera . position . x , this . camera . position . z , this . camera . rotation . y - this . degtorad ( 90 ) , this . micromove ) . y ;
543+ }
544+ if ( this . keys [ this . kc [ "d" ] ] ) {
545+ this . camera . position . x = this . ac ( this . camera . position . x , this . camera . position . z , this . camera . rotation . y + this . degtorad ( 90 ) , this . micromove ) . x ;
546+ this . camera . position . z = this . ac ( this . camera . position . x , this . camera . position . z , this . camera . rotation . y + this . degtorad ( 90 ) , this . micromove ) . y ;
547+ }
548+ if ( this . keys [ this . kc [ "space" ] ] ) {
549+ this . camera . position . y += this . micromove ;
550+ }
551+ if ( this . keys [ this . kc [ "shift" ] ] ) {
552+ this . camera . position . y -= this . micromove ;
553+ }
554+ }
555+ lockPointer ( ) {
556+ this . canvas . requestPointerLock ( )
557+ }
558+ }
559+
501560
502561var canvas , renderer , scene , camera , stats , raycaster ,
503562 gameState , stairsGeometry , world , selected , positionQ , cube , FPC ;
@@ -524,13 +583,13 @@ <h3>Gra zatrzymana</h3>
524583
525584 var ambientLight = new THREE . AmbientLight ( 0xcccccc ) ;
526585 scene . add ( ambientLight ) ;
527- var directionalLight = new THREE . DirectionalLight ( 0x666666 , 2 ) ;
586+ var directionalLight = new THREE . DirectionalLight ( 0x333333 , 2 ) ;
528587 directionalLight . position . set ( 1 , 1 , 0.5 ) . normalize ( ) ;
529588 scene . add ( directionalLight ) ;
530589
531590 raycaster = new THREE . Raycaster ( ) ;
532591
533- var texture = new THREE . TextureLoader ( ) . load ( 'atla.png' ) ;
592+ var texture = new THREE . TextureLoader ( ) . load ( 'assets/textures/ atla.png' ) ;
534593 texture . magFilter = THREE . NearestFilter ;
535594
536595 gameState = "menu" ;
@@ -654,7 +713,6 @@ <h3>Gra zatrzymana</h3>
654713 } )
655714}
656715
657-
658716function precision ( number ) {
659717 try {
660718 var precision = ( number + "" ) . split ( "." ) [ 1 ] . length ;
@@ -665,7 +723,6 @@ <h3>Gra zatrzymana</h3>
665723 return precision ;
666724}
667725
668-
669726function raycast ( ) {
670727 raycaster . setFromCamera ( { x :0 , y :0 } , camera ) ;
671728 var intersects = raycaster . intersectObjects ( scene . children ) ;
@@ -735,7 +792,6 @@ <h3>Gra zatrzymana</h3>
735792 }
736793}
737794
738-
739795function animate ( ) {
740796 stats . begin ( ) ;
741797 render ( )
0 commit comments