如何让GL_QUADS向侧面移动? [英] How to have a GL_QUADS move sidewards?
本文介绍了如何让GL_QUADS向侧面移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我是opengl的新手,我很困惑如何使用gltranslate / glrotate让gl_quads向侧面移动,任何帮助?以下是我对gl_quads的顶点:
hello, i am new to opengl and im confused on how to use gltranslate/glrotate to let the gl_quads move sidewards, any help? following is my vertices for the gl_quads:
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glTranslatef(0.3,0,0);
//glTranslatef(0.7,0,0);
//glRotatef(45.0,0.0,1.0,0.0);
glBegin(GL_QUADS);
glColor3f(1.0f, 0.5f, 0.0f); // Orange
glVertex2f(0,0);
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex2f(0.4,0);
glColor3f(1.0f, 1.0f, 0.0f); // Yellow
glVertex2f(0.4,0.4);
glColor3f(0.0f, 0.0f, 1.0f); // Blue
glVertex2f(0,0.4);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
我的尝试:
i试图移动位置和角度,但我应该看到它的实时模式向侧面移动
What I have tried:
i have tried moving the position and the angle but i should see the "live" mode of it moving sidewards
推荐答案
标准这样做的方法是随着时间的推移改变一些参数。由于您希望让它横向移动,然后调整x方向的平移。对于动画,通常人们设置计时器并在每个刻度上增加翻译。在Windows世界中,这意味着处理WM_TIMER消息。以下是MFC窗口的示例计时器处理例程:
The standard way of doing this is to have some parameter change over time. Since you want to have it move sideways then adjust the translation in the x direction. For animating it, usually people set a timer and increment the translation on each tick. In the windows world this means handling the WM_TIMER message. Here is a sample timer handling routine for an MFC window :
void MyWindow::OnTimer( UINT_PTR eventId )
{
if( eventId == MyTimerId )
{
m_TranslationX += increment;
Invalidate(); // cause the window to be redrawn
}
__super::OnTimer( eventId );
}
// the translation call in your display function will become :
glTranslatef( m_Translation, 0, 0 );
如果你愿意,你可以增加m_Translation直到它达到某个值,然后减去它一段时间,这将导致四边形向右移动,然后向左移动。
If you want to, you can increment m_Translation until it reaches a certain value and then decrement it for a while and this will cause the quads to move to the right and then to the left.
这篇关于如何让GL_QUADS向侧面移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文