1
votes

I have a problem with this openGL code:

        make3D();
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
        GL11.glClearColor(0.5f, 0.55f, 0.55f, 1.0f);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        GLU.gluLookAt(camX, camY, camZ, centerX, centerY, centerZ, upX, upY, upZ);

        // THE PROBLEM IS SOMEWHERE HERE
        // Rotate and render vehicle
        GL11.glPushMatrix();
        GL11.glTranslatef(0.0f, 0f, 0.0f);
        GL11.glRotatef(vehicleRoll, 0.0f, 0.0f, 1.0f);
        GL11.glRotatef(vehiclePitch, 1.0f, 0.0f, 0.0f);
        GL11.glTranslatef(-0.0f, -0f, -0.0f);
        scene.render(ObjectType.VEHICLE);
        GL11.glPopMatrix();

        // Render floor
        GL11.glPushMatrix();
        GL11.glRotatef(vehicleCourse, 0.0f, 1.0f, 0.0f);
        GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
        scene.render(ObjectType.ENVIROMENT_FLOOR);
        GL11.glPopMatrix();

        // Draw lights
        setUpLighting();

Roll rotation seems okay, object rotates to its side (just rolls over), but the pitch rotation doesnt work as intended. If i roll my object first by 30 degrees, and then rotate pitch by 30 degrees, i would like it to be rolled and facing down by 30 degrees, but it rotates my object by a vector of those two, in the end it looks like 15 degrees pitch and 15 degrees roll and also changes its heading.

tl;dr this code does move my object by its own axis, one by one and i need it to rotate around point of orgin, chaning pitch and roll without changing its heading

Apart of that the second object (floor), is ment to rotate to given course, and it works fine. Vehicle is the problem.

I already tried not calling translateF, or calling rotations and translate f and then calling them again with negative values, nothing realy seemed to work.

edit: added youtube video visualsing my problem, or rather the effect im trying to achieve https://www.youtube.com/watch?v=zc8b2Jo7mno&feature=youtu.be&t=111

1

1 Answers

1
votes

After spending few hours on reading about euler agles and quaternion's, when i almost gave up i suddenly had an epiphany. To get the things working in my case it was enough to swap two lines of code:

That:

 GL11.glRotatef(vehicleRoll, 0.0f, 0.0f, 1.0f);
 GL11.glRotatef(vehiclePitch, 1.0f, 0.0f, 0.0f);

to that:

 GL11.glRotatef(vehiclePitch, 1.0f, 0.0f, 0.0f);
 GL11.glRotatef(vehicleRoll, 0.0f, 0.0f, 1.0f);