2009-07-13 8 views
0

Я пытаюсь внедрить существующую реализацию ArcBall в JOGL в свой собственный проект. Он компилируется и запускается, но я не работаю! Я не могу играть с этим видом.JOGL ArcBall не работает

Я взял реализацию (два класса) здесь:

http://www.mdimension.com/page/Software?appNum=1

И следовал инструкциям embeding вещи в мой собственный проект. Вот класс, я использую ArcBall в:

общественного класса GLRenderer реализует GLEventListener {

private static final int MAP_SIZE = 1024; 
private static final int STEP_SIZE = 16; 
private static final float HEIGHT_RATIO = 1.5f; 

private float[][] temperatureMap = new float[MAP_SIZE][MAP_SIZE]; 
private float scaleValue = 0.15f; 

private GLU glu = new GLU(); 
private ArcBall arcBall = new ArcBall(); 

public void init(GLAutoDrawable drawable) { 
    GL gl = drawable.getGL(); 

    gl.glShadeModel(GL.GL_SMOOTH); 

    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); 
    gl.glClearDepth(1.0f); 
    gl.glEnable(GL.GL_DEPTH_TEST); 
    gl.glDepthFunc(GL.GL_LEQUAL); 
    gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); 

    loadValuesToMap(); 

    arcBall.registerDrawable(drawable); 

} 

public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { 
    GL gl = drawable.getGL(); 

    gl.glViewport(0, 0, width, height); 
    gl.glMatrixMode(GL.GL_PROJECTION); // Select The Projection Matrix 
    gl.glLoadIdentity(); 

    glu.gluPerspective(30,(float)width/(float)height,1.0f,650.0); 
    gl.glMatrixMode(GL.GL_MODELVIEW); 
    gl.glLoadIdentity(); 

    arcBall.reshape(width, height); 
} 

public void display(GLAutoDrawable drawable) { 

    arcBall.displayUpdateRotations(); 

    GL gl = drawable.getGL(); 

    gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 
    gl.glClear(GL.GL_COLOR_BUFFER_BIT); 
    gl.glClear(GL.GL_DEPTH_BUFFER_BIT); //added 

    gl.glMatrixMode(GL.GL_PROJECTION); 
    gl.glLoadIdentity(); 

    setLight(gl); 

    positionCamera(glu, gl); 

    drawXYZ(gl); 

    arcBall.displayTransform(gl); 

    drawMap(glu, gl); 

    gl.glFlush(); 
} 

public void setVertexColor(GL gl, int x, int y) { 
    float fColor = -0.15f + (temperatureMap[x][y]/256.0f); 
    gl.glColor3f(0.0f, 0.0f, fColor); 
} 

public void drawMap(GLU glu, GL gl) { 

    int x, z; 
    float y; 

    gl.glBegin(GL.GL_QUADS); 

    for(int X = 0; X <(MAP_SIZE - STEP_SIZE); X += STEP_SIZE) { 
     for(int Y = 0; Y < (MAP_SIZE -STEP_SIZE); Y += STEP_SIZE) { 

      // Get The (X, Y, Z) Value For The Bottom Left Vertex 
      x = X; 
      y = temperatureMap[X][Y]; 
      z = Y; 

      // Set The Color Value Of The Current Vertex 
      setVertexColor(gl, x, z); 

      gl.glVertex3f(x, y, z); 

      // Get The (X, Y, Z) Value For The Top Left Vertex 
      x = X; 
      y = temperatureMap[X][Y + STEP_SIZE]; 
      z = Y + STEP_SIZE ; 

      // Set The Color Value Of The Current Vertex 
      setVertexColor(gl, x, z); 

      gl.glVertex3f(x, y, z);   // Send This Vertex To OpenGL To Be Rendered 


      // Get The (X, Y, Z) Value For The Top Right Vertex 
      x = X + STEP_SIZE; 
      y = temperatureMap[X + STEP_SIZE][Y + STEP_SIZE]; 
      z = Y + STEP_SIZE ; 

      // Set The Color Value Of The Current Vertex 
      setVertexColor(gl, x, z); 

      gl.glVertex3f(x, y, z);   // Send This Vertex To OpenGL To Be Rendered 

      // Get The (X, Y, Z) Value For The Bottom Right Vertex 
      x = X + STEP_SIZE; 
      y = temperatureMap[X + STEP_SIZE][Y]; 
      z = Y; 

      // Set The Color Value Of The Current Vertex 
      setVertexColor(gl, x, z); 

      gl.glVertex3f(x, y, z);   // Send This Vertex To OpenGL To Be Rendered 


     } 
    } 

    gl.glEnd(); 

    gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 

    gl.glTranslated(0.1, 0.1, -0.5); 
    gl.glColor3f(0.0f, 0.0f, 1.0f); 
    glu.gluSphere(glu.gluNewQuadric(), 0.05f, 32, 32); 

    gl.glTranslated(0.1, 0.1, -0.1); 
    gl.glColor3f(0.0f, 1.0f, 0.0f); 
    glu.gluSphere(glu.gluNewQuadric(), 0.05f, 32, 32); 

    gl.glTranslated(0.1, -0.1, 0.1); 
    gl.glColor3f(1.0f, 0.0f, 0.0f); 
    glu.gluSphere(glu.gluNewQuadric(), 0.05f, 32, 32); 
} 

общественного недействительными positionCamera (GLU Glu, GL ГЛ) {

glu.gluPerspective(75.0f,1.09,0.1f,500.0f); 
    glu.gluLookAt(194, 80, 194, 
       131, 55, 131, 
       0, 1, 0); 
    gl.glScalef(scaleValue, scaleValue * HEIGHT_RATIO, scaleValue); 

}

public void setLight (GL gl) {

// Prepare light parameters. 
    float SHINE_ALL_DIRECTIONS = 1; 
    float[] lightPos = {0, -30, 0, SHINE_ALL_DIRECTIONS}; 
    float[] lightColorAmbient = {0.5f, 0.5f, 0.5f, 0.5f}; 
    float[] diffuseLight = { 0.8f, 0.8f, 0.8f, 1.0f }; 
    float[] lightColorSpecular = {0.5f, 0.5f, 0.5f, 0.5f}; 

    // Set light parameters. 
    gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, lightPos, 1); 
    gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, lightColorAmbient, 0); 
    gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, diffuseLight, 0); 
    gl.glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, lightColorSpecular, 0); 

    // Enable lighting in GL. 
    gl.glEnable(GL.GL_LIGHT1); 
    gl.glEnable(GL.GL_LIGHTING); 

    // Set material properties. 
    gl.glEnable(GL.GL_COLOR_MATERIAL);  

}

общественного недействительными drawXYZ (GL GL) { gl.glMatrixMode (GL.GL_MODELVIEW);

gl.glBegin(GL.GL_LINES); 

    gl.glColor3d(1.0, 0.0, 0.0); //red (x) 
    gl.glVertex3d(-0.1, 0.0, 0.0); 
    gl.glVertex3d(1500.0, 0.0, 0.0); 

    gl.glColor3d(0.0, 1.0, 0.0); //green (y) 
    gl.glVertex3d(0.0, -0.1, 0.0); 
    gl.glVertex3d(0.0, 1500.0, 0.0); 

    gl.glColor3d(0.0, 0.0, 1.0); //blue (z) 
    gl.glVertex3d(0.0, 0.0, 0.1); 
    gl.glVertex3d(0.0, 0.0, 1500.0); 

    gl.glEnd(); 

}

public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { 
    init(drawable); 
} 

private void loadValuesToMap() { 
    for(int i = 0; i < MAP_SIZE; i++) { 
     for(int j = 0; j< MAP_SIZE; j++) { 
      if(i > 300 && i < 700 && j > 300 && j < 700) 
       temperatureMap[i][j] = 150; 
      else 
       temperatureMap[i][j] = 100; 
     } 
    } 
} 

}

Я новичок в OpenGL соке может быть глупой ошибкой. Однако я был бы признателен за любую помощь.

Thanks

ответ

0

Исходный код не заполнен. Где ваша рамка (AWT Frame или Swing JFrame)? Посмотрите пример JOGL в Википедии.