Prosta animacja kwadratu:
#include <gl/glut.h>
#include <cmath>
#include <iostream>
using namespace std;
//
// Animate as Fast as You Can
//
// Funkcja update modyfikuje kat angle
double angle = 0;
void update()
{
angle += 0.0002;
}
// Funkcja wywołuje update i wymusza odrysowanie
void idlefunc()
{
update();
glutPostRedisplay();
}
void myDisplay() {
glClear(GL_COLOR_BUFFER_BIT);
// Rysowanie obróconego kwadratu
glBegin(GL_POLYGON);
for(int i = 0; i < 4; ++i)
{
double x = cos(angle + i*M_PI/2.0);
double y = sin(angle + i*M_PI/2.0);
glVertex2d(x, y);
}
glEnd();
// glFlush() juz nie potrzebne, bo:
// "An implicit glFlush is done by glutSwapBuffers before it returns."
glutSwapBuffers(); // UWAGA - zamiana buforów
}
void reshape(int, int) {}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); // UWAGA: GLUT_DOUBLE
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("GLUTSIMPLE ANIMATION");
glutIdleFunc(idlefunc); // UWAGA: rejestracja idlefunc
glutDisplayFunc(myDisplay);
glutReshapeFunc(reshape);
glutMainLoop();
}
Zadanie 1 - Zoom In/Out
Narysuj poniższą krzywą parametryczną
glBegin(GL_LINE_STRIP);
for(double t = 0; t <= 310; t+=0.02)
{
double x = sin(0.99*t) - 0.7*cos(3.01*t);
double y = cos(1.01*t) + 0.1*sin(15.03*t);
glVertex2d(x, y);
}
glEnd();
Następnie utwórz animację zoom in/out poprzez zmniejszenie/zwiększenie okna (world window).
Zadanie 2 - Hierarchical Modeling
Utwórz animację kwadratów na wzór:
Zadanie 3* - Hierarchical Modeling
Utwórz animację na wzór przykładu