Commits

Roi Atalla committed ca80c02

Press 'M' to grab/ungrab the mouse.

  • Participants
  • Parent commits d79e284

Comments (0)

Files changed (1)

File src/main/java/com/ra4king/opengl/test/Test.java

 	}
 	
 	public Test() {
-		super(true);//"Test",800,600,true);
+		super("Test",1024,768,true);
 		
 		Mouse.setGrabbed(true);
 	}
 		float turnSpeed = (float)Math.PI * delta;
 		float moveSpeed = (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) ? 100 : 50) * delta;
 		
-		angle += turnSpeed * Mouse.getDX() / 20f;
-		angleY -= turnSpeed * Mouse.getDY() / 20f;
+		if(Mouse.isGrabbed()) {
+			angle += turnSpeed * Mouse.getDX() / 20f;
+			angleY -= turnSpeed * Mouse.getDY() / 20f;
+		}
 		
 		if(Keyboard.isKeyDown(Keyboard.KEY_A))
 			position.add((float)Math.cos(angle+Math.PI)*moveSpeed, 0, (float)Math.sin(angle+Math.PI)*moveSpeed);
 	}
 	
 	@Override
+	public void keyPressed(int key, char c, long nanos) {
+		if(key == Keyboard.KEY_M)
+			Mouse.setGrabbed(!Mouse.isGrabbed());
+	}
+	
+	@Override
 	public void render() {
 		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 		
 				if(b == -50)
 					continue;
 				
-				glUniformMatrix4(modelViewMatrixUniform, false, modelViewMatrix.clearToIdentity().rotate(angleY, 1, 0, 0).rotate(angle,0,1,0).translate(a*10 - position.x(), -20 - position.y(), b*10-20 - position.z()).getBuffer());				
+				glUniformMatrix4(modelViewMatrixUniform, false, modelViewMatrix.clearToIdentity().rotate(angleY, 1, 0, 0).rotate(angle,0,1,0).translate(a*10 - position.x(), -20 - position.y(), b*10-20 - position.z()).getBuffer());
 				glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0);
 			}
 		}