@@ -2,13 +2,14 @@ import ControlsNavigator from "./ControlsNavigator";
22import Vec3 from "~/lib/math/Vec3" ;
33import Config from "../Config" ;
44import MathUtils from "~/lib/math/MathUtils" ;
5- import { ControlsState } from "../systems/ControlsSystem" ;
5+ import ControlsSystem , { ControlsState } from "../systems/ControlsSystem" ;
66import PerspectiveCamera from "~/lib/core/PerspectiveCamera" ;
77import TerrainHeightProvider from "~/app/terrain/TerrainHeightProvider" ;
88
99export default class FreeControlsNavigator extends ControlsNavigator {
1010 private readonly terrainHeightProvider : TerrainHeightProvider ;
1111 private readonly camera : PerspectiveCamera ;
12+ private readonly parent : ControlsSystem
1213 private pitch : number = MathUtils . toRad ( 45 ) ;
1314 private yaw : number = MathUtils . toRad ( 0 ) ;
1415 private forwardKeyPressed : boolean = false ;
@@ -21,16 +22,19 @@ export default class FreeControlsNavigator extends ControlsNavigator {
2122 private yawMinusKeyPressed : boolean = false ;
2223 private yawPlusKeyPressed : boolean = false ;
2324 private pointerLocked : boolean = false ;
25+ private bikeMode : boolean = false ;
2426
2527 public constructor (
2628 element : HTMLElement ,
2729 camera : PerspectiveCamera ,
28- terrainHeightProvider : TerrainHeightProvider
30+ terrainHeightProvider : TerrainHeightProvider ,
31+ parent : ControlsSystem
2932 ) {
3033 super ( element ) ;
3134
3235 this . camera = camera ;
3336 this . terrainHeightProvider = terrainHeightProvider ;
37+ this . parent = parent ;
3438
3539 this . addEventListeners ( ) ;
3640 }
@@ -107,6 +111,9 @@ export default class FreeControlsNavigator extends ControlsNavigator {
107111 case 'KeyF' :
108112 this . pitchPlusKeyPressed = true ;
109113 break ;
114+ case 'KeyB' :
115+ this . parent . switchBikeMode ( ) ;
116+ break ;
110117 }
111118 }
112119
@@ -216,11 +223,18 @@ export default class FreeControlsNavigator extends ControlsNavigator {
216223 } ;
217224 }
218225
226+ public setBikeMode ( bikeMode : boolean ) : void {
227+ this . bikeMode = bikeMode ;
228+ }
229+
219230 public update ( deltaTime : number ) : void {
220231 const mat = this . camera . matrixWorld . values ;
221232 const forwardDir = Vec3 . normalize ( new Vec3 ( mat [ 8 ] , mat [ 9 ] , mat [ 10 ] ) ) ;
222233 const rightDir = Vec3 . normalize ( new Vec3 ( mat [ 0 ] , mat [ 1 ] , mat [ 2 ] ) ) ;
223- const speed = this . fastMovementKeyPressed ? Config . FreeCameraSpeedFast : Config . FreeCameraSpeed ;
234+ const fastSpeed = this . bikeMode ? Config . BikeCameraSpeedFast : Config . FreeCameraSpeedFast ;
235+ const slowSpeed = this . bikeMode ? Config . BikeCameraSpeed : Config . FreeCameraSpeed ;
236+
237+ const speed = this . fastMovementKeyPressed ? fastSpeed : slowSpeed ;
224238
225239 let movementDelta = new Vec3 ( ) ;
226240 if ( this . forwardKeyPressed ) {
@@ -242,7 +256,12 @@ export default class FreeControlsNavigator extends ControlsNavigator {
242256 this . camera . position . z += movementDelta . z ;
243257
244258 const heightmapValue = this . getHeightmapValueAtPosition ( this . camera . position . x , this . camera . position . z ) ;
245- this . camera . position . y = Math . max ( this . camera . position . y , heightmapValue + Config . MinFreeCameraHeight ) ;
259+ if ( this . bikeMode ) {
260+ this . camera . position . y = heightmapValue + Config . FreeCameraBikeHeight ;
261+ } else {
262+ this . camera . position . y = Math . max ( this . camera . position . y , heightmapValue + Config . MinFreeCameraHeight ) ;
263+ }
264+
246265
247266 this . camera . updateMatrix ( ) ;
248267
0 commit comments