tags:

views:

179

answers:

1

Evening everyone,

I'm using glMultMatrixf in OpenGL to rotate my scene using the matrix:

float matrix[16] = {    1.0, 0.0, 0.0, 0.0, 
                            0.0, 1.0, 0.0, 0.0,
                            0.0, 0.0, 1.0, 0.0, 
                            0.0, 0.0, 0.0, 1.0 };

I've been following this guide (link) but its a little bit over the top for what I need.

How could I simply rotate the x-axis by 45 degrees?

Cheers

+1  A: 

Multiplying your transformation matrix by this rotation matrix should do the trick:

float rot45X[16] = {   1.0,       0.0,         0.0, 0.0, 
                        0.0, cos(PI/4), -sin(PI/4), 0.0,
                        0.0, sin(PI/4),  cos(PI/4), 0.0, 
                        0.0,       0.0,        0.0, 1.0 };

Edit: You can also of course use the utility function

glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);

where [x,y,z] indicate the axis of rotation (yes, it performs rotations around an arbitrary vector).

In your case you would need to call like this:

glRotatef(45, 1, 0, 0);
pau.estalella
Perfect thanks!
Laurence Dawson