Question: Modify Program 2.6 so that it calculates the amount of movement for the triangle based on elapsed time, rather than a constant amount as it
Modify Program 2.6 so that it calculates the amount of movement for the triangle based on elapsed time, rather than a constant amount as it is currently implemented. One approach for this is to get the current time from Java, and use it to calculate the elapsed time since the previous call to display(). Computing animations in this manner will ensure that they move at the same speed regardless of the speed of the particular computer.
Program 2.6


Java/JOGL application: // same imports and declarations as before, plus the following: import com.jogamp.opengl.util.*; public class Code extends JFrame implements GLEventListener { // same declarations as before, plus: private float x = 0.0f; // location of triangle private float inc = 0.01f; // offset for moving the triangle public Code() { // same constructor as before, plus this at the end, after the call to setVisible(true). Animator animtr = new Animator(myCanvas); animtr.start(); }
Step by Step Solution
3.30 Rating (165 Votes )
There are 3 Steps involved in it
java public class Code extends JFrame implements GLEventListener private f... View full answer
Get step-by-step solutions from verified subject matter experts
