Thanks for the explaination.
Let me list the part of the source code
to show the problem.
I use the VC6.0 under Window 2000,
and in the project, I have some routines
in CXXView, they are:
void CGLSample4View::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
GLsizei width, height;
GLdouble aspect;
width = cx;
height = cy;
if (cy==0)
aspect = (GLdouble)width;
else
aspect = (GLdouble)width/(GLdouble)height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, aspect, 1.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDrawBuffer(GL_BACK);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
}
void CGLSample4View::OnPaint()
{
CPaintDC dc(this); // device context for painting
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
CGLSample4Doc* pDoc = GetDocument();
pDoc->RenderScene();
SwapBuffers(dc.m_ps.hdc);
}
void CGLSample4View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CView::OnKeyDown(nChar, nRepCnt, nFlags);
CGLSample4Doc* pDoc = GetDocument();
switch (nChar)
{
case VK_F1:
pDoc->m_xRotate -= 1; //Change the rotation in X only
break;
case VK_F2:
pDoc->m_yRotate -= 1;//Change the rotation in Y only
break;
case VK_F3:
pDoc->m_zRotate -= 1;//Change the rotation in Z only
break;
}
InvalidateRect(NULL,FALSE);
}
And in the CXXDoc file, I have the followings:
CGLSample4Doc::CGLSample4Doc()
{
m_xRotate = 0;
m_yRotate = 0;
m_zRotate = 0;
}
void CGLSample4Doc::RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslated(0.0, 0.0, -8.0);
//****** The Real Rotation in 3 Axis
glRotated(m_xRotate, 1.0, 0.0, 0.0);
glRotated(m_yRotate, 0.0, 1.0, 0.0);
glRotated(m_zRotate, 0.0, 0.0, 1.0);
glDisable(GL_LIGHTING);
glLineWidth(3.0f);
glColor3f(1.0f,0.0f,0.0f); //X
glBegin(GL_LINES);
glVertex3f(0.0f,0.0f,0.001f);
glVertex3f(20.0f,0.0f,0.001f);
glEnd();
glColor3f(0.0f,1.0f,0.0f);//Y
glBegin(GL_LINES);
glVertex3f(0.0f,0.0f,0.001f);
glVertex3f(0.0f,20.0f,0.001f);
glEnd();
glColor3f(0.0f,0.0f,1.0f);//Z
glBegin(GL_LINES);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,0.0f,20.0f);
glEnd();
glLineWidth(1.0);
glPopMatrix();
}
Ok, so in the previous routine, you see there
are three rotation statements:
glRotated(m_xRotate, 1.0, 0.0, 0.0);
glRotated(m_yRotate, 0.0, 1.0, 0.0);
glRotated(m_zRotate, 0.0, 0.0, 1.0);
And when I press F1, only m_xRotate will be decreasted,
the m_yRotate & m_zRotate keep unchanged when F1 is pressed.
So it suppose the axis will be rotated with respect to X axis?
It somehow does not work right (when I press F1 --> F2 -->F3
and then F3–>F2 or F1, somehow the axis rotate entirly).
What is the problem (I mean when the m_xRoate is changed only,
should the entire axis rotate with X only? What is the bug,
and how to solve? Thanks.