-1
我試圖編碼一個正弦和餘弦波以顯示在我的面板上。我正在通過創建一個方法drawCurves()在我的EventListener類中嘗試這個。OpenGL - jogl中的正弦和餘弦波(JAVA)
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)來聲明每次繪製哪個波。