Compare commits
8 Commits
28e8c15fc1
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 701ff99000 | |||
| dd3ee57fcb | |||
| e7bfc4af89 | |||
| 97fcc6cdda | |||
| a6f9581a70 | |||
| a55efdab95 | |||
| 8ef6fa1124 | |||
| 95cfe0cf43 |
BIN
.cache/clangd/index/coil.cpp.430626AC9C964D13.idx
Normal file
BIN
.cache/clangd/index/coil.cpp.430626AC9C964D13.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/coil.hpp.679854B715F05634.idx
Normal file
BIN
.cache/clangd/index/coil.hpp.679854B715F05634.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/glad.c.9CBF9E314A3856F4.idx
Normal file
BIN
.cache/clangd/index/glad.c.9CBF9E314A3856F4.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/glad.h.9CF03EB8F40E8C67.idx
Normal file
BIN
.cache/clangd/index/glad.h.9CF03EB8F40E8C67.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/khrplatform.h.0F4E692CEB3E73A7.idx
Normal file
BIN
.cache/clangd/index/khrplatform.h.0F4E692CEB3E73A7.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/main.cpp.40336BE2C71C0AAD.idx
Normal file
BIN
.cache/clangd/index/main.cpp.40336BE2C71C0AAD.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/segment.cpp.E58BEE5B986EAFA7.idx
Normal file
BIN
.cache/clangd/index/segment.cpp.E58BEE5B986EAFA7.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/segment.hpp.C426421540A83234.idx
Normal file
BIN
.cache/clangd/index/segment.hpp.C426421540A83234.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/utils.cpp.9EA3B96F5F89167F.idx
Normal file
BIN
.cache/clangd/index/utils.cpp.9EA3B96F5F89167F.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/utils.hpp.66E4232BF41BB544.idx
Normal file
BIN
.cache/clangd/index/utils.hpp.66E4232BF41BB544.idx
Normal file
Binary file not shown.
3
.gitignore
vendored
3
.gitignore
vendored
@@ -33,3 +33,6 @@
|
|||||||
*.app
|
*.app
|
||||||
|
|
||||||
build/
|
build/
|
||||||
|
|
||||||
|
*.csv
|
||||||
|
.cache/
|
||||||
|
|||||||
16
.vscode/launch.json
vendored
Normal file
16
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
// 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": [
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug",
|
||||||
|
"program": "${workspaceFolder}/<executable file>",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,13 +1,32 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
cmake_minimum_required(VERSION 3.20)
|
||||||
project(TimeCoil)
|
project(TimeCoil)
|
||||||
|
|
||||||
SET(PROJECT_SOURCES src/main.cpp src/glad.c)
|
include(FetchContent)
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/include )
|
|
||||||
|
SET(CMAKE_BUILD_TYPE Debug)
|
||||||
|
SET(PROJECT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp src/glad.c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/coil/coil.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/coil/segment.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/utils/utils.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/coil
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/ui
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/utils
|
||||||
|
)
|
||||||
|
|
||||||
add_executable(TimeCoil ${PROJECT_SOURCES})
|
add_executable(TimeCoil ${PROJECT_SOURCES})
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
glm
|
||||||
|
GIT_REPOSITORY https://github.com/g-truc/glm.git
|
||||||
|
GIT_TAG 5847dd91b2dc85cdd8d395ccf68985310e3e0e40
|
||||||
|
)
|
||||||
|
|
||||||
|
FetchContent_MakeAvailable(glm)
|
||||||
|
|
||||||
find_package(glfw3 3.4 REQUIRED)
|
find_package(glfw3 3.4 REQUIRED)
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
|
target_link_libraries(TimeCoil glfw OpenGL::GL glm)
|
||||||
target_link_libraries(TimeCoil glfw)
|
|
||||||
target_link_libraries(TimeCoil OpenGL::GL)
|
|
||||||
|
|||||||
2
build.sh
2
build.sh
@@ -1,2 +1,2 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
cd build && cmake -DCMAKE_C_FLAGS="-g" .. && make && ./TimeCoil
|
mkdir -p build && cd build && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_C_FLAGS="-g -v -da -Q -O0" .. && make && ./TimeCoil # > ../points.csv && python ../tools/build_3d.py ../points.csv
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
layout (location = 0) in vec3 aPos;
|
layout (location = 0) in vec3 aPos;
|
||||||
layout (location = 1) in vec3 col;
|
layout (location = 1) in vec3 col;
|
||||||
|
|
||||||
|
uniform mat4 model;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 projection;
|
||||||
|
|
||||||
out vec3 frag_col;
|
out vec3 frag_col;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
frag_col = col;
|
frag_col = col;
|
||||||
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
|
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||||
}
|
}
|
||||||
66
src/coil/coil.cpp
Normal file
66
src/coil/coil.cpp
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#include <cstdint>
|
||||||
|
#include <glad/glad.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <coil/coil.hpp>
|
||||||
|
#include <coil/segment.hpp>
|
||||||
|
#include <utils/utils.hpp>
|
||||||
|
|
||||||
|
Coil::Coil(uint32_t currentYear, uint32_t amountOfSegments, uint32_t sliceDetalization, float radius, float width)
|
||||||
|
: radius(radius), width(width), currentYear(currentYear) {
|
||||||
|
for (short i = amountOfSegments / -2.; i < amountOfSegments / 2.; i++) {
|
||||||
|
uint32_t year = this->currentYear + i;
|
||||||
|
|
||||||
|
segments.push_back(CoilSegment(this, year, segmentHeight, i, sliceDetalization,false));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<CoilSegment> &Coil::getSegments() {
|
||||||
|
return segments;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Coil::getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Coil::getRadius() {
|
||||||
|
return radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Coil::initGLBuffers() {
|
||||||
|
|
||||||
|
glGenVertexArrays(1, &VAO);
|
||||||
|
glGenBuffers(1, &VBO);
|
||||||
|
glGenBuffers(1, &EBO);
|
||||||
|
|
||||||
|
glBindVertexArray(VAO);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||||
|
|
||||||
|
// glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*) (3 * sizeof(float)));
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
|
||||||
|
glBindVertexArray(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Coil::render() {
|
||||||
|
glBindVertexArray(VAO);
|
||||||
|
std::cout << "Rendering a coil." << std::endl;
|
||||||
|
for (CoilSegment segment : segments) {
|
||||||
|
std::cout << "Rendering " << segment.getYear() << std::endl;
|
||||||
|
segment.fillVBO();
|
||||||
|
uint64_t indicesCount = segment.fillEBO(EBO);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||||
|
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
|
// glDrawArrays(GL_POINTS, 0, segment.getVerticesLength());
|
||||||
|
glDrawElements(GL_TRIANGLES_ADJACENCY, sizeof(unsigned int)*indicesCount, GL_UNSIGNED_INT, 0);
|
||||||
|
}
|
||||||
|
glBindVertexArray(0);
|
||||||
|
}
|
||||||
31
src/coil/coil.hpp
Normal file
31
src/coil/coil.hpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include <vector>
|
||||||
|
#include "segment.hpp"
|
||||||
|
#include <glad/glad.h>
|
||||||
|
|
||||||
|
#ifndef COIL_HPP
|
||||||
|
#define COIL_HPP
|
||||||
|
|
||||||
|
// Coil segment is a one turn of a coil
|
||||||
|
// Coil slice is a set of points that define slice of coil
|
||||||
|
|
||||||
|
class Coil {
|
||||||
|
// distance between coil center and nearest to it coil edge
|
||||||
|
float radius;
|
||||||
|
// distance between coil slices edges
|
||||||
|
float width;
|
||||||
|
float segmentHeight;
|
||||||
|
uint32_t currentYear;
|
||||||
|
std::vector<CoilSegment> segments;
|
||||||
|
|
||||||
|
GLuint VBO, VAO, EBO;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Coil(uint32_t currentYear, uint32_t amountOfSegments, uint32_t sliceDetalization, float radius, float width);
|
||||||
|
std::vector<CoilSegment> &getSegments();
|
||||||
|
float getWidth();
|
||||||
|
float getRadius();
|
||||||
|
void render();
|
||||||
|
void initGLBuffers();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COIL_HPP
|
||||||
289
src/coil/segment.cpp
Normal file
289
src/coil/segment.cpp
Normal file
@@ -0,0 +1,289 @@
|
|||||||
|
#include <glm/common.hpp>
|
||||||
|
#include <glm/ext/matrix_float4x4.hpp>
|
||||||
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
|
#include <glm/trigonometric.hpp>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include <utils/utils.hpp>
|
||||||
|
#include <coil/segment.hpp>
|
||||||
|
#include <coil/coil.hpp>
|
||||||
|
|
||||||
|
// x, y, z, r, g, b
|
||||||
|
#define FIELDS_IN_POINT 6
|
||||||
|
#define DAYS_IN_YEAR (isLeap? 366.0f : 365.0f)
|
||||||
|
|
||||||
|
using glm::vec4;
|
||||||
|
using glm::vec3;
|
||||||
|
using glm::mat4;
|
||||||
|
using glm::radians;
|
||||||
|
using glm::rotate;
|
||||||
|
using glm::sin;
|
||||||
|
using glm::cos;
|
||||||
|
using glm::translate;
|
||||||
|
|
||||||
|
using std::endl;
|
||||||
|
using std::cout;
|
||||||
|
using std::cerr;
|
||||||
|
|
||||||
|
CoilSegment::CoilSegment(
|
||||||
|
Coil* coil,
|
||||||
|
uint16_t year,
|
||||||
|
uint16_t height,
|
||||||
|
int shift,
|
||||||
|
uint32_t sliceDetalization,
|
||||||
|
bool isLeap
|
||||||
|
) :
|
||||||
|
coil(coil), year(year),
|
||||||
|
height(height), shift(shift),
|
||||||
|
sliceDetalization(sliceDetalization), isLeap(isLeap) {
|
||||||
|
init();
|
||||||
|
calculate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoilSegment::init () {
|
||||||
|
verticesLength = DAYS_IN_YEAR * FIELDS_IN_POINT * (sliceDetalization+2);
|
||||||
|
vertices = (float *) calloc(verticesLength, sizeof(float));
|
||||||
|
if (vertices == NULL) {
|
||||||
|
cerr << "Allocation failed" << endl;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
calculate();
|
||||||
|
// cout << "Initialized CoilSegment"
|
||||||
|
// << "(year: " << year
|
||||||
|
// << ", height: " << height
|
||||||
|
// << ", shift: " << shift
|
||||||
|
// << ", isLeap: " << isLeap <<")" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoilSegment::printVertices() {
|
||||||
|
for (uint16_t day = 0; day < DAYS_IN_YEAR; day ++) {
|
||||||
|
cout << "Day " << day << ", " <<
|
||||||
|
"x: " << vertices[FIELDS_IN_POINT * day + 0] << ", " <<
|
||||||
|
"y: " << vertices[FIELDS_IN_POINT * day + 1] << ", " <<
|
||||||
|
"z: " << vertices[FIELDS_IN_POINT * day + 2] << ", " <<
|
||||||
|
"r: " << vertices[FIELDS_IN_POINT * day + 3] << ", " <<
|
||||||
|
"g: " << vertices[FIELDS_IN_POINT * day + 4] << ", " <<
|
||||||
|
"b: " << vertices[FIELDS_IN_POINT * day + 5] << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float *CoilSegment::calculateSlice() {
|
||||||
|
uint32_t size = (/*start and end of a slize*/2 + sliceDetalization) * FIELDS_IN_POINT * sizeof(float);
|
||||||
|
float *slice = (float *)malloc(size);
|
||||||
|
mat4 transform = mat4(1.);
|
||||||
|
transform = glm::scale(
|
||||||
|
transform,
|
||||||
|
vec3(
|
||||||
|
coil->getWidth(),
|
||||||
|
10,
|
||||||
|
1
|
||||||
|
)
|
||||||
|
);
|
||||||
|
vec3 point = vec3(cos(0), sin(0), 0);
|
||||||
|
// Start of a slice
|
||||||
|
slice[0] = cos(0);
|
||||||
|
slice[1] = sin(0);
|
||||||
|
slice[2] = 0;
|
||||||
|
slice[3] = 1;
|
||||||
|
slice[4] = 1;
|
||||||
|
slice[5] = 1;
|
||||||
|
|
||||||
|
float degreeByPoint = -180. / (sliceDetalization + 1);
|
||||||
|
|
||||||
|
for (uint32_t i = 1; i <= sliceDetalization; i ++) {
|
||||||
|
uint32_t offset = FIELDS_IN_POINT * i;
|
||||||
|
|
||||||
|
slice[offset + 0] = round_to_presicion(cos(radians(degreeByPoint * i)), 5);
|
||||||
|
slice[offset + 1] = round_to_presicion(sin(radians(degreeByPoint * i)), 5);
|
||||||
|
slice[offset + 2] = 0;
|
||||||
|
slice[offset + 3] = 1;
|
||||||
|
slice[offset + 4] = 1;
|
||||||
|
slice[offset + 5] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// End of a slice
|
||||||
|
uint32_t endIndex = (size / sizeof(float) - FIELDS_IN_POINT);
|
||||||
|
slice[endIndex + 0] = round_to_presicion(cos(radians(180.)), 5);
|
||||||
|
slice[endIndex + 1] = round_to_presicion(sin(radians(180.)), 5);
|
||||||
|
slice[endIndex + 2] = 0;
|
||||||
|
slice[endIndex + 3] = 1;
|
||||||
|
slice[endIndex + 4] = 1;
|
||||||
|
slice[endIndex + 5] = 1;
|
||||||
|
|
||||||
|
return slice;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoilSegment::constructSegment(float *slice) {
|
||||||
|
float degreesPerDay = 360.f / DAYS_IN_YEAR;
|
||||||
|
|
||||||
|
for (uint32_t day = 0; day < DAYS_IN_YEAR; day ++) {
|
||||||
|
float daysDegree = day * degreesPerDay;
|
||||||
|
vec3 daysPosition = vec3(
|
||||||
|
cos(radians(daysDegree)) * coil->getRadius(),
|
||||||
|
10* daysDegree/360.,
|
||||||
|
sin(radians(daysDegree)) * coil->getRadius()
|
||||||
|
);
|
||||||
|
|
||||||
|
mat4 transform = mat4(1.);
|
||||||
|
|
||||||
|
transform = translate(
|
||||||
|
transform,
|
||||||
|
daysPosition
|
||||||
|
);
|
||||||
|
|
||||||
|
transform = rotate(
|
||||||
|
transform,
|
||||||
|
-radians(daysDegree),
|
||||||
|
vec3(
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
|
0.0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
for (uint32_t slicePoint = 0; slicePoint < (2 + sliceDetalization); slicePoint ++) {
|
||||||
|
uint32_t slicePointOffset = FIELDS_IN_POINT * slicePoint;
|
||||||
|
vec4 point(
|
||||||
|
slice[slicePointOffset + 0],
|
||||||
|
slice[slicePointOffset + 1],
|
||||||
|
slice[slicePointOffset + 2],
|
||||||
|
1
|
||||||
|
);
|
||||||
|
|
||||||
|
point = transform * point;
|
||||||
|
uint64_t currentPointOffset = day * (2+sliceDetalization) * FIELDS_IN_POINT + slicePointOffset;
|
||||||
|
vertices[currentPointOffset + 0] = point.x;
|
||||||
|
vertices[currentPointOffset + 1] = point.y;
|
||||||
|
vertices[currentPointOffset + 2] = point.z;
|
||||||
|
|
||||||
|
vertices[currentPointOffset + 3] = 0.5;
|
||||||
|
vertices[currentPointOffset + 4] = 0.5;
|
||||||
|
vertices[currentPointOffset + 5] = 0.5;
|
||||||
|
|
||||||
|
// memcpy(
|
||||||
|
// vertices + currentPointOffset + 3,
|
||||||
|
// slice + slicePointOffset + 3,
|
||||||
|
// 3
|
||||||
|
// );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void CoilSegment::fillVBO() {
|
||||||
|
// printVertices();
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * verticesLength, vertices, GL_STATIC_DRAW);
|
||||||
|
}
|
||||||
|
uint64_t CoilSegment::fillEBO(uint64_t EBO) {
|
||||||
|
uint64_t indicesLength = 6 * (sliceDetalization+2) * DAYS_IN_YEAR;
|
||||||
|
uint64_t currentIndex = 0;
|
||||||
|
uint64_t* indices = (uint64_t*) calloc(indicesLength, sizeof(uint64_t));
|
||||||
|
for (uint64_t day = 0; day < DAYS_IN_YEAR; day ++) {
|
||||||
|
for (uint64_t pointOfSlice = 0; pointOfSlice < (sliceDetalization+2); pointOfSlice ++) {
|
||||||
|
// cout << currentIndex << endl;
|
||||||
|
uint64_t dayOffset = day * (sliceDetalization+2);
|
||||||
|
uint64_t offset = dayOffset + pointOfSlice;
|
||||||
|
//First triangle
|
||||||
|
indices[currentIndex] = offset;
|
||||||
|
currentIndex ++;
|
||||||
|
indices[currentIndex] = offset + (sliceDetalization+2);
|
||||||
|
currentIndex ++;
|
||||||
|
indices[currentIndex] = offset + 1;
|
||||||
|
currentIndex++;
|
||||||
|
//Second triangle
|
||||||
|
|
||||||
|
if (pointOfSlice % (sliceDetalization+1) == 0 && pointOfSlice != 0) {
|
||||||
|
indices[currentIndex] = offset - (sliceDetalization+2);
|
||||||
|
currentIndex++;
|
||||||
|
indices[currentIndex] = offset + 1;
|
||||||
|
currentIndex++;
|
||||||
|
indices[currentIndex] = offset;
|
||||||
|
} else {
|
||||||
|
indices[currentIndex] = offset + 1;
|
||||||
|
currentIndex++;
|
||||||
|
indices[currentIndex] = offset + (sliceDetalization+3);
|
||||||
|
currentIndex ++;
|
||||||
|
indices[currentIndex] = offset + (sliceDetalization+2);
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// void testEBO(uint64_t *EBO, uint64_t length) {
|
||||||
|
// for (uint64_t i = 0; i < length; i ++) {
|
||||||
|
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// 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
|
||||||
|
// | point | point | point | point | point | point |
|
||||||
|
// | slice | slice |
|
||||||
|
//
|
||||||
|
void CoilSegment::calculate() {
|
||||||
|
float *slice = calculateSlice();
|
||||||
|
|
||||||
|
constructSegment(slice);
|
||||||
|
exportSegmentToCsv();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
float *CoilSegment::getVertices() { return vertices; }
|
||||||
|
|
||||||
|
uint64_t CoilSegment::getVerticesLength() { return verticesLength; }
|
||||||
|
|
||||||
|
uint16_t CoilSegment::getYear() { return year; }
|
||||||
|
|
||||||
|
void CoilSegment::render() {
|
||||||
|
|
||||||
|
}
|
||||||
|
void CoilSegment::exportSliceToCSV(float *slice) {
|
||||||
|
cout << "Exporting slice to csv" << endl;
|
||||||
|
std::ofstream outFile("./slice_export.csv");
|
||||||
|
|
||||||
|
outFile << "x,y,z" << endl;
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < sliceDetalization+2; i ++) {
|
||||||
|
uint32_t offset = FIELDS_IN_POINT * i;
|
||||||
|
outFile
|
||||||
|
<< slice[offset + 0] << ","
|
||||||
|
<< slice[offset + 1] << ",0" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoilSegment::exportSegmentToCsv() {
|
||||||
|
cout << "Exporting segment to csv" << endl;
|
||||||
|
std::ofstream outFile("./segment_export.csv");
|
||||||
|
|
||||||
|
outFile << "x,y,z" << endl;
|
||||||
|
|
||||||
|
for (uint16_t day = 0; day < DAYS_IN_YEAR; day ++) {
|
||||||
|
uint64_t dayOffset = day * (2+sliceDetalization) * FIELDS_IN_POINT;
|
||||||
|
|
||||||
|
for (uint32_t point_in_slice = 0; point_in_slice < (2+sliceDetalization); point_in_slice ++) {
|
||||||
|
uint32_t sliceOffset = point_in_slice * FIELDS_IN_POINT;
|
||||||
|
outFile << vertices[dayOffset + sliceOffset + 0] << ","
|
||||||
|
<< vertices[dayOffset + sliceOffset + 1] << ","
|
||||||
|
<< vertices[dayOffset + sliceOffset + 2] << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/coil/segment.hpp
Normal file
38
src/coil/segment.hpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#ifndef COIL_SEGMENT_HPP
|
||||||
|
#define COIL_SEGMENT_HPP
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
class Coil;
|
||||||
|
|
||||||
|
class CoilSegment {
|
||||||
|
Coil *coil;
|
||||||
|
uint16_t year;
|
||||||
|
uint16_t height;
|
||||||
|
// Number of a segments, counting from the central (which is 0)
|
||||||
|
int shift;
|
||||||
|
uint32_t sliceDetalization;
|
||||||
|
bool isLeap;
|
||||||
|
float *vertices;
|
||||||
|
uint64_t verticesLength;
|
||||||
|
|
||||||
|
void init();
|
||||||
|
float* calculateSlice();
|
||||||
|
void constructSegment(float *slice);
|
||||||
|
|
||||||
|
public:
|
||||||
|
CoilSegment(Coil* coil, uint16_t year, uint16_t height, int shift, uint32_t sliceDetalization, bool isLeap);
|
||||||
|
void calculate();
|
||||||
|
void printVertices();
|
||||||
|
float *getVertices();
|
||||||
|
uint64_t getVerticesLength();
|
||||||
|
void printSlice(float *slice);
|
||||||
|
void exportSliceToCSV(float *slice);
|
||||||
|
void exportSegmentToCsv();
|
||||||
|
void render();
|
||||||
|
void fillVBO();
|
||||||
|
uint64_t fillEBO(uint64_t EBO);
|
||||||
|
uint16_t getYear();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COIL_SEGMENT_HPP
|
||||||
319
src/main.cpp
319
src/main.cpp
@@ -1,12 +1,25 @@
|
|||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <ctime>
|
||||||
|
#include <iostream>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
|
#include <coil/coil.hpp>
|
||||||
|
#include <coil/segment.hpp>
|
||||||
|
#include <utils/utils.hpp>
|
||||||
|
|
||||||
|
using std::cerr;
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
|
||||||
#define RAND_0_1 ((float)rand()) / RAND_MAX
|
#define RAND_0_1 ((float)rand()) / RAND_MAX
|
||||||
|
#define DISPLAY_WIDTH 800
|
||||||
|
#define DISPLAY_HEIGHT 600
|
||||||
|
|
||||||
void framebufferSizeCallback(GLFWwindow *window, int width, int height) {
|
void framebufferSizeCallback(GLFWwindow *window, int width, int height) {
|
||||||
glViewport(10, 10, width-10, height-10);
|
glViewport(10, 10, width-10, height-10);
|
||||||
@@ -18,95 +31,11 @@ void processInput(GLFWwindow *window) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderGraphics(GLFWwindow *window) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void gracefulExit(int code) {
|
|
||||||
glfwTerminate();
|
|
||||||
exit(code);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string readFile(std::string path) {
|
|
||||||
std::ifstream file(path);
|
|
||||||
if (!file.is_open())
|
|
||||||
std::cerr << "File " << path << " was not found." << std::endl;
|
|
||||||
|
|
||||||
std::string content = "";
|
|
||||||
std::string buffer = "";
|
|
||||||
|
|
||||||
while(getline(file, buffer)) {
|
|
||||||
content += buffer + "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
content += '\0';
|
|
||||||
file.close();
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateVertices(float (&vertices)[24]) {
|
|
||||||
// if (RAND_0_1 < 0.99f) return;
|
|
||||||
float a[] = {
|
|
||||||
-1.0f, 1.0f, 0.0f, RAND_0_1, RAND_0_1, RAND_0_1, // upper left
|
|
||||||
-1.0f, -1.0f, 0.0f, RAND_0_1, RAND_0_1, RAND_0_1, // bottom left
|
|
||||||
1.0f, 1.0f, 0.0f, RAND_0_1, RAND_0_1, RAND_0_1, // upper right
|
|
||||||
1.0f, -1.0f, 0.0f, RAND_0_1, RAND_0_1, RAND_0_1 // bottom right
|
|
||||||
};
|
|
||||||
|
|
||||||
// vertices = a;
|
|
||||||
memcpy(vertices, a, sizeof(a));
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int prepareShaders() {
|
|
||||||
unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
|
||||||
unsigned int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
|
||||||
|
|
||||||
std::string vertexShaderSourceString = readFile("../shaders/shader.vert");
|
|
||||||
std::string fragmentShaderSourceString = readFile("../shaders/shader.frag");
|
|
||||||
|
|
||||||
const char *vertexShaderSource = vertexShaderSourceString.c_str();
|
|
||||||
const char *fragmentShaderSource = fragmentShaderSourceString.c_str();
|
|
||||||
|
|
||||||
glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
|
|
||||||
glCompileShader(vertexShader);
|
|
||||||
|
|
||||||
int success;
|
|
||||||
char log[512];
|
|
||||||
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
|
|
||||||
if (!success) {
|
|
||||||
glGetShaderInfoLog(vertexShader, 512, NULL, log);
|
|
||||||
std::cerr << "Could not compile vertex shader: " << log << std::endl;
|
|
||||||
gracefulExit(-1);
|
|
||||||
}
|
|
||||||
glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
|
|
||||||
glCompileShader(fragmentShader);
|
|
||||||
|
|
||||||
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
|
|
||||||
if (!success) {
|
|
||||||
glGetShaderInfoLog(fragmentShader, 512, NULL, log);
|
|
||||||
std::cerr << "Could not compile fragment shader: " << log << std::endl;
|
|
||||||
gracefulExit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int shaderProgram;
|
|
||||||
shaderProgram = glCreateProgram();
|
|
||||||
glAttachShader(shaderProgram, vertexShader);
|
|
||||||
glAttachShader(shaderProgram, fragmentShader);
|
|
||||||
glLinkProgram(shaderProgram);
|
|
||||||
|
|
||||||
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
|
|
||||||
if(!success) {
|
|
||||||
glGetProgramInfoLog(shaderProgram, 512, NULL, log);
|
|
||||||
std::cerr << "Could not link program: " << log << std::endl;
|
|
||||||
gracefulExit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
glDeleteShader(vertexShader);
|
|
||||||
glDeleteShader(fragmentShader);
|
|
||||||
return shaderProgram;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main () {
|
int main () {
|
||||||
|
|
||||||
|
Coil c = Coil(2025, 1, 5, 50, 10);
|
||||||
|
|
||||||
srand(time(0));
|
srand(time(0));
|
||||||
glfwInit();
|
glfwInit();
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
@@ -116,80 +45,182 @@ int main () {
|
|||||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GLFWwindow *window = glfwCreateWindow(800, 600, "TimeCoil", NULL, NULL);
|
GLFWwindow *window = glfwCreateWindow(DISPLAY_WIDTH, DISPLAY_HEIGHT, "TimeCoil", NULL, NULL);
|
||||||
if (window == NULL) {
|
if (window == NULL) {
|
||||||
std::cerr << "Failed to create GLFW window." << std::endl;
|
cerr << "Failed to create GLFW window." << endl;
|
||||||
gracefulExit(-1);
|
gracefulExit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebufferSizeCallback);
|
glfwSetFramebufferSizeCallback(window, framebufferSizeCallback);
|
||||||
|
|
||||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||||
std::cerr << "Failed to initialize GLAD." << std::endl;
|
cerr << "Failed to initialize GLAD." << endl;
|
||||||
return -1;
|
gracefulExit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int shaderProgram = prepareShaders();
|
|
||||||
|
|
||||||
float vertices[] = {
|
|
||||||
-1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, // upper left
|
|
||||||
-1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom left
|
|
||||||
1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, // upper right
|
|
||||||
1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f // bottom right
|
|
||||||
};
|
|
||||||
unsigned int indices[] = {
|
|
||||||
1, 2, 3,
|
|
||||||
1, 2, 0
|
|
||||||
};
|
|
||||||
unsigned int VBO, VAO, EBO;
|
|
||||||
glGenVertexArrays(1, &VAO);
|
|
||||||
glGenBuffers(1, &VBO);
|
|
||||||
glGenBuffers(1, &EBO);
|
|
||||||
|
|
||||||
glBindVertexArray(VAO);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
|
||||||
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
|
|
||||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*) (3 * sizeof(float)));
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
|
uint64_t shaderProgram = prepareShaders();
|
||||||
|
glUseProgram(shaderProgram);
|
||||||
|
|
||||||
|
glm::mat4 projection = glm::mat4(1.0f);
|
||||||
|
projection = glm::perspective(glm::radians(50.0f), (float)DISPLAY_WIDTH / (float)DISPLAY_HEIGHT, 0.001f, 2000.0f);
|
||||||
|
|
||||||
|
unsigned int projectionLoc = glGetUniformLocation(shaderProgram, "projection");
|
||||||
|
glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(projection));
|
||||||
|
|
||||||
|
|
||||||
|
c.initGLBuffers();
|
||||||
|
|
||||||
|
// float vertices[] = {
|
||||||
|
// // positions // texture coords
|
||||||
|
// 05.5f, 0.5f, 0.0f, 1.0f, 1.0f, // top right
|
||||||
|
// 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, // bottom right
|
||||||
|
// -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, // bottom left
|
||||||
|
// -0.5f, 0.5f, 0.0f, 0.0f, 1.0f // top left
|
||||||
|
// };
|
||||||
|
// unsigned int indices[] = {
|
||||||
|
// 0, 1, 3, // first triangle
|
||||||
|
// 1, 2, 3 // second triangle
|
||||||
|
// };
|
||||||
|
// unsigned int VBO, VAO, EBO;
|
||||||
|
// glGenVertexArrays(1, &VAO);
|
||||||
|
// glGenBuffers(1, &VBO);
|
||||||
|
// glGenBuffers(1, &EBO);
|
||||||
|
|
||||||
|
// glBindVertexArray(VAO);
|
||||||
|
|
||||||
|
// glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
// glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||||
|
// glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
// // position attribute
|
||||||
|
// glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
|
||||||
|
// glEnableVertexAttribArray(0);
|
||||||
|
// // texture coord attribute
|
||||||
|
// glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||||
|
// glEnableVertexAttribArray(1);
|
||||||
|
|
||||||
while(!glfwWindowShouldClose(window)) {
|
while(!glfwWindowShouldClose(window)) {
|
||||||
processInput(window);
|
processInput(window);
|
||||||
|
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
glUseProgram(shaderProgram);
|
|
||||||
|
|
||||||
// float time = glfwGetTime();
|
glm::mat4 model = glm::mat4(1.0f);
|
||||||
// float greenValue = sin(time);
|
glm::mat4 view = glm::mat4(1.0f);
|
||||||
|
model = glm::rotate(model, glm::radians(5.0f), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||||
|
view = glm::translate(view, glm::vec3(0.0f, 0.0f, -89.0f));
|
||||||
|
|
||||||
|
unsigned int modelLoc = glGetUniformLocation(shaderProgram, "model");
|
||||||
|
unsigned int viewLoc = glGetUniformLocation(shaderProgram, "view");
|
||||||
|
|
||||||
|
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
|
||||||
|
glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
|
||||||
|
|
||||||
// int vertexColorLocation = glGetUniformLocation(shaderProgram, "MyColor");
|
c.render();
|
||||||
// glUniform4f(vertexColorLocation, 0, greenValue, 0, 1);
|
// glBindVertexArray(VAO);
|
||||||
glBindVertexArray(VAO);
|
// glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
updateVertices(vertices);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_DYNAMIC_DRAW);
|
|
||||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
glDeleteVertexArrays(1, &VAO);
|
// CoilSegment cs = CoilSegment(10, 0, false);
|
||||||
glDeleteBuffers(1, &VBO);
|
// for (auto segment : c.getSegments()) {
|
||||||
glDeleteProgram(shaderProgram);
|
// // segment.printVertices();
|
||||||
|
// }
|
||||||
|
// cs.printVertices();
|
||||||
gracefulExit(0);
|
gracefulExit(0);
|
||||||
|
// srand(time(0));
|
||||||
|
// glfwInit();
|
||||||
|
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
|
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
|
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
|
// #ifdef __APPLE__
|
||||||
|
// glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// GLFWwindow *window = glfwCreateWindow(800, 600, "TimeCoil", NULL, NULL);
|
||||||
|
// if (window == NULL) {
|
||||||
|
// std::cerr << "Failed to create GLFW window." << std::endl;
|
||||||
|
// gracefulExit(-1);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// glfwMakeContextCurrent(window);
|
||||||
|
// glfwSetFramebufferSizeCallback(window, framebufferSizeCallback);
|
||||||
|
|
||||||
|
// if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||||
|
// std::cerr << "Failed to initialize GLAD." << std::endl;
|
||||||
|
// return -1;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// unsigned int shaderProgram = prepareShaders();
|
||||||
|
|
||||||
|
// float *vertices = cs.getVertices();
|
||||||
|
// unsigned int amountOfVerticies = cs.getVerticesLength();
|
||||||
|
// std::cout << amountOfVerticies << std::endl;
|
||||||
|
// // float vertices[] = {
|
||||||
|
// // -1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, // upper left
|
||||||
|
// // -0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom left
|
||||||
|
// // 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // upper right
|
||||||
|
// // 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f // bottom right
|
||||||
|
// // };
|
||||||
|
// // unsigned int indices[] = {
|
||||||
|
// // 1, 2, 3,
|
||||||
|
// // 1, 2, 0
|
||||||
|
// // };
|
||||||
|
// unsigned int VBO, VAO, EBO;
|
||||||
|
// glGenVertexArrays(1, &VAO);
|
||||||
|
// glGenBuffers(1, &VBO);
|
||||||
|
// // glGenBuffers(1, &EBO);
|
||||||
|
|
||||||
|
// glBindVertexArray(VAO);
|
||||||
|
|
||||||
|
// glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
// // glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||||
|
|
||||||
|
// glBufferData(GL_ARRAY_BUFFER, amountOfVerticies, vertices, GL_STATIC_DRAW);
|
||||||
|
// // glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
// glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
|
||||||
|
// glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
// glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*) (3 * sizeof(float)));
|
||||||
|
// glEnableVertexAttribArray(1);
|
||||||
|
|
||||||
|
// glBindVertexArray(0);
|
||||||
|
|
||||||
|
// while(!glfwWindowShouldClose(window)) {
|
||||||
|
// processInput(window);
|
||||||
|
|
||||||
|
// glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||||
|
// glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
// glUseProgram(shaderProgram);
|
||||||
|
|
||||||
|
// // float time = glfwGetTime();
|
||||||
|
// // float greenValue = sin(time);
|
||||||
|
|
||||||
|
|
||||||
|
// // int vertexColorLocation = glGetUniformLocation(shaderProgram, "MyColor");
|
||||||
|
// // glUniform4f(vertexColorLocation, 0, greenValue, 0, 1);
|
||||||
|
// glBindVertexArray(VAO);
|
||||||
|
|
||||||
|
// // updateVertices(vertices);
|
||||||
|
// glBufferData(GL_ARRAY_BUFFER, amountOfVerticies, vertices, GL_DYNAMIC_DRAW);
|
||||||
|
// // glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||||
|
// glDrawArrays(GL_LINE_STRIP_ADJACENCY, -30, amountOfVerticies);
|
||||||
|
|
||||||
|
|
||||||
|
// glBindVertexArray(0);
|
||||||
|
// glfwSwapBuffers(window);
|
||||||
|
// glfwPollEvents();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// glDeleteVertexArrays(1, &VAO);
|
||||||
|
// glDeleteBuffers(1, &VBO);
|
||||||
|
// glDeleteProgram(shaderProgram);
|
||||||
|
// gracefulExit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
82
src/utils/utils.cpp
Normal file
82
src/utils/utils.cpp
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#include <glad/glad.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <cmath>
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
float round_to_presicion( float value, int precision ) {
|
||||||
|
const int adjustment = pow(10,precision);
|
||||||
|
return floor( value*(adjustment) + 0.5 )/adjustment;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string readFile(std::string path) {
|
||||||
|
std::ifstream file(path);
|
||||||
|
if (!file.is_open())
|
||||||
|
std::cerr << "File " << path << " was not found." << std::endl;
|
||||||
|
|
||||||
|
std::string content = "";
|
||||||
|
std::string buffer = "";
|
||||||
|
|
||||||
|
while(getline(file, buffer)) {
|
||||||
|
content += buffer + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
content += '\0';
|
||||||
|
file.close();
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gracefulExit(int code) {
|
||||||
|
glfwTerminate();
|
||||||
|
exit(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t prepareShaders() {
|
||||||
|
unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
unsigned int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
|
std::string vertexShaderSourceString = readFile("../shaders/shader.vert");
|
||||||
|
std::string fragmentShaderSourceString = readFile("../shaders/shader.frag");
|
||||||
|
|
||||||
|
const char *vertexShaderSource = vertexShaderSourceString.c_str();
|
||||||
|
const char *fragmentShaderSource = fragmentShaderSourceString.c_str();
|
||||||
|
|
||||||
|
glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
|
||||||
|
glCompileShader(vertexShader);
|
||||||
|
|
||||||
|
int success;
|
||||||
|
char log[512];
|
||||||
|
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
|
||||||
|
if (!success) {
|
||||||
|
glGetShaderInfoLog(vertexShader, 512, NULL, log);
|
||||||
|
std::cerr << "Could not compile vertex shader: " << log << std::endl;
|
||||||
|
gracefulExit(-1);
|
||||||
|
}
|
||||||
|
glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
|
||||||
|
glCompileShader(fragmentShader);
|
||||||
|
|
||||||
|
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
|
||||||
|
if (!success) {
|
||||||
|
glGetShaderInfoLog(fragmentShader, 512, NULL, log);
|
||||||
|
std::cerr << "Could not compile fragment shader: " << log << std::endl;
|
||||||
|
gracefulExit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int shaderProgram;
|
||||||
|
shaderProgram = glCreateProgram();
|
||||||
|
glAttachShader(shaderProgram, vertexShader);
|
||||||
|
glAttachShader(shaderProgram, fragmentShader);
|
||||||
|
glLinkProgram(shaderProgram);
|
||||||
|
|
||||||
|
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
|
||||||
|
if(!success) {
|
||||||
|
glGetProgramInfoLog(shaderProgram, 512, NULL, log);
|
||||||
|
std::cerr << "Could not link program: " << log << std::endl;
|
||||||
|
gracefulExit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glDeleteShader(vertexShader);
|
||||||
|
glDeleteShader(fragmentShader);
|
||||||
|
return shaderProgram;
|
||||||
|
}
|
||||||
12
src/utils/utils.hpp
Normal file
12
src/utils/utils.hpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include <glad/glad.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <cmath>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
float round_to_presicion( float value, int precision );
|
||||||
|
|
||||||
|
std::string readFile(std::string path);
|
||||||
|
|
||||||
|
void gracefulExit(int code);
|
||||||
|
|
||||||
|
uint64_t prepareShaders();
|
||||||
40
tools/build_3d.py
Executable file
40
tools/build_3d.py
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#!/usr/bin/env python0;
|
||||||
|
|
||||||
|
import plotly.graph_objects as go
|
||||||
|
import pandas as pd
|
||||||
|
import numpy as np
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print(f"Usage: ./{sys.argv[0]} <filename>")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
df = pd.read_csv(sys.argv[1])
|
||||||
|
|
||||||
|
fig = go.Figure(data=[go.Scatter3d(x=df['x'], y=df['y'], z=df['z'], mode='markers')])
|
||||||
|
|
||||||
|
fig.update_layout(
|
||||||
|
scene = dict(
|
||||||
|
xaxis_title='X',
|
||||||
|
yaxis_title='Y',
|
||||||
|
zaxis_title='Z',
|
||||||
|
xaxis=dict(nticks=10, range=[-220, 220]),
|
||||||
|
yaxis=dict(nticks=10, range=[-220, 220]),
|
||||||
|
zaxis=dict(nticks=10, range=[-220, 220])
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
fig.update_layout(
|
||||||
|
scene = dict(
|
||||||
|
camera = dict(
|
||||||
|
eye=dict(x=1.5, y=1.5, z=1.5)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
fig.data[0].y, fig.data[0].z = fig.data[0].z, fig.data[0].y
|
||||||
|
|
||||||
|
|
||||||
|
fig.show()
|
||||||
Reference in New Issue
Block a user