# Thread: rotating object 90 degrees using a matrix and glMultMatrix(R);

1. ## rotating object 90 degrees using a matrix and glMultMatrix(R);

Hello, I need to rotate an object 90 degrees around the X-axis.

Since I am very new to OpenGL I am still practicing, and therefor i don't want to use the glRotate function in this program I am doing at the moment.

So I want to specify the Rotation matrix myself and then add it using glMultMatrix.

I did the following:
//The rotation matrix OGL style:

GLfloat R[16]={1,0,0,0,cos(90),sin(90),0,0,-sin(90),cos(90),0,0,0,0,1}

//In the display func:

glPushMatrix();
glMultMatrix(R);
drawhouse();//this is the object i am rotating
glPopMatrix();

There is some rotation going on, but it is wrongly rotated. I cannot understand what I am doing wrong.
I hope somebody can help me out here, thank you very much.

2. ## Re: rotating object 90 degrees using a matrix and glMultMatrix(R);

Math functions sin and cos need radians, you used degrees.

3. ## Re: rotating object 90 degrees using a matrix and glMultMatrix(R);

hmmm

Now I am doing the following:
#define PI 22/7

theta=90*PI/180;
GLfloat R[16]={1,0,0,0,cos(theta),sin(theta),0,0,-sin(theta),cos(theta),0,0,0,0,1}

but alas, it still gives me wrong image...

Also if i rotate about the z-axis:

GLfloat Rz[16]={cos(theta),sin(theta),0.,0.,-sin(theta),cos(theta),0.,0.,0.,0.,1.,0.,0.,0.,1};

it gives me a wrong rotation...

4. ## Re: rotating object 90 degrees using a matrix and glMultMatrix(R);

Integer division 22/7 gives 3.

You wanted
#define PI (22.0/7.0)
or really
#ifndef M_PI
#define M_PI 3.141592653589793238462643383279502884197169399375 10
#endif

and

double theta = 90.0 * M_PI / 180.0;

Remember that OpenGL matrices are column-major.

Code :
```1 cos(theta) -sin(theta) 0
0 sin(theta) cos(theta)  0
0    0         0         1
0    0         0       missing?```
But you probably wanted
Code :
```1     0          0        0
0  cos(theta) sin(theta)  0
0 -sin(theta) cos(theta)  0
0     0          0        1```
Be more careful.

5. ## Re: rotating object 90 degrees using a matrix and glMultMatrix(R);

yes of course hehe
Shame on me...It was the integer divide that made the inacurracy.
Thank you very much

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•