【发布时间】:2012-03-14 18:58:05
【问题描述】:
我正在尝试编写正弦波和余弦波以显示在我的面板上。我正在通过创建方法 drawCurves() 在我的 EventListener 类中尝试这个。
曲线GLEventListener:
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)来声明每次绘制哪个波浪。
【问题讨论】:
标签: java opengl jogl trigonometry