PDA

View Full Version : Rotation about y-axis using glLoadMatrixf



Canadian0469
05-17-2008, 06:19 PM
Hey all,

I'm trying to rotate a triangle by the basic program as follows:


#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

Lord crc
05-17-2008, 06:34 PM
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).

Canadian0469
05-17-2008, 07:08 PM
Thanks so much!