Results 1 to 3 of 3

Thread: Rotation about y-axis using glLoadMatrixf

  1. #1
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    11

    Rotation about y-axis using glLoadMatrixf

    Hey all,

    I'm trying to rotate a triangle by the basic program as follows:
    Code :
    #include <gl/glut.h> // GLUT header file
    #include <gl/gl.h> // OpenGL header file
    #include <math.h>
     
    GLfloat matrix[16] = {cos(2.f), 0, -sin(2.f), 0, 0, 1, 0, 0, sin(2.f), 0, cos(2.f), 0, 0, 0, 0, 1};
     
    void display() {
    glBegin(GL_TRIANGLES);
    glColor3f( 0.0f, 1.0f, 0.0f);
    glVertex3f(-0.5f,-0.5f, 0.0f);
    glColor3f( 0.0f, 0.0f, 1.0f);
    glVertex3f( 0.5f,-0.5f, 0.0f);
    glColor3f( 1.0f, 0.0f, 0.0f);
    glVertex3f( 0.0f, 0.5f, 0.0f);
    glEnd();
    glFlush();
    }
    void main(int argc, char **argv) {
    glutInit(&amp;argc, argv);
    glutCreateWindow("Testing");
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixf(matrix);
    glutDisplayFunc(display);
    glutMainLoop();
    }

    It's rotating, but in a weird way... I have it set at 2 degrees right now but it's rotating so much that the triangle is being turned at LEAST 180 degrees! Any idea what I'm doing wrong? (I know I can use glRotatef but I want to try doing in using the custom matrix I made).

    Thanks,

    Canadian0469

  2. #2
    Senior Member Regular Contributor
    Join Date
    Apr 2001
    Posts
    180

    Re: Rotation about y-axis using glLoadMatrixf

    In most environments, including C, the angle parameter for sin() and cos() should be in radians, not degrees. To convert, multiply by Pi and divide by 180 (ie 2.f * 3.14 / 180 or similar).

  3. #3
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    11

    Re: Rotation about y-axis using glLoadMatrixf

    Thanks so much!

Similar Threads

  1. Rotation About An Axis
    By California in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-06-2016, 05:24 AM
  2. Rotation not on the 0,0,0 axis
    By tzano in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-03-2004, 12:55 PM
  3. changing axis of rotation and center of rotation in openGL performer
    By ravishashi in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 07-08-2003, 04:42 AM
  4. Rotation around two fixed rotation axis
    By Roland in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 03-06-2002, 12:07 PM
  5. axis,rotation
    By amigos in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-15-2000, 12:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean