2

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 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.