Int windowId;
// Animation settings
int animate_mode = 0;
int animation_frame = 0;
// Joint parameters
const float HEAD_MIN = -10.0f;
const float HEAD_MAX = 10.0f;
const float LEFT_HAND_MIN = -5.0f;
const float LEFT_HAND_MAX = 5.0f;
const float RIGHT_HAND_MIN = -5.0f;
const float RIGHT_HAND_MAX = 5.0f;
const float CLOUD_MIN = -10.0f;
const float CLOUD_MAX = 10.0f;
float joint_rot_head = 0.0f;
float joint_rot_left_hand = 0.0f;
float joint_rot_right_hand = 0.0f;
// Coordinates of a circle vertices
GLfloat circle[20][2] = {
{1, 0},
{0.951057, 0.309017},
{0.809017, 0.587785},
{0.587786, 0.809017},
{0.309018, 0.951056},
{0, 1},
{-0.309016, 0.951057},
{-0.587784, 0.809018},
{-0.809016, 0.587787},
{-0.951056, 0.309019},
{-1, 0},
{-0.951057, -0.309014},
{-0.809019, -0.587783},
{-0.587788, -0.809015},
{-0.30902, -0.951055},
{0, -1},
{0.309013, -0.951058},
{0.587782, -0.80902},
{0.809014, -0.587789},
{0.951055, -0.309021}
};
//Function declarations
void initGlui();
void initGl();
void display(void);
void animate();
void myReshape(int w, int h);
void GLUI_Control(int id);
void drawSquare(int i);
void drawCircle();
int main(int argc, char** argv)
{
/* Инициализация первоначального состояния GLUT */
glutInit(&argc, argv);//самая первая команда инициализации
/* Выбор режима окна:
Одиночный буфер и RGBA палитра */
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);//устанавливает цветовую модель - RGBA или color-index
/* Установка размеров и положения окна */
glutInitWindowPosition(10, 10);//установим начало координат окна
Win[0] = 1000;
Win[1] = 1000;
glutInitWindowSize(Win[0], Win[1]);//размер окна
/* Открытие окна */
windowID = glutCreateWindow("Lab1: Drawing a duckling");
glutReshapeFunc(myReshape);
glutDisplayFunc(display);//вызывается всякий раз при перерисовке окна
initGlui();
//*Цвет фона
glClearColor(0.7f, 0.7f, 0.9f, 1.0f);
//* Запуск механизма обработки событий */
glutMainLoop();
return 0;
}
// Animate button handler. Called when the "animate" checkbox is pressed.
void animateButton(int) {
// synchronize variables that GLUT uses
glui->sync_live();
animation_frame = 0;
if (animate_mode == 1) {
// start animation
GLUI_Master.set_glutIdleFunc(animate);
} else {
// stop animation
GLUI_Master.set_glutIdleFunc(NULL);
}
}
// Initialize GLUI and the user interface
Void initGlui() {
GLUI_Master.set_glutIdleFunc(NULL);
// Create GLUI window
glui = GLUI_Master.create_glui("Duckling Controls", 0, Win[0] + 10, 0);
GLUI_Panel *panel = glui->add_panel("Joints");
// Create a control to specify the rotation of the joint
GLUI_Spinner *head_spinner
= glui->add_spinner_to_panel(panel, "Head", GLUI_SPINNER_FLOAT, &joint_rot_head);
head_spinner->set_speed(0.1);
head_spinner->set_float_limits(HEAD_MIN, HEAD_MAX, GLUI_LIMIT_CLAMP);
GLUI_Spinner *left_hand_spinner
= glui->add_spinner_to_panel(panel, "Left Hand", GLUI_SPINNER_FLOAT, &joint_rot_left_hand);
left_hand_spinner->set_speed(0.1);
left_hand_spinner->set_float_limits(LEFT_HAND_MIN, LEFT_HAND_MAX, GLUI_LIMIT_CLAMP);
GLUI_Spinner *right_hand_spinner
= glui->add_spinner_to_panel(panel, "Right Hand", GLUI_SPINNER_FLOAT, &joint_rot_right_hand);
right_hand_spinner->set_speed(0.1);
right_hand_spinner->set_float_limits(RIGHT_HAND_MIN, RIGHT_HAND_MAX, GLUI_LIMIT_CLAMP);
// Add button to specify animation mode
GLUI_Panel *panel2 = glui->add_panel("Controls");
glui->add_checkbox_to_panel(panel2, "Animate", &animate_mode, 0, animateButton);
// Set the main window to be the "active" window
glui->set_main_gfx_window(windowID);
}
