@@ -93,3 +93,83 @@ class FlyingCamera extends Animatable
9393 momentum.lerp ( right, amount);
9494 }
9595}
96+
97+ class FPSCamera extends Animatable
98+ {
99+ Camera camera;
100+ Vector momentum = new Vector ();
101+ Vector movement = new Vector ();
102+ Vector tmp = new Vector ();
103+
104+ Vector traceStart = new Vector ();
105+ Vector traceEnd = new Vector ();
106+
107+ Vector up = new Vector (0.0 ,0.0 ,1.0 );
108+
109+ int movementX= 0 ;
110+ int movementY= 0 ;
111+
112+ FPSCamera ( this .camera) {
113+
114+ HTML .document.onMouseDown.listen ( (HTML .MouseEvent e) {
115+ e.preventDefault ();
116+ HTML .document.body.requestPointerLock ();
117+ });
118+
119+ HTML .document.body.onMouseMove.listen ( (HTML .MouseEvent e) {
120+ e.preventDefault ();
121+ movementX += e.movement.x;
122+ movementY += e.movement.y;
123+ });
124+
125+ }
126+
127+ void animate ( double elapsed)
128+ {
129+ Map <int , bool > cpk = currentlyPressedKeys;
130+ Map <String , bool > cpmb = currentlyPressedMouseButtons;
131+
132+ movement.scale (0 );
133+
134+ if (cpk[Key .W ] != null ) {
135+ movement.subtract ( camera.getBack () );
136+ }
137+ if (cpk[Key .A ] != null ) {
138+ movement.subtract ( camera.getRight () );
139+ }
140+ if (cpk[Key .S ] != null ) {
141+ movement.add ( camera.getBack () );
142+ }
143+ if (cpk[Key .D ] != null ) {
144+ movement.add ( camera.getRight () );
145+ }
146+
147+ movement.z = 0.0 ;
148+ movement.normalize ();
149+ momentum.add (movement);
150+ tmp.set (momentum);
151+ tmp.scale (0.02 );
152+
153+ traceStart.set (camera.getPos ());
154+ traceEnd.set (camera.getPos ());
155+ traceEnd.add (tmp);
156+
157+ //Output output = level.trace( traceStart, traceEnd, 10.0);
158+ //if( output.fraction == 1.0 || output.startSolid || output.allSolid )
159+
160+ camera.translateFromVec (tmp);
161+ momentum.scale ( 0.85 );
162+
163+ if ( cpk[Key .SPACE ] != null ) {
164+ }
165+
166+ if ( movementY!= 0 )
167+ camera.matrix.rotate ( movementY* 0.006 , camera.getRight ());
168+ if ( movementX!= 0 )
169+ camera.matrix.rotate ( movementX* 0.006 , up);
170+
171+ movementX= 0 ;
172+ movementY= 0 ;
173+ }
174+
175+ }
0 commit comments