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®;
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.
Many regards the Black Adder
Relic
October 18, 2005, 5:47am
2
Math functions sin and cos need radians, you used degrees.
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…
Relic
October 18, 2005, 6:22am
4
:eek:
Integer division 22/7 gives 3.
You wanted
#define PI (22.0/7.0)
or really
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327950288419716939937510
#endif
and
double theta = 90.0 * M_PI / 180.0;
Remember that OpenGL matrices are column-major.
Your matrix built from R[16]
1 cos(theta) -sin(theta) 0
0 sin(theta) cos(theta) 0
0 0 0 1
0 0 0 missing?
But you probably wanted
1 0 0 0
0 cos(theta) sin(theta) 0
0 -sin(theta) cos(theta) 0
0 0 0 1
Be more careful.
yes of course hehe
Shame on me…It was the integer divide that made the inacurracy.
Thank you very much