【问题标题】:OpenGL - sine and cosine waves in jogl (JAVA)OpenGL - jogl (JAVA) 中的正弦和余弦波
【发布时间】: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


    【解决方案1】:

    好吧,我不打算为你写代码,但是this,似乎有一个使用贝塞尔样条的可行方法。当然它是在 Lua 中的,但你应该能够将它转置为 java 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-21
      • 1970-01-01
      • 1970-01-01
      • 2016-06-16
      • 2015-05-23
      • 2017-10-06
      • 1970-01-01
      相关资源
      最近更新 更多