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.6Java/JOGL application: // same imports and declarations as before, plus the following: importpublic void display(GLAutoDrawable drawable) { GL4 gl= (GL4) GLContext.getCurrentGL();} gl.gl ProgramUniform1f(rendering Program, offsetLoc, x); gl.glDrawArrays (GL_TRIANGLES,0,3); } .. //

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

1 Expert Approved Answer
Step: 1 Unlock

java public class Code extends JFrame implements GLEventListener private f... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Graphics Programming Questions!