noraantonia 0 Newbie Poster

hello

I implemented a rotating cube in opengl which rotates when the user moves the mouse.
I am a beginner with opengl, so i wanted to ask you a question on rotating.
here is my code for the rotation :

void CDiplomaView::OnLButtonDown(UINT nFlags, CPoint point) 
{
    // TODO: Add your message handler code here and/or call default
	 m_LeftButtonDown = TRUE;
                 m_LeftDownPos = point;
	CView::OnLButtonDown(nFlags, point);
}

void CDiplomaView::OnMouseMove(UINT nFlags, CPoint point) 
{
  // TODO: Add your message handler code here and/or call default
	if (m_LeftButtonDown)
                {
                     CDiplomaDoc* pDoc = GetDocument();
                     CSize rotate = m_LeftDownPos - point;
                     m_LeftDownPos = point;;
                     pDoc->m_xRotate += rotate.cx/3;
                     pDoc->m_yRotate += rotate.cy/3;
                     InvalidateRect(NULL, FALSE);
                 }
                     CView::OnMouseMove(nFlags, point);
}

The problem is that i don't know how to make it spin around the z axis when the user moves the mouse. I know that i have to write this function :

glRotated(m_zRotate, 0.0, 0.0, 1.0);

where m_zRotate is the angle of the rotation in my rendering function. But on mouse move function, how can i implement the z rotation taking into consideration the fact that cz doesn't exist ? only cx and cy - Size variables used in OnSize function.

And also my rotation is kind of sudden, not very natural, i don't know why, maybe because it doesn't rotate on the z axis ?

Or can you propose a different code for rotation using the mouse with a more natural rotation ?

Thank you in advance for your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.