Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_DEPRECATE
- #include <time.h>
- #include <vector>
- #include <cstdlib>
- #include <cstdio>
- #include <iostream>
- #include <glew.h>
- #include <vector>
- #include <cmath>
- #include <ctime>
- #include "SOIL.h"
- #include <glfw3.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- #include <iostream>
- #include <string>
- #include<Windows.h>
- #define SCREEN_WIDTH 1000
- #define SCREEN_HEIGHT 1000
- #define PC_MODE 16
- #define CONSOLE_MODE 0
- #define MAXRAD 4
- #define MINRAD 1
- #define MAXHEIGHT 7
- #define MINHEIGHT 2
- #define MAXFREQ_X 40
- #define MINFREQ_X 3
- #define ANGLE 2
- #define DLIGHT 0.5
- #define TWINKIE_SPEED 20
- const double M_PI = 3.14;
- //Режим текстуры и анимации
- bool modT = false, modM=false;
- //Параметры для анимации
- float t, twinkie_steps = 100, dt = 5 / twinkie_steps;
- typedef struct {
- GLfloat x, y, z;
- } point;
- //Координаты основной фигуры
- std::vector<point> base_center;
- std::vector<std::vector<point>> base_side;
- //Координаты фигур для анимации (третью пока не реализовала)
- // Для каждой фигуры нужно каким-то образов изменить один параметр, чтобы он был отличен от основной фигуры,
- // У первой - rx и ry меняются местами
- // У второй - изменений высоты в 2 раза
- // Для третье можно сделать изменение наклона
- std::vector<point> tw1_center; // Координаты центров на каждом этаже
- std::vector<std::vector<point>> tw1_side; // Координаты боковых точек для каждого этажа vector[i][j] - j-ая координата на i-ом этаже
- std::vector<point> tw2_center;
- std::vector<std::vector<point>> tw2_side;
- std::vector<point> tw3_center;
- std::vector<std::vector<point>> tw3_side;
- GLint MOVE_X = 0;
- GLint MOVE_Y = 0;
- GLint MOVE_Z = 0;
- GLint ROTATE_X = 0;
- GLint ROTATE_Y = 0;
- GLint ROTATE_Z = 0;
- GLboolean global_ambient = false;
- GLboolean two_side = true;
- GLboolean local_viewer = true;
- GLboolean IS_FILL = true;
- GLfloat Amount = 10;
- GLfloat mSize = 1.0f;
- //Количество уровней
- GLint floors = 7;
- //Для понимания того, какая стадия в анимации
- int check = 1;
- //--------Координаты фигуры
- // В отрисовке фигуры она переворачивается, пыталась сделать, чтобы было по-человечески, но забила и просто работаю с тем, что есть
- float xDown = 0;
- float yDown = 0;
- float xUp = 30;
- float yUp = 30;
- float height = 200; // Высота
- float rx = 50; // Радиус по х
- float ry = 100; // Радиус по у
- GLuint textureID;
- GLFWwindow* WINDOW;
- // Прототипы функций
- void save();
- void load();
- void makeLight();
- void tweenking();
- void CreateTwilFig1();
- void CreateTwilFig2();
- void CreateTwilFig3();
- void CreateBasicFig();
- void display();
- void save()
- {
- FILE *file;
- file = fopen("data.txt", "w");
- fprintf(file, "%f\n", xDown);
- fprintf(file, "%f\n", yDown);
- fprintf(file, "%f\n", xUp);
- fprintf(file, "%f\n", yUp);
- fprintf(file, "%f\n", height);
- fprintf(file, "%f\n", rx);
- fprintf(file, "%f\n", ry);
- fprintf(file, "%f\n", Amount);
- fprintf(file, "%f\n", mSize);
- fprintf(file, "%i\n", floors);
- fprintf(file, "%i\n", MOVE_X);
- fprintf(file, "%i\n", MOVE_Y);
- fprintf(file, "%i\n", MOVE_Z);
- fprintf(file, "%i\n", ROTATE_X);
- fprintf(file, "%i\n", ROTATE_Y);
- fprintf(file, "%i\n", ROTATE_Z);
- fprintf(file, "%i\n", IS_FILL ? 1 : 0);
- fclose(file);
- printf("-> current state saved\n");
- }
- void load()
- {
- FILE *file;
- file = fopen("data.txt", "r");
- if (!file) {
- printf("-> failed to load!\n");
- return;
- }
- int temp;
- fscanf(file, "%f\n", &xDown);
- fscanf(file, "%f\n", &yDown);
- fscanf(file, "%f\n", &xUp);
- fscanf(file, "%f\n", &yUp);
- fscanf(file, "%f\n", &height);
- fscanf(file, "%f\n", &rx);
- fscanf(file, "%f\n", &ry);
- fscanf(file, "%f\n", &Amount);
- fscanf(file, "%f\n", &mSize);
- fscanf(file, "%i\n", &floors);
- fscanf(file, "%i\n", &MOVE_X);
- fscanf(file, "%i\n", &MOVE_Y);
- fscanf(file, "%i\n", &MOVE_Z);
- fscanf(file, "%i\n", &ROTATE_X);
- fscanf(file, "%i\n", &ROTATE_Y);
- fscanf(file, "%i\n", &ROTATE_Z);
- fscanf(file, "%i\n", &temp);
- fclose(file);
- if (temp == 1) {
- IS_FILL = true;
- }
- else
- {
- IS_FILL = false;
- }
- printf("-> previous state loaded\n");
- }
- void key(GLFWwindow * window, int key, int scancode, int action, int mods)
- {
- if (action == GLFW_PRESS || action == GLFW_REPEAT) {
- switch (key) {
- case GLFW_KEY_ESCAPE:
- glfwSetWindowShouldClose(window, GLFW_TRUE);
- break;
- case GLFW_KEY_UP:
- MOVE_Y += 30;
- break;
- case GLFW_KEY_DOWN:
- MOVE_Y -= 30;
- break;
- case GLFW_KEY_LEFT:
- MOVE_X -= 30;
- break;
- case GLFW_KEY_RIGHT:
- MOVE_X += 30;
- break;
- case GLFW_KEY_3:
- MOVE_Z += 100;
- break;
- case GLFW_KEY_4:
- MOVE_Z -= 100;
- break;
- case GLFW_KEY_W:
- ROTATE_X += 5;
- break;
- case GLFW_KEY_S:
- ROTATE_X -= 5;
- break;
- case GLFW_KEY_A:
- ROTATE_Y += 5;
- break;
- case GLFW_KEY_D:
- ROTATE_Y -= 5;
- break;
- case GLFW_KEY_5:
- ROTATE_Z += 5;
- break;
- case GLFW_KEY_6:
- ROTATE_Z -= 5;
- break;
- case GLFW_KEY_F:
- IS_FILL = !IS_FILL;
- break;
- case GLFW_KEY_1:
- mSize += 0.3f;
- break;
- case GLFW_KEY_2:
- mSize -= 0.3f;
- break;
- case GLFW_KEY_T:
- modT = !modT;
- break;
- //Разбиение
- case GLFW_KEY_Z:
- Amount += 1;
- break;
- case GLFW_KEY_X:
- Amount -= 1;
- break;
- //Анимация
- case GLFW_KEY_DELETE:
- modM = true;
- tweenking();
- break;
- //Изменение количество этажей
- case GLFW_KEY_PAGE_UP:
- floors++;
- break;
- case GLFW_KEY_PAGE_DOWN:
- floors--;
- break;
- //Сохранение состояния
- case GLFW_KEY_O:
- save();
- break;
- case GLFW_KEY_P:
- load();
- break;
- }
- }
- }
- void makeLight() {
- float light0_diffuse[] = { 0.8f, 0.8f, 0.8f };
- float light0_position[] = { -390, 290, 300, 1.0 };
- float light0_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
- float light0_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- float ambient[] = { 0.5f, 0.2f, 0.2f, 1.0f };
- float default_amb[] = { 0.2f, 0.2f, 0.2f, 1.0f };
- glEnable(GL_NORMALIZE);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- if (global_ambient)
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
- else
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT, default_amb);
- if (two_side)
- glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
- else
- glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
- if (local_viewer)
- glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
- else
- glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
- glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
- glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);
- glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
- }
- void tweenking()
- {
- int i, j, speed;
- int k = 0;
- printf("tweenking: h=%d\n", k);
- for (t = 0, speed = 0; speed <= TWINKIE_SPEED; t += dt, speed++) {
- for (i = 0; i < floors + 1; i += 1) {
- for (j = 0; j < Amount; j += 1) {
- base_side[i][j].x = (1 - t)*(1 - t)*(1 - t)*base_side[i][j].x + 3 * t*(1 - t)*(1 - t)*tw3_side[i][j].x + 3 * t*t*(1 - t)*tw1_side[i][j].x + t * t*t*tw2_side[i][j].x;
- base_side[i][j].y = (1 - t)*(1 - t)*(1 - t)*base_side[i][j].y + 3 * t*(1 - t)*(1 - t)*tw3_side[i][j].y + 3 * t*t*(1 - t)*tw1_side[i][j].y + t * t*t*tw2_side[i][j].y;
- base_side[i][j].z = (1 - t)*(1 - t)*(1 - t)*base_side[i][j].z + 3 * t*(1 - t)*(1 - t)*tw3_side[i][j].z + 3 * t*t*(1 - t)*tw1_side[i][j].z + t * t*t*tw2_side[i][j].z;
- }
- base_center[i].x = (1 - t)*(1 - t)*(1 - t)*base_center[i].x + 3 * t*(1 - t)*(1 - t)*tw3_center[i].x + 3 * t*t*(1 - t)*tw1_center[i].x + t * t*t*tw2_center[i].x;
- base_center[i].y = (1 - t)*(1 - t)*(1 - t)*base_center[i].y + 3 * t*(1 - t)*(1 - t)*tw3_center[i].y + 3 * t*t*(1 - t)*tw1_center[i].y + t * t*t*tw2_center[i].y;
- base_center[i].z = (1 - t)*(1 - t)*(1 - t)*base_center[i].z + 3 * t*(1 - t)*(1 - t)*tw3_center[i].z + 3 * t*t*(1 - t)*tw1_center[i].z + t * t*t*tw2_center[i].z;
- }
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- display();
- glfwSwapBuffers(WINDOW);
- Sleep(20);
- }
- modM = false;
- //CreateTwilFig();
- }
- void DrawFig(
- std::vector<std::vector<point>>& cyl_side,
- std::vector<point>& cyl_center)
- {
- glBindTexture(GL_TEXTURE_2D, textureID);
- glPolygonMode(GL_FRONT_AND_BACK, IS_FILL ? GL_FILL : GL_LINE);
- GLint j, i;
- for (j = 0; j < Amount - 1; j++) {
- for (i = 0; i < floors; i++) {
- glColor3f(1, 1, 0);
- glBegin(GL_TRIANGLES);
- glVertex3f(cyl_side[i][j].x, cyl_side[i][j].y, cyl_side[i][j].z);
- glVertex3f(cyl_center[i].x, cyl_center[i].y, cyl_center[i].z);
- glVertex3f(cyl_side[i][j + 1].x, cyl_side[i][j + 1].y, cyl_side[i][j + 1].z);
- glEnd();
- }
- glColor3f(1, 1, 0);
- glBegin(GL_TRIANGLES);
- glVertex3f(cyl_side[0][j].x, cyl_side[0][j].y, cyl_side[0][j].z);
- glVertex3f(cyl_center[floors].x, cyl_center[floors].y, cyl_center[floors].z);
- glVertex3f(cyl_side[0][j + 1].x, cyl_side[0][j + 1].y, cyl_side[0][j + 1].z);
- glEnd();
- }
- glColor3f(1, 1, 0);
- glBegin(GL_TRIANGLES);
- glVertex3f(cyl_side[0][j].x, cyl_side[0][j].y, cyl_side[0][j].z);
- glVertex3f(cyl_center[floors].x, cyl_center[floors].y, cyl_center[floors].z);
- glVertex3f(cyl_side[0][0].x, cyl_side[0][0].y, cyl_side[0][0].z);
- glEnd();
- for (i = 0; i < floors; i++) {
- glColor3f(1, 1, 0);
- glBegin(GL_TRIANGLES);
- glVertex3f(cyl_side[i][Amount - 1].x, cyl_side[i][Amount - 1].y, cyl_side[i][Amount - 1].z);
- glVertex3f(cyl_center[i].x, cyl_center[i].y, cyl_center[i].z);
- glVertex3f(cyl_side[i][0].x, cyl_side[i][0].y, cyl_side[i][0].z);
- glEnd();
- }
- }
- void CreateTwilFig1() {
- glBindTexture(GL_TEXTURE_2D, textureID);
- if (Amount < 3) Amount = 3;
- const float step = float(2 * M_PI) / Amount;
- float dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
- float dx1temp = 0, dy1temp = 0, dx2temp = 0, dy2temp = 0;
- float xCenterUpTemp = 0;
- float yCenterUpTemp = 0;
- float angle = 0;
- float hh = height;
- GLint i = 1, j;
- tw1_center.resize(floors + 2);
- tw1_side.resize(floors + 2);
- for (i = 0; i < floors + 2; i++) tw1_side[i].resize(Amount + 1);
- glPolygonMode(GL_FRONT_AND_BACK, IS_FILL ? GL_FILL : GL_LINE);
- for (float angle = 0, j = 0; angle <= float(2 * M_PI); j++, angle += step) {
- dx1 = ry * cosf(angle);
- dy1 = rx * sinf(angle);
- for (GLint i = 0; i < floors; i++) {
- dx1temp = (dx1 / floors) * (floors - i);
- dy1temp = (dy1 / floors) * (floors - i);
- xCenterUpTemp = -(xUp / floors) * (floors - i) + xUp;
- yCenterUpTemp = -(yUp / floors) * (floors - i) + yUp;
- tw1_side[i][j].x = dx1temp + xCenterUpTemp;
- tw1_side[i][j].y = dy1temp + yCenterUpTemp;
- tw1_side[i][j].z = hh - (hh / floors) * i;
- tw1_center[i].x = xCenterUpTemp;
- tw1_center[i].y = yCenterUpTemp;
- tw1_center[i].z = hh - (hh / floors) * i;
- }
- }
- tw1_center[floors].x = xUp;
- tw1_center[floors].y = yUp;
- tw1_center[floors].z = 0;
- }
- void CreateTwilFig3() {
- glBindTexture(GL_TEXTURE_2D, textureID);
- if (Amount < 3) Amount = 3;
- const float step = float(2 * M_PI) / Amount;
- float dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
- float dx1temp = 0, dy1temp = 0, dx2temp = 0, dy2temp = 0;
- float xCenterUpTemp = 0;
- float yCenterUpTemp = 0;
- float xUpT = 0;
- float yUpT = 0;
- float angle = 0;
- float hh = 2*height;
- xUpT = -xUp;
- yUpT = -yUp;
- GLint i = 1, j;
- tw3_center.resize(floors + 2);
- tw3_side.resize(floors + 2);
- for (i = 0; i < floors + 2; i++) tw3_side[i].resize(Amount + 1);
- glPolygonMode(GL_FRONT_AND_BACK, IS_FILL ? GL_FILL : GL_LINE);
- for (float angle = 0, j = 0; angle <= float(2 * M_PI); j++, angle += step) {
- dx1 = rx * cosf(angle);
- dy1 = ry * sinf(angle);
- for (GLint i = 0; i < floors; i++) {
- dx1temp = (dx1 / floors) * (floors - i);
- dy1temp = (dy1 / floors) * (floors - i);
- xCenterUpTemp = -(xUpT / floors) * (floors - i) + xUpT;
- yCenterUpTemp = -(yUpT / floors) * (floors - i) + yUpT;
- tw3_side[i][j].x = dx1temp + xCenterUpTemp;
- tw3_side[i][j].y = dy1temp + yCenterUpTemp;
- tw3_side[i][j].z = hh - (hh / floors) * i;
- tw3_center[i].x = xCenterUpTemp;
- tw3_center[i].y = yCenterUpTemp;
- tw3_center[i].z = hh - (hh / floors) * i;
- }
- }
- tw3_center[floors].x = xUpT;
- tw3_center[floors].y = yUpT;
- tw3_center[floors].z = 0;
- }
- void CreateTwilFig2() {
- glBindTexture(GL_TEXTURE_2D, textureID);
- if (Amount < 3) Amount = 3;
- const float step = float(2 * M_PI) / Amount;
- float dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
- float dx1temp = 0, dy1temp = 0, dx2temp = 0, dy2temp = 0;
- float xCenterUpTemp = 0;
- float yCenterUpTemp = 0;
- float angle = 0;
- float hh;
- if (check == -1) {
- hh = height;
- }
- else {
- hh = height + 0.5;
- }
- GLint i = 1, j;
- tw2_center.resize(floors + 2);
- tw2_side.resize(floors + 2);
- for (i = 0; i < floors + 2; i++) tw2_side[i].resize(Amount + 1);
- glPolygonMode(GL_FRONT_AND_BACK, IS_FILL ? GL_FILL : GL_LINE);
- for (float angle = 0, j = 0; angle <= float(2 * M_PI); j++, angle += step) {
- dx1 = rx * cosf(angle);
- dy1 = ry * sinf(angle);
- for (GLint i = 0; i < floors; i++) {
- dx1temp = (dx1 / floors) * (floors - i);
- dy1temp = (dy1 / floors) * (floors - i);
- xCenterUpTemp = -(xUp / floors) * (floors - i) + xUp;
- yCenterUpTemp = -(yUp / floors) * (floors - i) + yUp;
- tw2_side[i][j].x = dx1temp + xCenterUpTemp;
- tw2_side[i][j].y = dy1temp + yCenterUpTemp;
- tw2_side[i][j].z = hh - (hh / floors) * i;
- tw2_center[i].x = xCenterUpTemp;
- tw2_center[i].y = yCenterUpTemp;
- tw2_center[i].z = hh - (hh / floors) * i;
- }
- }
- tw2_center[floors].x = xUp;
- tw2_center[floors].y = yUp;
- tw2_center[floors].z = 0;
- }
- void CreateBasicFig() {
- glBindTexture(GL_TEXTURE_2D, textureID);
- if (Amount < 3) Amount = 3;
- const float step = float(2 * M_PI) / Amount;
- float dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
- float dx1temp = 0, dy1temp = 0, dx2temp = 0, dy2temp = 0;
- float xCenterUpTemp = 0;
- float yCenterUpTemp = 0;
- int hh = height;
- if (check == 1) {
- hh = height;
- }
- else {
- //hh = height * 2;
- hh = height;
- }
- float angle = 0;
- GLint i = 1, j;
- base_center.resize(floors + 2);
- base_side.resize(floors + 2);
- for (i = 0; i < floors + 2; i++) base_side[i].resize(Amount + 1);
- glPolygonMode(GL_FRONT_AND_BACK, IS_FILL ? GL_FILL : GL_LINE);
- for (float angle = 0, j = 0; angle <= float(2 * M_PI); j++, angle += step) {
- dx1 = rx * cosf(angle);
- dy1 = ry * sinf(angle);
- for (GLint i = 0; i < floors; i++) {
- dx1temp = (dx1 / floors) * (floors - i);
- dx2temp = (dx2 / floors) * (floors - i);
- dy1temp = (dy1 / floors) * (floors - i);
- dy2temp = (dy2 / floors) * (floors - i);
- xCenterUpTemp = -(xUp / floors) * (floors - i) + xUp;
- yCenterUpTemp = -(yUp / floors) * (floors - i) + yUp;
- base_side[i][j].x = dx1temp + xCenterUpTemp;
- base_side[i][j].y = dy1temp + yCenterUpTemp;
- base_side[i][j].z = hh - (hh / floors) * i;
- base_center[i].x = xCenterUpTemp;
- base_center[i].y = yCenterUpTemp;
- base_center[i].z = hh - (hh / floors) * i;
- }
- }
- base_center[floors].x = xUp;
- base_center[floors].y = yUp;
- base_center[floors].z = 0;
- }
- void display()
- {
- int width, height;
- glfwGetFramebufferSize(WINDOW, &width, &height);
- if (!modM) {
- CreateTwilFig1();
- CreateTwilFig2();
- CreateTwilFig3();
- }
- //Подключение текстуры
- //Static cube
- glViewport(0, 0, width / 2, height / 2);
- glEnable(GL_DEPTH_TEST);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-width, width, -height, height, -1000, 1000);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- //projection Ozy Вверху слева
- glViewport(0, height / 2 + 1, width / 2 + 1, height / 2);
- glEnable(GL_DEPTH_TEST);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-width, width, -height, height, -1000, 1000);
- glRotatef(90, 1, 0, 0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(-250, -250, 500);
- glTranslatef(MOVE_X + 350, MOVE_Y + 350, MOVE_Z - 500);
- glScaled(mSize, mSize, mSize);
- glRotatef(ROTATE_X, 1, 0, 0);
- glRotatef(ROTATE_Y, 0, 1, 0);
- glRotatef(ROTATE_Z, 0, 0, 1);
- if (modM) {
- DrawFig(base_side, base_center);
- }
- else {
- CreateBasicFig();
- DrawFig(base_side, base_center);
- }
- //projection Oxy Вверху справа
- glViewport(width / 2 + 1, height / 2 + 1, width / 2, height / 2);
- glEnable(GL_DEPTH_TEST);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-width, width, -height, height, -1000, 1000);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(MOVE_X, MOVE_Y, MOVE_Z - 500);
- glScaled(mSize, mSize, mSize);
- glRotatef(ROTATE_X, 1, 0, 0);
- glRotatef(ROTATE_Y, 0, 1, 0);
- glRotatef(ROTATE_Z, 0, 0, 1);
- if (modM) {
- DrawFig(base_side, base_center);
- }
- else {
- CreateBasicFig();
- DrawFig(base_side, base_center);
- }
- //projection Oxz Внизу справа
- glViewport(width / 2 + 1, 0, width / 2, height / 2);
- glEnable(GL_DEPTH_TEST);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-width, width, -height, height, -1000, 1000);
- glRotatef(90, 0, 1, 0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(-200, -200, 500);
- glTranslatef(MOVE_X + 350, MOVE_Y + 350, MOVE_Z - 500);
- glScaled(mSize, mSize, mSize);
- glRotatef(ROTATE_X, 1, 0, 0);
- glRotatef(ROTATE_Y, 0, 1, 0);
- glRotatef(ROTATE_Z, 0, 0, 1);
- if (modM) {
- DrawFig(base_side, base_center);
- }
- else {
- CreateBasicFig();
- DrawFig(base_side, base_center);
- }
- //DrawFigure2();
- //DrawNewFigure();
- }
- int main()
- {
- if (!glfwInit())
- exit(1);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
- GLFWwindow * window = glfwCreateWindow(800, 600, "Laba", NULL, NULL);
- WINDOW = window;
- if (!window)
- {
- glfwTerminate();
- exit(1);
- }
- glfwMakeContextCurrent(window);
- glfwSetKeyCallback(window, key);
- //СВЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕТА
- //makeLight();
- int w = 512, h = 512;
- unsigned char* image = SOIL_load_image("./met.bmp", &w, &h, 0, SOIL_LOAD_RGB);
- glGenTextures(1, &textureID);
- glBindTexture(GL_TEXTURE_2D, textureID);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
- SOIL_free_image_data(image);
- glBindTexture(GL_TEXTURE_2D, 0);
- while (!glfwWindowShouldClose(window)) {
- if (modT) {
- glEnable(GL_TEXTURE_2D);
- }
- else {
- glDisable(GL_TEXTURE_2D);
- }
- display(); //рисует
- glfwSwapBuffers(window); //Меняет буферы
- glfwPollEvents(); //Слушает нажатия
- }
- glfwDestroyWindow(window);
- glfwTerminate();
- return 0;
- }
- //void DrawFigure() {
- // glBindTexture(GL_TEXTURE_2D, textureID);
- //
- // if (Amount < 3) Amount = 3;
- // const float step = float(2 * M_PI) / Amount;
- //
- // float dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
- // float dx1temp = 0, dy1temp = 0, dx2temp = 0, dy2temp = 0;
- // float xCenterUpTemp = 0;
- // float yCenterUpTemp = 0;
- //
- // float angle = 0;
- //
- // float len = hight / 2;
- //
- // GLint i = 1;
- //
- // glPolygonMode(GL_FRONT_AND_BACK, IS_FILL ? GL_FILL : GL_LINE);
- //
- // for (float angle = 0; angle <= float(2 * M_PI); angle += step) {
- // dx1 = rx * cosf(angle);
- // dy1 = ry * sinf(angle);
- // dx2 = rx * cosf(angle + step);
- // dy2 = ry * sinf(angle + step);
- //
- // for (GLint i = 0; i < floors; i++) {
- // dx1temp = (dx1 / floors) * (floors - i);
- // dx2temp = (dx2 / floors) * (floors - i);
- // dy1temp = (dy1 / floors) * (floors - i);
- // dy2temp = (dy2 / floors) * (floors - i);
- // xCenterUpTemp = -(xUp / floors) * (floors - i) + xUp;
- // yCenterUpTemp = -(yUp / floors) * (floors - i) + yUp;
- //
- //
- //
- // glColor3d(0, 1, 0);
- // glBegin(GL_TRIANGLES);
- // glVertex3f(xCenterUpTemp, yCenterUpTemp, len - hight / floors * i);
- // glVertex3f(dx1temp + xCenterUpTemp, dy1temp + yCenterUpTemp, len - hight / floors * i);
- // glVertex3f(dx2temp + xCenterUpTemp, dy2temp + yCenterUpTemp, len - hight / floors * i);
- // glEnd();
- // }
- // glColor3d(1, 1, 1);
- // glBegin(GL_TRIANGLES);
- // glVertex3f(xUp, yUp, -len);
- // glVertex3f(dx1 + xDown, dy1 + yDown, len);
- // glVertex3f(dx2 + xDown, dy2 + yDown, len);
- // glEnd();
- //
- // //glBegin(GL_TRIANGLES);// Основание
- // //glVertex3f(xDown, yDown, len);
- // //glVertex3f(dx1 + xDown, dy1 + yDown, len);
- // //glVertex3f(dx2 + xDown, dy2 + yDown, len);
- // //glEnd();
- //
- // }
- //
- //
- //
- // //printf("cone_renewed: s_j=%d\n", floors);
- // //glDisable(GL_TEXTURE_2D);
- //
- //
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement