Roi Atalla avatar Roi Atalla committed 7714a62

Fixed the issue with 8.4. It was actually in the Timer: it wasn't keeping track of the elapsed time properly.

Comments (0)

Files changed (2)

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter8/example4/Example8_4.java

 					return lerp(q0, q1, alpha);
 				
 				dot = clamp(dot, -1, 1);
-				float theta = (float)Math.cos(dot) * alpha;
+				float theta = (float)Math.acos(dot) * alpha;
 				
-				Quaternion q2 = q1.sub(new Quaternion(q0).mult(dot)).normalize();
+				Quaternion q2 = q1.add(new Quaternion(q0).mult(-dot)).normalize();
 				
 				return q0.mult((float)Math.cos(theta)).add(q2.mult((float)Math.sin(theta)));
 			}
 			
 			private Quaternion lerp(Quaternion q0, Quaternion q1, float alpha) {
 				return new Quaternion(q0.x() + (q1.x() - q0.x()) * alpha,
-						  q0.y() + (q1.y() - q0.y()) * alpha,
-						  q0.z() + (q1.z() - q0.z()) * alpha,
-						  q0.w() + (q1.w() - q0.w()) * alpha).normalize();
+									  q0.y() + (q1.y() - q0.y()) * alpha,
+									  q0.z() + (q1.z() - q0.z()) * alpha,
+									  q0.w() + (q1.w() - q0.w()) * alpha).normalize();
 			}
 			
 			public void startAnimation(int destination, float duration) {

src/main/java/com/ra4king/opengl/util/Timer.java

 	private float absPrevTime;
 	private float secAccumTime;
 	
+	private long elapsedTime;
+	
 	public Timer() {
 		this(Type.INFINITE, 1);
 	}
 	}
 	
 	public boolean update(long deltaTime) {
-		float currTime = deltaTime / (float)1e9;
+		elapsedTime += deltaTime;
+		
+		float currTime = elapsedTime / (float)1e9;
 		
 		if(!hasUpdated) {
 			absPrevTime = currTime;
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.