研究这本书OpenGL SuperBible fram Addison-Wesley
,我读到:
每次调用 glTranslate 在模型视图矩阵上都是累积的,
这是什么意思?
这是否意味着例如此代码:
glTranslatef(2.0,3.0,0);
glTranslatef(4.0,5.0,0);
首先将原点上的对象移动到该点(2,3,0)
,然后再将其从原点转换(2,3,0)
为(2+4,3+5,0+0) = (6,8,0)
不从原点?
这是真的glScalef
吗glRotatef
?
例如这段代码:
glScalef(2.0,3.0,4.0);
glScalef(3.0,4.0,5.0);
首先把一个1x1x1
长方体变成一个立方体2x3x4
,然后把这个立方体变成6x12x20
一个?
最后,这段代码是否意味着绕 x 轴旋转 75 度?
glRotatef(30.0,1,0,0);
glRotatef(45.0,1,0,0);
最重要的是:在每次调用这些函数之前调用 glLoadIdentity() 会取消这些功能吗?
我的意思是你认为这段代码能保证每次translates will be done from the origin?
,scale changes will be done from the initial state?
void COpenGLControl::ZoomToFullExtent()
{
float zoom1 = (float)oglWindowWidth/(float)ImageWidth;
float zoom2 = (float)oglWindowHeight/(float)ImageHeight;
m_fZoom = min(zoom1,zoom2);
m_fZoomInverse = 1/m_fZoom;
m_fPosX = 0;
m_fPosY = 0;
OnDraw(NULL);
}
void COpenGLControl::FixedZoomIn()
{
m_fZoom = 2*m_fZoom;
m_fZoomInverse = 1/m_fZoom;
OnDraw(NULL);
}
void COpenGLControl::FixedZoomOut()
{
m_fZoom = 0.5*m_fZoom;
m_fZoomInverse = 1/m_fZoom;
OnDraw(NULL);
}
void COpenGLControl::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (WantToPan)
{
if (m_fLastX < 0.0f && m_fLastY < 0.0f)
{
m_fLastX = (float)point.x;
m_fLastY = (float)point.y;
}
diffX = (int)(point.x - m_fLastX);
diffY = (int)(point.y - m_fLastY);
m_fLastX = (float)point.x;
m_fLastY = (float)point.y;
if (nFlags & MK_MBUTTON)
{
m_fPosX += (float)0.2f*m_fZoomInverse*diffX;
m_fPosY += (float)0.2f*m_fZoomInverse*diffY;
}
OnDraw(NULL);
}
CWnd::OnMouseMove(nFlags, point);
}
void COpenGLControl::OnDraw(CDC *pDC)
{
// TODO: Camera controls
wglMakeCurrent(hdc,hrc);
glLoadIdentity();
gluLookAt(0,0,1,0,0,0,0,1,0);
glScalef(m_fZoom,m_fZoom,1.0);
glTranslatef(m_fPosX, m_fPosY, 0.0f);
wglMakeCurrent(NULL, NULL);
}