Roi Atalla avatar Roi Atalla committed ca80c02

Press 'M' to grab/ungrab the mouse.

Comments (0)

Files changed (1)

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);
 			}
 		}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.