Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <GLFW/glfw3.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <iostream>
- #include <math.h>
- #include <GL/glu.h>
- #include <vector>
- void print(float[]);
- using namespace std;
- class level{
- public:
- vector<double> point;
- vector<vector<double>> points;
- level(double h){
- point.reserve(3);
- points.reserve(100);
- double x, y,phi,r1 = 4*sqrt(h),r2 = 2 * sqrt(h);
- phi = 0;
- while (phi < 6.2){
- x = r1*cos(phi);
- y = r2*sin(phi);
- point.emplace_back(x);
- point.emplace_back(y);
- point.emplace_back(h);
- points.emplace_back(point);
- }
- }
- };
- double xpos, ypos;
- // 24 вариант
- static void error_callback(int error, const char* description)
- {
- fputs(description, stderr);
- }
- static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
- {
- if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
- glfwSetWindowShouldClose(window, GL_TRUE);
- }
- void make3per() {
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- double M[] = {
- 1 , 0 , 0 , 0 ,
- 0 , 1 , 0 , 0 ,
- 0 , 0 , -1.5 , 0 ,
- 0 , 0 , -0.9, 3
- };
- double phi = -0.2;
- double M1[] = {
- cos(-phi) , 0 , sin(-phi) , 0,
- 0 , 1 , 0 , 0,
- -sin(-phi), 0 , cos(-phi) , 0,
- 0 , 0 , 0, 1
- };
- double M3[] = {
- 1 , 0 , 0 , 0,
- 0 , cos(phi) , sin(phi) , 0,
- 0 , -sin(phi) , cos(phi) , 0,
- 0 , 0 , 0, 1
- };
- glLoadMatrixd(M);
- glMultMatrixd(M1);
- glMultMatrixd(M3);
- }
- int main(void)
- {
- double xCenter = 0.f, yCenter = 0.f, zCenter = 0.0f, scale = 1.f;
- int rAngle = 0, dAngle = 0;
- double h = 0;
- //грани
- float front[] = { 0.f ,1.f ,1.f,
- 0.f,0.f,0.f,
- 0.5f,0.f,0.f,
- 0.5f,0.5f,0.f,
- 0.f,0.5f,0.f
- };
- float back[] = { 0.f ,0.5f ,1.f,
- 0.f,0.f,0.5f,
- 0.5f,0.f,0.5f,
- 0.5f,0.5f,0.5f,
- 0.f,0.5f,0.5f
- };
- float down[] = { 1.f ,0.5f, 0.f,
- 0.f,0.f,0.f,
- 0.5f,0.f,0.f,
- 0.5f,0.f,0.5f,
- 0.f,0.f,0.5f
- };
- float top[] = { 1.f ,1.f ,0.f,
- 0.f,0.5f,0.f,
- 0.5f,0.5f,0.f,
- 0.5f,0.5f,0.5f,
- 0.f,0.5f,0.5f
- };
- float lleft[] = { 0.f,1.f,0.5f,
- 0.f,0.f,0.f,
- 0.f,0.f,0.5f,
- 0.f,0.5f,0.5f,
- 0.f,0.5f,0.f
- };
- float rright[] = { 0.5f,1.f,0.f,
- 0.5f,0.f,0.f,
- 0.5f,0.f,0.5f,
- 0.5f,0.5f,0.5f,
- 0.5f,0.5f,0.f
- };
- vector<level> l;
- for (int i = 0; i < 30; i++){
- level a(h);
- l[i] = a;
- h += 0.1;
- }
- GLFWwindow* window;
- glfwSetErrorCallback(error_callback);
- if (!glfwInit()) {
- exit(EXIT_FAILURE);
- }
- window = glfwCreateWindow(800, 800, "Laba2", NULL, NULL);
- if (!window) {
- glfwTerminate();
- }
- glfwMakeContextCurrent(window);
- glfwSetKeyCallback(window, key_callback);
- int width, height;
- double ratio;
- make3per();
- glfwGetFramebufferSize(window, &width, &height);
- ratio = width / height;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_MODELVIEW_MATRIX);
- glEnable(GL_DEPTH_TEST);
- while (!glfwWindowShouldClose(window))
- {
- glfwGetCursorPos(window, &xpos, &ypos);
- glClearColor(0, 0, 0, 0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- /*for (int i = 0; i < 30; i++) {
- level a = l[i];
- for(int j = 0 ; j < l[i].points.size() - 1 ; j++){
- glBegin(GL_LINES);
- vector<double> p1 = l[i].points[j];
- vector<double> p2 = l[i].points[j + 1];
- p1.reserve(3);
- p2.reserve(3);
- glColor3d(1, 0, 0);
- glVertex3d(p1[0], p1[1], p1[2]);
- glVertex3d(p2[0], p2[1], p2[2]);
- glEnd();
- }
- }*/
- //отрисовка граней
- /*print(back);
- print(front);
- print(lleft);
- print(rright);
- print(down);
- print(top);*/
- glfwSwapBuffers(window);
- glfwPollEvents();
- }
- glfwTerminate();
- exit(EXIT_SUCCESS);
- }
- void print(float plane[]) {
- glBegin(GL_QUADS);
- glVertex3d(plane[3], plane[4], plane[5]);
- glColor3f(plane[0] + xpos / 300, plane[1] - xpos / 200, plane[2] + ypos / 900);
- glVertex3d(plane[6], plane[7], plane[8]);
- glColor3f(plane[0] - xpos / 900, plane[1] - xpos / 700, plane[2] - ypos / 900);
- glVertex3d(plane[9], plane[10], plane[11]);
- glColor3f(plane[0] + xpos / 900, plane[1] + xpos / 300, plane[2] - ypos / 600);
- glVertex3d(plane[12], plane[13], plane[14]);
- glColor3f(plane[0] - xpos / 800, plane[1] + xpos / 900, plane[2] + ypos / 900);
- glEnd();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement