tags:

views:

201

answers:

0

Hi!

I'm trying to embed an existing implementation of ArcBall in JOGL into my own project. It compiles and runs but I doesn't work! I can't play around with the view.

I took the implementation (two classes) from here:

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

And followed the instructions of embeding the thing into my own project. Here's the class I'm using ArcBall in:

public class GLRenderer implements 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);
}

public void positionCamera(GLU glu, GL 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);

}

public void 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;
        }
    }
}

}

I'm new to openGL soke it might be a stupid mistake. I'd appreciate any help though.

Thanks