Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Repaired Camera3rdPerson and ExampleFrame (3D Math Tutorial #6) world

projections and camera translations.
  • Loading branch information...
commit cf7438608930c339411b403f2eab4c77638a42dd 1 parent fa7f378
Westin Miller authored April 20, 2012
7  3D Graphics/JOGL Beginner/src/com/pi/gl/graphics/Camera3rdPerson.java
@@ -9,7 +9,7 @@
9 9
 	private static final float yawMilli = .1f;
10 10
 	private static final float pitchMilli = .1f;
11 11
 
12  
-	private float pitch = 45, yaw = 0;
  12
+	private float pitch = 45, yaw = 0, centerDist = 500;
13 13
 	private boolean u, l, d, r;
14 14
 	private long lastMoveProc = -1;
15 15
 
@@ -43,11 +43,12 @@ public void translate(GL2 gl) {
43 43
 			else if (d)
44 44
 				modPitch(-passed * pitchMilli);
45 45
 			if (l)
46  
-				modYaw(passed * yawMilli);
47  
-			else if (r)
48 46
 				modYaw(-passed * yawMilli);
  47
+			else if (r)
  48
+				modYaw(passed * yawMilli);
49 49
 		}
50 50
 		lastMoveProc = System.currentTimeMillis();
  51
+		gl.glTranslatef(0, 0, -centerDist);
51 52
 		gl.glRotatef(pitch, 1, 0, 0);
52 53
 		gl.glRotatef(360 - yaw, 0, 1, 0);
53 54
 	}
5  3D Graphics/JOGL Beginner/src/com/pi/gl/graphics/RenderLoop.java
@@ -20,8 +20,7 @@ public RenderLoop(DisplayManager displayManager) {
20 20
 		this.displayManager = displayManager;
21 21
 		float[][] hMap;
22 22
 		try {
23  
-			hMap = MeshLoader.loadHeightMap(new File("heightmap.png"), 0,
24  
-					255);
  23
+			hMap = MeshLoader.loadHeightMap(new File("heightmap.png"), 0, 255);
25 24
 		} catch (Exception e) {
26 25
 			hMap = new float[50][50];
27 26
 		}
@@ -47,7 +46,7 @@ public void display(GLAutoDrawable drawable) {
47 46
 		gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
48 47
 		gl.glLoadIdentity();
49 48
 		gl.glOrtho(drawable.getWidth() / -2, drawable.getWidth() / 2,
50  
-				drawable.getHeight() / 2, drawable.getHeight() / -2, -500, 500);
  49
+				drawable.getHeight() / -2, drawable.getHeight() / 2, 50, 1000);
51 50
 		gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
52 51
 		gl.glLoadIdentity();
53 52
 		displayManager.getCamera().translate(gl);
2  3D Graphics/JOGL Beginner/tut/3 - World Projection and The First Triangle
@@ -12,7 +12,7 @@ In our case we will be adding it to the display function of the render loop.  Th
12 12
 [CODE]		// Define the world projection
13 13
 		gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
14 14
 		gl.glLoadIdentity();
15  
-		gl.glOrtho(drawable.getWidth()/-2, drawable.getWidth()/2, drawable.getHeight()/2, drawable.getHeight()/-2, -500, 500);
  15
+		gl.glOrtho(drawable.getWidth()/-2, drawable.getWidth()/2, drawable.getHeight()/-2, drawable.getHeight()/2, 50, 1000);
16 16
 		gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
17 17
 		gl.glLoadIdentity();[/CODE]
18 18
 		
11  3D Graphics/JOGL Beginner/tut/4 - Camera 3rd Person
@@ -17,7 +17,7 @@ public class Camera3rdPerson implements KeyListener {
17 17
 	private static final float yawMilli = .1f;
18 18
 	private static final float pitchMilli = .1f;
19 19
 
20  
-	private float pitch = 45, yaw = 0;
  20
+	private float pitch = 45, yaw = 0, centerDist = 500;
21 21
 	private boolean u, l, d, r;
22 22
 	private long lastMoveProc = -1;
23 23
 
@@ -47,15 +47,16 @@ public class Camera3rdPerson implements KeyListener {
47 47
 		if (lastMoveProc != -1) {
48 48
 			long passed = System.currentTimeMillis() - lastMoveProc;
49 49
 			if (u)
50  
-				modPitch(passed * pitchMilli);
51  
-			else if (d)
52 50
 				modPitch(-passed * pitchMilli);
  51
+			else if (d)
  52
+				modPitch(passed * pitchMilli);
53 53
 			if (l)
54  
-				modYaw(passed * yawMilli);
55  
-			else if (r)
56 54
 				modYaw(-passed * yawMilli);
  55
+			else if (r)
  56
+				modYaw(passed * yawMilli);
57 57
 		}
58 58
 		lastMoveProc = System.currentTimeMillis();
  59
+		gl.glTranslatef(0, 0, -centerDist);
59 60
 		gl.glRotatef(pitch, 1, 0, 0);
60 61
 		gl.glRotatef(360 - yaw, 0, 1, 0);
61 62
 	}

0 notes on commit cf74386

Please sign in to comment.
Something went wrong with that request. Please try again.