Problem with the glRotate!!

Good morning, my problem is i want to rotate a shape 90 degrees in z axis and i use the method glRotate(90.0f,0.0f,0.0f,1.0f); and the shape is not rotated! My code is:


package org.yourorghere;

import com.sun.opengl.util.Animator;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;



/**
 * SimpleJOGL.java 

 * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P>
 *
 * This version is equal to Brian Paul's version 1.2 1999/10/21
 */
public class SimpleJOGL implements GLEventListener {

    public static void main(String[] args) {
        Frame frame = new Frame("Simple JOGL Application");
        GLCanvas canvas = new GLCanvas();

        canvas.addGLEventListener(new SimpleJOGL());
        frame.add(canvas);
        frame.setSize(640, 480);
        final Animator animator = new Animator(canvas);
        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                // Run this on another thread than the AWT event queue to
                // make sure the call to Animator.stop() completes before
                // exiting
                new Thread(new Runnable() {

                    public void run() {
                        animator.stop();
                        System.exit(0);
                    }
                }).start();
            }
        });
        // Center frame
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        animator.start();
    }

    final double ONE_DEGREE = (Math.PI/180);
    final double THREE_SIXTY = 2 * Math.PI;


    public void init(GLAutoDrawable drawable) {
        // Use debug pipeline
        // drawable.setGL(new DebugGL(drawable.getGL()));

        GL gl = drawable.getGL();
        System.err.println("INIT GL IS: " + gl.getClass().getName());

        // Enable VSync
        gl.setSwapInterval(1);

        // Setup the drawing area and shading mode
        GLU glu = new GLU();

        gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

        gl.glViewport(-250, -150, 250, 150);
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluOrtho2D(-250.0, 250.0, -150.0, 150.0);
    }

    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
        
    }

    public void display(GLAutoDrawable drawable) {
        GL gl = drawable.getGL();
        GLU glu =new GLU();

        double x,y;
        double radius = 100;

        float red = 1.0f;
        float green = 0.0f;
        float blue = 0.0f;

        gl.glClear(GL.GL_COLOR_BUFFER_BIT);
        gl.glPushMatrix();
        gl.glColor3f(red, green, blue);
        gl.glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
        gl.glBegin(GL.GL_POLYGON);

        // angle is
        // x = radius * (cosine of angle)
        // y = radius * (sine of angle)
        for (double a=0; a<THREE_SIXTY; a+=ONE_DEGREE) {
            x = radius * (Math.sin(a));
            y = radius * (Math.cos(a));
            gl.glVertex2d(x, y);
        }

        gl.glEnd();
        gl.glPopMatrix();

        gl.glFlush();
    }

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


Help me, please!
Thanks for your attetion!

Don’t know if thats the problem, but glRotate(90.0f,0.0f,0.0f,1.0f) doesn’t rotate in z axis, but around the z axis.

And how i will rotate my shape???

Play around with the last 3 values of glRotate - they define the axis around your shape should rotate. use glRotate(90f,1f, 0f, 0f) to rotate around the x-axis for example.
Also take a look at http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=04

Rotate around the x-axis and the y-axis and i see the rotate in the screen by in the z-axis isn’t rotate because if i don’t use the command glRotatef(90.f,0.0f,0.0f,1.0f), i get in my screen these:

http://imageshack.gr/files/zx7kyq05z37vonk7lqkz.jpg

and then i use the command glRotatef(90.f,0.0f,0.0f,1.0f) and in my screen i look the same picture with no rotate.

Uh… doesn’t this mean your vertices are a circle, in the xy plane, centered at x=0, y=0, z=0? Shading this a solid color and rotating it about the z-axis is always gonna look the same. Try a different shape or add a texture.

What is causing the confusing, I think, is that the projectionmatrix is making your sphere look like an oval.

Now as ManaSink correctly said, rotating a perfect sphere won’t really change much visually.

But in this case, the sphere looks like an oval, so you’d expect to see the oval rotating. This is not the case, because it is a transformation in screenspace. First get your transform right (glOrtho2D) and then things will make more sense, visually.

Try changing your init code to the following to get a circle, rather than a ellipse.


        gl.glViewport(0, 0, 640, 480); //viewport typically matches size of screen/canvas
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluOrtho2D(-320, 320, -240, 240); //some multiple of screen/viewport dimensions to preserve aspect ratio and prevent squashing

The viewport defines the device coordinates, usually this is set for you, and matches the size of your canvas or the display resolution if you’re fullscreen.
The gluOrtho2D call defines the rectangle in world coordinates that you are trying to display.

Also, this stuff is usually done in the reshape() call, so that if the user resizes the frame, there is no weird stretching…

Good luck! ;D

I’ve made the changes and it now appears circle, thank you all for your answers! ;D