Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.76 KB | None | 0 0
  1. // dear imgui: standalone example application for GLFW + OpenGL 3, using programmable pipeline
  2. // If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp.
  3. // (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
  4.  
  5. #include "imgui.h"
  6. #include "imgui_impl_glfw.h"
  7. #include "imgui_impl_opengl3.h"
  8. #include <stdio.h>
  9. #include <vector>
  10. #include <glm/glm.hpp>
  11. #include <glm/gtc/matrix_transform.hpp>
  12. #include <glm/gtc/type_ptr.hpp>
  13. #define STB_IMAGE_IMPLEMENTATION
  14. #include <stb_image.h>
  15.  
  16. // About OpenGL function loaders: modern OpenGL doesn't have a standard header file and requires individual function pointers to be loaded manually.
  17. // Helper libraries are often used for this purpose! Here we are supporting a few common ones: gl3w, glew, glad.
  18. // You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
  19. #if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
  20. #include <GL/gl3w.h> // Initialize with gl3wInit()
  21. #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
  22. #include <GL/glew.h> // Initialize with glewInit()
  23. #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
  24. #include <glad/glad.h> // Initialize with gladLoadGL()
  25. #else
  26. #include IMGUI_IMPL_OPENGL_LOADER_CUSTOM
  27. #endif
  28.  
  29. #include <GLFW/glfw3.h> // Include glfw3.h after our OpenGL definitions
  30.  
  31. static void glfw_error_callback(int error, const char* description)
  32. {
  33. fprintf(stderr, "Glfw Error %d: %s\n", error, description);
  34. }
  35. class Camera
  36. {
  37.  
  38. float rotationAngle = glm::half_pi<float>();
  39. float elevationAngle = 0.0f;
  40. float speed = 0.05f;
  41. float elevationBoundary = 1.5f;
  42. public:
  43. void moveUp()
  44. {
  45. if (elevationAngle + speed < elevationBoundary)
  46. {
  47. elevationAngle += speed;
  48. }
  49. }
  50. void moveDown()
  51. {
  52. if (elevationAngle - speed > -elevationBoundary)
  53. {
  54. elevationAngle -= speed;
  55. }
  56. }
  57. void moveRight()
  58. {
  59. rotationAngle += speed;
  60. }
  61. void moveLeft()
  62. {
  63. rotationAngle -= speed;
  64. }
  65. glm::vec3 getPos()
  66. {
  67. return glm::vec3(cos(rotationAngle) * cos(elevationAngle), sin(elevationAngle), sin(rotationAngle) * cos(elevationAngle));
  68. }
  69. };
  70.  
  71. void processInput(GLFWwindow *window);
  72. void framebuffer_size_callback(GLFWwindow* window, int width, int height);
  73. void prepareShader(unsigned int &shader, GLenum type, const GLchar ** source);
  74. void generateCube(float x, float y, float z, float size, std::vector<float> *vertices, std::vector<unsigned int> *indices);
  75. void generateSponge(float x, float y, float z, float size, int recursionLevel, std::vector<float> *vertices, std::vector<unsigned int> *indices);
  76. void fillTextureCoords(std::vector<float> &data, float* textureCoords, int totalTextureCoordsNumber);
  77.  
  78. const char *vertexShaderSource = "#version 330 core\n"
  79. "layout (location = 0) in vec3 aPos;\n"
  80. "layout (location = 1) in vec2 aTexCoord;\n"
  81. "out vec2 TexCoord;\n"
  82. "uniform mat4 view;\n"
  83. "uniform mat4 projection;\n"
  84. "void main()\n"
  85. "{\n"
  86. " gl_Position = projection * view * vec4(aPos, 1.0);\n"
  87. " TexCoord = aTexCoord;\n"
  88. "}\0";
  89. const char *fragmentShaderSource = "#version 330 core\n"
  90. "in vec2 TexCoord;\n"
  91. "out vec4 FragColor;\n"
  92. "uniform vec4 color;\n"
  93. "uniform sampler2D myTexture;\n"
  94. "void main()\n"
  95. "{\n"
  96. " FragColor = texture(myTexture, TexCoord) * color;\n"
  97. "}\n\0";
  98.  
  99. Camera cam;
  100.  
  101. int main(int, char**)
  102. {
  103. // Setup window
  104. glfwSetErrorCallback(glfw_error_callback);
  105. if (!glfwInit())
  106. return 1;
  107.  
  108. // Decide GL+GLSL versions
  109. #if __APPLE__
  110. // GL 3.2 + GLSL 150
  111. const char* glsl_version = "#version 150";
  112. glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  113. glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
  114. glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
  115. glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
  116. #else
  117. // GL 4.3 + GLSL 430
  118. const char* glsl_version = "#version 430";
  119. glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
  120. glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  121. glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
  122. glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only
  123. #endif
  124. float windowHeight = 800, windowWidth = 800;
  125. GLFWwindow* window = glfwCreateWindow(windowHeight, windowWidth, "Sierpinski", NULL, NULL);
  126. if (window == NULL)
  127. {
  128. return 1;
  129. }
  130. glfwMakeContextCurrent(window);
  131. glfwSwapInterval(1);
  132.  
  133. // Initialize OpenGL loader
  134. #if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
  135. bool err = gl3wInit() != 0;
  136. #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
  137. bool err = glewInit() != GLEW_OK;
  138. #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
  139. bool err = !gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
  140. #endif
  141. if (err)
  142. {
  143. fprintf(stderr, "Failed to initialize OpenGL loader!\n");
  144. return 1;
  145. }
  146.  
  147. glViewport(0, 0, windowHeight, windowWidth);
  148. glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
  149.  
  150. // Setup Dear ImGui binding
  151. IMGUI_CHECKVERSION();
  152. ImGui::CreateContext();
  153. ImGuiIO& io = ImGui::GetIO(); (void)io;
  154. //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
  155. //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
  156.  
  157. ImGui_ImplGlfw_InitForOpenGL(window, true);
  158. ImGui_ImplOpenGL3_Init(glsl_version);
  159.  
  160. // Setup style
  161. ImGui::StyleColorsDark();
  162. //ImGui::StyleColorsClassic();
  163.  
  164.  
  165. unsigned int vertexShader, fragmentShader, shaderProgram;
  166. prepareShader(vertexShader, GL_VERTEX_SHADER, &vertexShaderSource);
  167. prepareShader(fragmentShader, GL_FRAGMENT_SHADER, &fragmentShaderSource);
  168. shaderProgram = glCreateProgram();
  169. glAttachShader(shaderProgram, vertexShader);
  170. glAttachShader(shaderProgram, fragmentShader);
  171. glLinkProgram(shaderProgram);
  172. glDeleteShader(vertexShader);
  173. glDeleteShader(fragmentShader);
  174.  
  175.  
  176. float textureCoords[] = {
  177. 0.0f, 0.0f,
  178. 1.0f, 0.0f,
  179. 0.0f, 1.0f,
  180. 1.0f, 1.0f
  181. };
  182. const int TOTAL_TEXTURE_COORDS_NUMBER = 8;
  183. //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  184.  
  185. int width, height, nrChannels;
  186. unsigned char *textureData = stbi_load("textures.jpg", &width, &height, &nrChannels, 0);
  187. stbi_set_flip_vertically_on_load(true);
  188. std::vector<float>vertices;
  189. std::vector<unsigned int>indices;
  190. float x = 0.8, y = 0.8, z = 0.8, size = 1;
  191. int recursionLevel = 1;
  192.  
  193. if (recursionLevel != 0) {
  194. generateSponge(x, y, z, size, recursionLevel - 1, &vertices, &indices);
  195. }
  196. else {
  197. generateCube(x, y, z, size, &vertices, &indices);
  198. }
  199.  
  200. //fillTextureCoords(vertices, textureCoords, TOTAL_TEXTURE_COORDS_NUMBER);
  201.  
  202. unsigned int VBO, VAO, EBO;
  203. glGenVertexArrays(1, &VAO);
  204. glBindVertexArray(VAO);
  205.  
  206. unsigned int texture;
  207. glGenTextures(1, &texture);
  208. glBindTexture(GL_TEXTURE_2D, texture);
  209.  
  210. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  211. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  212. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  213. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  214.  
  215. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, textureData);
  216. glGenerateMipmap(GL_TEXTURE_2D);
  217. stbi_image_free(textureData);
  218.  
  219. glGenBuffers(1, &EBO);
  220. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
  221. glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(int), &indices.front(), GL_DYNAMIC_DRAW);
  222.  
  223. glGenBuffers(1, &VBO);
  224. glBindBuffer(GL_ARRAY_BUFFER, VBO);
  225. glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), &vertices.front(), GL_DYNAMIC_DRAW);
  226.  
  227. glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
  228. glEnableVertexAttribArray(0);
  229. glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
  230. glEnableVertexAttribArray(1);
  231.  
  232. glBindTexture(GL_TEXTURE_2D, texture);
  233. glBindVertexArray(VAO);
  234.  
  235.  
  236. int pyramidColorLocation = glGetUniformLocation(shaderProgram, "color");
  237. int viewLocation = glGetUniformLocation(shaderProgram, "view");
  238. ImVec4 backgroundColor = ImVec4(0.5f, 0.5f, 0.0f, 1.0f);
  239. ImVec4 pyramidColor = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
  240.  
  241. glClearDepth(1.0f);
  242. glEnable(GL_DEPTH_TEST);
  243.  
  244. glUseProgram(shaderProgram);
  245. glm::mat4 projection(1.0f);
  246. projection = glm::ortho(-1.0f, 1.0f, -1.0f, 1.0f, -10.0f, 10.0f);
  247. //projection = glm::scale(projection, glm::vec3(0.5f, 0.5f, 0.5f));
  248.  
  249. int projectionLocation = glGetUniformLocation(shaderProgram, "projection");
  250. glUniformMatrix4fv(projectionLocation, 1, GL_FALSE, glm::value_ptr(projection));
  251. while (!glfwWindowShouldClose(window))
  252. {
  253. glfwPollEvents();
  254. // Start the Dear ImGui frame
  255. ImGui_ImplOpenGL3_NewFrame();
  256. ImGui_ImplGlfw_NewFrame();
  257. ImGui::NewFrame();
  258.  
  259. {
  260. ImGui::Begin("settings");
  261. ImGui::SetWindowSize(ImVec2(300, 100));
  262. ImGui::SetWindowPos(ImVec2(0, 0));
  263. ImGui::SliderInt("level", &recursionLevel, 0, 5);
  264. if (ImGui::Button("update"))
  265. {
  266. vertices.clear();
  267. indices.clear();
  268. if (recursionLevel != 0) {
  269. generateSponge(x, y, z, size, recursionLevel - 1, &vertices, &indices);
  270. }
  271. else {
  272. generateCube(x, y, z, size, &vertices, &indices);
  273. }
  274. glBindBuffer(GL_ARRAY_BUFFER, VBO);
  275. glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), &vertices.front(), GL_DYNAMIC_DRAW);
  276. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
  277. glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(int), &indices.front(), GL_DYNAMIC_DRAW);
  278. //glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
  279. glEnableVertexAttribArray(0);
  280. }
  281. ImGui::ColorEdit3("triangles", (float*)&pyramidColor);
  282. ImGui::End();
  283. }
  284. glUseProgram(shaderProgram);
  285.  
  286. glm::mat4 view(1.0f);
  287. view = glm::lookAt(cam.getPos(), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
  288. glUniformMatrix4fv(viewLocation, 1, GL_FALSE, glm::value_ptr(view));
  289.  
  290. glClearColor(backgroundColor.x, backgroundColor.y, backgroundColor.z, backgroundColor.w);
  291. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  292.  
  293. glUniform4f(pyramidColorLocation, pyramidColor.x, pyramidColor.y, pyramidColor.z, pyramidColor.w);
  294.  
  295. glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);
  296. ImGui::Render();
  297. ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
  298.  
  299. glfwSwapBuffers(window);
  300. processInput(window);
  301. }
  302.  
  303. // Cleanup
  304. ImGui_ImplOpenGL3_Shutdown();
  305. ImGui_ImplGlfw_Shutdown();
  306. ImGui::DestroyContext();
  307.  
  308. glfwTerminate();
  309. return 0;
  310. }
  311.  
  312. void processInput(GLFWwindow *window)
  313. {
  314. if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
  315. glfwSetWindowShouldClose(window, true);
  316.  
  317. if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS)
  318. cam.moveUp();
  319. if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS)
  320. cam.moveDown();
  321. if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS)
  322. cam.moveLeft();
  323. if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS)
  324. cam.moveRight();
  325. }
  326. void framebuffer_size_callback(GLFWwindow* window, int width, int height)
  327. {
  328. glViewport(0, 0, width, height);
  329. }
  330.  
  331. void prepareShader(unsigned int &shader, GLenum type, const GLchar ** source)
  332. {
  333. shader = glCreateShader(type);
  334. glShaderSource(shader, 1, source, NULL);
  335. glCompileShader(shader);
  336. }
  337.  
  338. void generateCube(float x, float y, float z, float size, std::vector<GLfloat> *vertices, std::vector<unsigned int> *indices) {
  339. float smallSize = size / 3;
  340. float smalltextureSize = 1 / 3;
  341. int index = 0;
  342. if (indices->size() > 6) {
  343. index = indices->at(indices->size() - 5) + 1;
  344. }
  345. std::vector<GLfloat> newVertices = {
  346. x, y, z, 1,1,
  347. x - size, y, z, 0,1,
  348. x - size, y, z - size, 0,0,
  349. x, y, z - size, 1,0,
  350.  
  351. x, y - size, z, 0,0,
  352. x - size, y - size, z,0,1,
  353. x - size, y - size, z - size,1,0,
  354. x, y - size, z - size,1,1,
  355.  
  356. //top small +
  357. x - smallSize, y, z - smallSize,1 - smalltextureSize,1 - smalltextureSize,
  358. x - 2 * smallSize, y, z - smallSize,0 + smalltextureSize,1 - smalltextureSize,
  359. x - 2 * smallSize, y, z - 2 * smallSize, 0 + smalltextureSize,0 + smalltextureSize,
  360. x - smallSize, y, z - 2 * smallSize,1 - smalltextureSize,0 + smalltextureSize,
  361.  
  362. //back small +
  363. x - smallSize, y - smallSize, z - size,0, 0,
  364. x - 2 * smallSize, y - smallSize, z - size,0, 1,
  365. x - 2 * smallSize, y - 2 * smallSize, z - size,1, 0,
  366. x - smallSize, y - 2 * smallSize, z - size,1, 1,
  367.  
  368. //left small +
  369. x,y - smallSize, z - smallSize,0, 0,
  370. x,y - smallSize, z - 2 * smallSize,0, 1,
  371. x,y - 2 * smallSize, z - 2 * smallSize,1, 0,
  372. x,y - 2 * smallSize, z - smallSize,1, 1,
  373.  
  374. //front small +
  375. x - smallSize, y - smallSize, z,0, 0,
  376. x - 2 * smallSize, y - smallSize, z,0, 1,
  377. x - 2 * smallSize, y - 2 * smallSize, z,1, 0,
  378. x - smallSize, y - 2 * smallSize, z,1, 1,
  379.  
  380. //right small
  381. x - size,y - smallSize, z - smallSize,0, 0,
  382. x - size,y - smallSize, z - 2 * smallSize,0, 1,
  383. x - size,y - 2 * smallSize, z - 2 * smallSize,1, 0,
  384. x - size,y - 2 * smallSize, z - smallSize,1, 1,
  385.  
  386. //bottom small +
  387. x - smallSize, y - size, z - smallSize,0, 0,
  388. x - 2 * smallSize, y - size, z - smallSize,0, 1,
  389. x - 2 * smallSize, y - size, z - 2 * smallSize,1, 0,
  390. x - smallSize, y - size, z - 2 * smallSize, 1, 1
  391. };
  392.  
  393. std::vector<unsigned int> newIndices{
  394. //top
  395. 0,8,9,0,9,1,
  396. 1,9,10,1,10,2,
  397. 2,10,11,2,11,3,
  398. 3,11,8,3,8,0,
  399. //back
  400. 3,12,13,3,13,2,
  401. 2,13,14,2,14,6,
  402. 6,14,15,6,15,7,
  403. 7,15,12,7,12,3,
  404. //right
  405. 0,16,17,0,17,3,
  406. 3,17,18,3,18,7,
  407. 7,18,19,7,19,4,
  408. 4,19,16,4,16,0,
  409. //front
  410. 0,20,21,0,21,1,
  411. 1,21,22,1,22,5,
  412. 5,22,23,5,23,4,
  413. 4,23,20,4,20,0,
  414. //left
  415. 1,24,25,1,25,2,
  416. 2,25,26,2,26,6,
  417. 6,26,27,6,27,5,
  418. 5,27,24,5,24,1,
  419. //bottom
  420. 4,28,29,4,29,5,
  421. 5,29,30,5,30,6,
  422. 6,30,31,6,31,7,
  423. 7,31,28,7,28,4
  424. };
  425.  
  426. for (int i = 0; i < indices->size(); i++) {
  427. indices->at(i) += index;
  428. }
  429.  
  430. vertices->insert(vertices->end(), newVertices.begin(), newVertices.end());
  431. indices->insert(indices->end(), newIndices.begin(), newIndices.end());
  432.  
  433. }
  434.  
  435. void generateSponge(float x, float y, float z, float size, int recursionLevel, std::vector<GLfloat> *vertices, std::vector<unsigned int> *indices) {
  436. float smallSize = size / 3;
  437. if (recursionLevel > 0) {
  438. //top
  439. generateSponge(x, y, z, smallSize, recursionLevel - 1, vertices, indices);
  440. generateSponge(x - smallSize, y, z, smallSize, recursionLevel - 1, vertices, indices);
  441. generateSponge(x - 2 * smallSize, y, z, smallSize, recursionLevel - 1, vertices, indices);
  442.  
  443. generateSponge(x, y, z - smallSize, smallSize, recursionLevel - 1, vertices, indices);
  444. generateSponge(x - 2 * smallSize, y, z - smallSize, smallSize, recursionLevel - 1, vertices, indices);
  445.  
  446. generateSponge(x, y, z - 2 * smallSize, smallSize, recursionLevel - 1, vertices, indices);
  447. generateSponge(x - smallSize, y, z - 2 * smallSize, smallSize, recursionLevel - 1, vertices, indices);
  448. generateSponge(x - 2 * smallSize, y, z - 2 * smallSize, smallSize, recursionLevel - 1, vertices, indices);
  449.  
  450. //middle
  451. generateSponge(x, y - smallSize, z, smallSize, recursionLevel - 1, vertices, indices);
  452. generateSponge(x - 2 * smallSize, y - smallSize, z, smallSize, recursionLevel - 1, vertices, indices);
  453.  
  454. generateSponge(x, y - smallSize, z - 2 * smallSize, smallSize, recursionLevel - 1, vertices, indices);
  455. generateSponge(x - 2 * smallSize, y - smallSize, z - 2 * smallSize, smallSize, recursionLevel - 1, vertices, indices);
  456.  
  457. //bottom
  458. generateSponge(x, y - 2 * smallSize, z, smallSize, recursionLevel - 1, vertices, indices);
  459. generateSponge(x - smallSize, y - 2 * smallSize, z, smallSize, recursionLevel - 1, vertices, indices);
  460. generateSponge(x - 2 * smallSize, y - 2 * smallSize, z, smallSize, recursionLevel - 1, vertices, indices);
  461.  
  462. generateSponge(x, y - 2 * smallSize, z - smallSize, smallSize, recursionLevel - 1, vertices, indices);
  463. generateSponge(x - 2 * smallSize, y - 2 * smallSize, z - smallSize, smallSize, recursionLevel - 1, vertices, indices);
  464.  
  465. generateSponge(x, y - 2 * smallSize, z - 2 * smallSize, smallSize, recursionLevel - 1, vertices, indices);
  466. generateSponge(x - smallSize, y - 2 * smallSize, z - 2 * smallSize, smallSize, recursionLevel - 1, vertices, indices);
  467. generateSponge(x - 2 * smallSize, y - 2 * smallSize, z - 2 * smallSize, smallSize, recursionLevel - 1, vertices, indices);
  468. }
  469. else {
  470. //top
  471. generateCube(x, y, z, smallSize, vertices, indices);
  472. generateCube(x - smallSize, y, z, smallSize, vertices, indices);
  473. generateCube(x - 2 * smallSize, y, z, smallSize, vertices, indices);
  474.  
  475. generateCube(x, y, z - smallSize, smallSize, vertices, indices);
  476. generateCube(x - 2 * smallSize, y, z - smallSize, smallSize, vertices, indices);
  477.  
  478. generateCube(x, y, z - 2 * smallSize, smallSize, vertices, indices);
  479. generateCube(x - smallSize, y, z - 2 * smallSize, smallSize, vertices, indices);
  480. generateCube(x - 2 * smallSize, y, z - 2 * smallSize, smallSize, vertices, indices);
  481.  
  482. //middle
  483. generateCube(x, y - smallSize, z, smallSize, vertices, indices);
  484. generateCube(x - 2 * smallSize, y - smallSize, z, smallSize, vertices, indices);
  485.  
  486. generateCube(x, y - smallSize, z - 2 * smallSize, smallSize, vertices, indices);
  487. generateCube(x - 2 * smallSize, y - smallSize, z - 2 * smallSize, smallSize, vertices, indices);
  488.  
  489. //bottom
  490. generateCube(x, y - 2 * smallSize, z, smallSize, vertices, indices);
  491. generateCube(x - smallSize, y - 2 * smallSize, z, smallSize, vertices, indices);
  492. generateCube(x - 2 * smallSize, y - 2 * smallSize, z, smallSize, vertices, indices);
  493.  
  494. generateCube(x, y - 2 * smallSize, z - smallSize, smallSize, vertices, indices);
  495. generateCube(x - 2 * smallSize, y - 2 * smallSize, z - smallSize, smallSize, vertices, indices);
  496.  
  497. generateCube(x, y - 2 * smallSize, z - 2 * smallSize, smallSize, vertices, indices);
  498. generateCube(x - smallSize, y - 2 * smallSize, z - 2 * smallSize, smallSize, vertices, indices);
  499. generateCube(x - 2 * smallSize, y - 2 * smallSize, z - 2 * smallSize, smallSize, vertices, indices);
  500. }
  501. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement