Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members Related Pages
Lesson3: Using Animation. - In this lesson you will learn how to create animation in your window. We will modify code from the Lesson 2, to add animation to the triangle.
- See also:
- sjgui::CWnd::OnAnimate()
class CSpcWnd : public sjgui::CWnd
{
float m_fRotation;
public:
CSpcWnd():CWnd(){m_fRotation=0.0f;}
virtual void OnAnimate()
{
m_fRotation+=1;
if(m_fRotation>360)m_fRotation-=360;
}
virtual void OnDraw()
{
Animate();
SET_GL_SIMPLE_PROSPECTIVE;
glTranslatef(0.0f,0.0f,-10.0f);
glRotatef(m_fRotation,0.0f,1.0f,0.0f);
glColor3f(0.0f,0.0f,1.0f);
glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
}
};
Back to Lesson 2. Forward to Lesson 4.
- The following is full source code for this lesson.
#include <sjgui/sjgui.h>
class CSpcWnd : public sjgui::CWnd
{
float m_fRotation;
public:
CSpcWnd():CWnd(){m_fRotation=0.0f;}
virtual void OnAnimate()
{
m_fRotation+=1;
if(m_fRotation>360)m_fRotation-=360;
}
virtual void OnDraw()
{
Animate();
SET_GL_SIMPLE_PROSPECTIVE;
glTranslatef(0.0f,0.0f,-10.0f);
glRotatef(m_fRotation,0.0f,1.0f,0.0f);
glColor3f(0.0f,0.0f,1.0f);
glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
}
};
int main(int argc, char* argv[])
{
CSpcWnd SpcWnd;
SpcWnd.PosWnd(20,50,320,240);
if(sjgui::Create("Animating",&SpcWnd))
{
sjgui::GlobalMainLoop();
}
else
printf("Could not create opengl window.\n");
return 0;
}
|
|