开发者

Quaternion rotation x-axis 45 Degrees

开发者 https://www.devze.com 2022-12-15 08:10 出处:网络
Evening 开发者_StackOverflow社区everyone, I\'m using glMultMatrixf in OpenGL to rotate my scene using the matrix:

Evening 开发者_StackOverflow社区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


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消