2012-03-14 17 views
-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 ofOne)が必要です。

答えて

0

私はコードを書くつもりはありませんが、thisは、ベジェスプラインを使った無理な方法があるようです。もちろんそれはLuaにありますが、あなたはそれをJavaのメソッドに変換することができます。

関連する問題