rotating to a normal

Started by
11 comments, last by daniel_i_l 18 years ago
Quote:Original post by daniel_i_l
But isn't the glMultMatrix like a rotation call, if that is true then the glTranslate should come after (like you said, rotation then translation)?
OpenGL uses column vectors, which is reflected in the fact that OpenGL transform function calls must be issued 'backwards' from the order in which you want them to be applied. So if you want rotate->translate, you call glTranslate() first, and the rotation function second.
Advertisement
Thanks for clearing that up:)
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
I implemented it like this:
glLoadIdentity(); Camera.Look(); glColor3f(0.5,1,0.5); CVector3 vForward2D = {1,0,0}; CVector3 vNormal; vNormal = NormalToMap(g_HeightMap, ((Map.BestPoint.x)/SCALE_SIDE), ((Map.BestPoint.z)/SCALE_SIDE));  CVector3 vSide = Normalize(Cross(vNormal, vForward2D)); CVector3 vForward = Cross(vSide, vNormal); CVector3 vPosition = Map.BestPoint;  float m[16]; m[0] = vSide.x; m[1] = vSide.y; m[2] = vSide.z; m[3] = 0.0f; m[4] = vNormal.x; m[5] = vNormal.y; m[6] = vNormal.z; m[7] = 0.0f; m[8] = vForward.x; m[9] = vForward.y; m[10] = vForward.z; m[11] = 0.0f; m[12] = vPosition.x; m[13] = vPosition.y; m[14] = vPosition.z; m[15] = 1.0f;  glMultMatrixf(m);   glLineWidth(2); glBegin(GL_TRIANGLES);  glVertex3f(-15, 1,  15);  glVertex3f( 20, 1,  20);  glVertex3f(  0, 1, -20); glEnd(); glLineWidth(1);

And it worked Great! I don't even have to translate cause of the vPosition input.
I just have a little question, when I set the forward to
CVector3 vForward2D = {1,0,0};
the triangle points to the left instead of to the right, only when I set the x to -1 it points right. Also, when the z is set to 1 it point into the screen instead of out of it? Why does this happen?
Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky

This topic is closed to new replies.

Advertisement