我试图编写一个正弦波和余弦波来显示在我的面板上。我通过创建方法drawCurves()在我的EventListener类中尝试此操作。
CurvesGLEventListener:
package firstAttempt;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
/**
* For now we will focus only two of the GLEventListeners init() and display().
*/
public class CurvesGLEventListener implements GLEventListener {
/**
* Interface to the GLU library.
*/
private GLU glu;
/**
* Take care of initialization here.
*/
public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
glu = new GLU();
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.glViewport(0, 0, 900, 550);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluOrtho2D(0.0, 900.0, 0.0, 550.0);
}
/**
* Take care of drawing here.
*/
public void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
drawCurves();
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width,
int height) {
}
public void displayChanged(GLAutoDrawable drawable,
boolean modeChanged, boolean deviceChanged) {
}
private void drawCurves() {
/**
* Here is where I need to implement the method
**/
}
}
我被告知,有了这个观点,我应该使用以下方式绘制我的波浪:
(x, (Math.sin(x/60.0)*100.0))
(x, (Math.cos(x/60.0)*100.0))
你能帮我实现这个方法吗?看起来好主意的是该方法采用参数(例如int whichOne)来声明每次绘制哪个波。