From 8b84258c1af5b39f5f60652fa2883bc4c19c1b81 Mon Sep 17 00:00:00 2001 From: leca Date: Tue, 18 Nov 2025 00:17:47 +0300 Subject: [PATCH] Specify opengl version in cmake, fix some artifacts --- .vscode/launch.json | 3 --- CMakeLists.txt | 2 +- src/coil/coil.cpp | 22 ++++++++++++------- src/coil/coil.hpp | 2 +- src/coil/segment.cpp | 52 -------------------------------------------- src/coil/segment.hpp | 1 - src/main.cpp | 4 ++-- 7 files changed, 18 insertions(+), 68 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index b73002c..d383d53 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,7 +1,4 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fe7e95..a87cc35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src add_executable(TimeCoil ${PROJECT_SOURCES}) find_package(glfw3 3.4 REQUIRED) -find_package(OpenGL REQUIRED) +find_package(OpenGL 3.3 REQUIRED) find_package(glm REQUIRED) target_link_libraries(TimeCoil glfw OpenGL::GL glm::glm) diff --git a/src/coil/coil.cpp b/src/coil/coil.cpp index 7df6f4f..b112950 100644 --- a/src/coil/coil.cpp +++ b/src/coil/coil.cpp @@ -87,6 +87,10 @@ uint32_t Coil::fillEBO() { for (CoilSegment &segment : segments) { indicesLength += segment.getDaysAmount() * segment.getSlicePointsAmount() * 6; } + // We subtract this because last day of the uppermost segment will not have connections to + // the next day beacuse there is no next day :) + indicesLength -= segments[segments.size() - 1].getSlicePointsAmount() * 6; + uint32_t *indices = (uint32_t *)malloc(indicesLength * sizeof(uint32_t)); uint32_t currentIndex = 0; @@ -100,7 +104,10 @@ uint32_t Coil::fillEBO() { for (uint32_t day = 0; day < segment.getDaysAmount(); day++) { for (uint32_t pointOfSlice = 0; pointOfSlice < slicePointsAmount; pointOfSlice++) { uint32_t dayOffset = day * slicePointsAmount; - uint32_t currentPointIndex = yearOffset + dayOffset + pointOfSlice - 1; + uint32_t currentPointIndex = yearOffset + dayOffset + pointOfSlice; + if (segmentNumber == segments.size() - 1 && day == segment.getDaysAmount() - 1) { + continue; + } // First triangle indices[currentIndex] = currentPointIndex; currentIndex++; @@ -108,18 +115,17 @@ uint32_t Coil::fillEBO() { currentIndex++; indices[currentIndex] = currentPointIndex + 1; currentIndex++; + std::cout << segment.getSlicePointsAmount() << " " << pointOfSlice << std::endl; // Second triangle - //if (pointOfSlice % (sliceDetalization+1) == 0 && pointOfSlice != 0) { - if (pointOfSlice == segment.getSliceDetailization() - 1 && - pointOfSlice != 0) { + + indices[currentIndex] = currentPointIndex + 1; + currentIndex++; + + if (pointOfSlice == segment.getSlicePointsAmount() - 1) { indices[currentIndex] = currentPointIndex - (slicePointsAmount - 1); currentIndex++; - indices[currentIndex] = currentPointIndex + 1; - currentIndex++; indices[currentIndex] = currentPointIndex; } else { - indices[currentIndex] = currentPointIndex + 1; - currentIndex++; indices[currentIndex] = currentPointIndex + slicePointsAmount + 1; currentIndex++; indices[currentIndex] = currentPointIndex + slicePointsAmount; diff --git a/src/coil/coil.hpp b/src/coil/coil.hpp index 6916141..f83fa00 100644 --- a/src/coil/coil.hpp +++ b/src/coil/coil.hpp @@ -7,7 +7,7 @@ // Coil segment is a one turn of a coil -// Coil slice is a set of points that define slice of coil +// (Segment) slice is a set of points that define shape of the segment class Coil { // distance between coil center and nearest to it coil edge diff --git a/src/coil/segment.cpp b/src/coil/segment.cpp index a85c4cc..7eeaef4 100644 --- a/src/coil/segment.cpp +++ b/src/coil/segment.cpp @@ -151,58 +151,6 @@ void CoilSegment::constructSegment(float *slice) { } free(slice); } -uint64_t CoilSegment::fillEBO(uint64_t EBO) { - uint64_t indicesLength = 6 * slicePointsAmount * getDaysAmount(); - uint64_t currentIndex = 0; - uint64_t* indices = (uint64_t*) calloc(indicesLength, sizeof(uint64_t)); - for (uint64_t day = 0; day < getDaysAmount() - 1; day ++) { - for (uint64_t pointOfSlice = 0; pointOfSlice < slicePointsAmount; pointOfSlice ++) { - // cout << currentIndex << endl; - uint64_t dayOffset = day * slicePointsAmount; - uint64_t currentPointIndex = dayOffset + pointOfSlice; - - //First triangle - indices[currentIndex] = currentPointIndex; - currentIndex ++; - indices[currentIndex] = currentPointIndex + slicePointsAmount; - currentIndex ++; - indices[currentIndex] = currentPointIndex + 1; - currentIndex++; - //Second triangle - // if (pointOfSlice % (sliceDetalization+1) == 0 && pointOfSlice != 0) { - if (pointOfSlice == sliceDetailization+1) { - indices[currentIndex] = currentPointIndex - (slicePointsAmount - 1); - currentIndex++; - indices[currentIndex] = currentPointIndex + 1; - currentIndex++; - indices[currentIndex] = currentPointIndex; - } else { - indices[currentIndex] = currentPointIndex + 1; - currentIndex++; - indices[currentIndex] = currentPointIndex + slicePointsAmount + 1; - currentIndex ++; - indices[currentIndex] = currentPointIndex + slicePointsAmount; - } - currentIndex ++; - } - } - - // for (uint64_t i = 0; i < indicesLength; i ++) { - // cout << indices[i] << ","; - // } - // cout << endl; - // cout << indicesLength << endl; - - if (currentIndex != indicesLength) { - cerr << "currentIndex == indicesLength assertion failed" << endl; - cerr << currentIndex << " " << indicesLength << endl; - } - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned long) * indicesLength, indices, GL_STATIC_DRAW); - free(indices); - return indicesLength; -} - // Sample layout of 2 slices with 3 points. // |x |y |z |r |g |b | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 diff --git a/src/coil/segment.hpp b/src/coil/segment.hpp index 2e0e443..f77e4db 100644 --- a/src/coil/segment.hpp +++ b/src/coil/segment.hpp @@ -34,7 +34,6 @@ class CoilSegment { void printSlice(float *slice); void exportSliceToCSV(float *slice); void exportSegmentToCsv(); - uint64_t fillEBO(uint64_t EBO); uint16_t getYear(); uint16_t getDaysAmount(); diff --git a/src/main.cpp b/src/main.cpp index d4a27da..c62256d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,7 +57,7 @@ void processMousePosCallback(GLFWwindow *window, double deltaX, double deltaY) { } int main () { - Coil coil = Coil(2025, 3, 10, 2, 50, 10); + Coil coil = Coil(2024, 3, 10, 1, 50, 10); srand(time(0)); glfwInit(); @@ -115,7 +115,7 @@ int main () { coil.render(); glfwSwapBuffers(window); - glfwPollEvents(); + glfwPollEvents(); } gracefulExit(0);