Compare commits
No commits in common. "dd3ee57fcb5438824849255c14c34bb8234efa41" and "97fcc6cddacef7d70aceb4dee6a29a2e502bed57" have entirely different histories.
dd3ee57fcb
...
97fcc6cdda
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -35,4 +35,3 @@
|
||||||
build/
|
build/
|
||||||
|
|
||||||
*.csv
|
*.csv
|
||||||
.cache/
|
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
// 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}"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -3,7 +3,6 @@ project(TimeCoil)
|
||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
SET(CMAKE_BUILD_TYPE Debug)
|
|
||||||
SET(PROJECT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp src/glad.c
|
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/coil.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/coil/segment.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/coil/segment.cpp
|
||||||
|
|
2
build.sh
2
build.sh
|
@ -1,2 +1,2 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
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
|
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,15 +1,10 @@
|
||||||
#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 = projection * view * model * vec4(aPos, 1.0);
|
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
|
||||||
}
|
}
|
|
@ -1,18 +1,15 @@
|
||||||
#include <cstdint>
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <coil/coil.hpp>
|
#include <coil/coil.hpp>
|
||||||
#include <coil/segment.hpp>
|
#include <coil/segment.hpp>
|
||||||
#include <utils/utils.hpp>
|
#include <utils/utils.hpp>
|
||||||
|
|
||||||
Coil::Coil(uint32_t currentYear, uint32_t amountOfSegments, uint32_t sliceDetalization, float radius, float width)
|
Coil::Coil(uint32_t currentYear, uint32_t amountOfSegments)
|
||||||
: radius(radius), width(width), currentYear(currentYear) {
|
: currentYear(currentYear) {
|
||||||
for (short i = amountOfSegments / -2.; i < amountOfSegments / 2.; i++) {
|
for (short i = amountOfSegments / -2.; i < amountOfSegments / 2.; i++) {
|
||||||
uint32_t year = this->currentYear + i;
|
uint32_t year = this->currentYear + i;
|
||||||
|
segments.push_back(CoilSegment(this, year, segmentHeight, i, 3,false));
|
||||||
segments.push_back(CoilSegment(this, year, segmentHeight, i, sliceDetalization,false));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,47 +17,20 @@ std::vector<CoilSegment> &Coil::getSegments() {
|
||||||
return segments;
|
return segments;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Coil::getWidth() {
|
double Coil::getWidth() {
|
||||||
return width;
|
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() {
|
void Coil::render() {
|
||||||
glBindVertexArray(VAO);
|
prepareShaders();
|
||||||
std::cout << "Rendering a coil." << std::endl;
|
uint64_t VBO;
|
||||||
|
glGenBuffers(1, (unsigned int*) &(VBO));
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
for (CoilSegment segment : segments) {
|
for (CoilSegment segment : segments) {
|
||||||
std::cout << "Rendering " << segment.getYear() << std::endl;
|
double* vertices = segment.getVertices();
|
||||||
segment.fillVBO();
|
uint64_t verticesLength = segment.getVerticesLength();
|
||||||
uint64_t indicesCount = segment.fillEBO(EBO);
|
glBufferData(GL_ARRAY_BUFFER, verticesLength, vertices, GL_STATIC_DRAW);
|
||||||
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);
|
|
||||||
}
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "segment.hpp"
|
#include "segment.hpp"
|
||||||
#include <glad/glad.h>
|
|
||||||
|
|
||||||
#ifndef COIL_HPP
|
#ifndef COIL_HPP
|
||||||
#define COIL_HPP
|
#define COIL_HPP
|
||||||
|
@ -10,22 +9,18 @@
|
||||||
|
|
||||||
class Coil {
|
class Coil {
|
||||||
// distance between coil center and nearest to it coil edge
|
// distance between coil center and nearest to it coil edge
|
||||||
float radius;
|
double radius;
|
||||||
// distance between coil slices edges
|
// distance between coil slices edges
|
||||||
float width;
|
double width;
|
||||||
float segmentHeight;
|
double segmentHeight;
|
||||||
uint32_t currentYear;
|
uint32_t currentYear;
|
||||||
std::vector<CoilSegment> segments;
|
std::vector<CoilSegment> segments;
|
||||||
|
|
||||||
GLuint VBO, VAO, EBO;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Coil(uint32_t currentYear, uint32_t amountOfSegments, uint32_t sliceDetalization, float radius, float width);
|
Coil(uint32_t currentYear, uint32_t amountOfSegments);
|
||||||
std::vector<CoilSegment> &getSegments();
|
std::vector<CoilSegment> &getSegments();
|
||||||
float getWidth();
|
double getWidth();
|
||||||
float getRadius();
|
|
||||||
void render();
|
void render();
|
||||||
void initGLBuffers();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COIL_HPP
|
#endif // COIL_HPP
|
|
@ -1,10 +1,8 @@
|
||||||
#include <glm/common.hpp>
|
|
||||||
#include <glm/ext/matrix_float4x4.hpp>
|
#include <glm/ext/matrix_float4x4.hpp>
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
#include <glm/trigonometric.hpp>
|
#include <glm/trigonometric.hpp>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
@ -46,12 +44,11 @@ CoilSegment::CoilSegment(
|
||||||
|
|
||||||
void CoilSegment::init () {
|
void CoilSegment::init () {
|
||||||
verticesLength = DAYS_IN_YEAR * FIELDS_IN_POINT * (sliceDetalization+2);
|
verticesLength = DAYS_IN_YEAR * FIELDS_IN_POINT * (sliceDetalization+2);
|
||||||
vertices = (float *) calloc(verticesLength, sizeof(float));
|
vertices = (double *) calloc(verticesLength, sizeof(double));
|
||||||
if (vertices == NULL) {
|
if (vertices == NULL) {
|
||||||
cerr << "Allocation failed" << endl;
|
cerr << "Allocation failed" << endl;
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
calculate();
|
|
||||||
// cout << "Initialized CoilSegment"
|
// cout << "Initialized CoilSegment"
|
||||||
// << "(year: " << year
|
// << "(year: " << year
|
||||||
// << ", height: " << height
|
// << ", height: " << height
|
||||||
|
@ -72,19 +69,9 @@ void CoilSegment::printVertices() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float *CoilSegment::calculateSlice() {
|
double *CoilSegment::calculateSlice() {
|
||||||
uint32_t size = (/*start and end of a slize*/2 + sliceDetalization) * FIELDS_IN_POINT * sizeof(float);
|
uint32_t size = (/*start and end of a slize*/2 + sliceDetalization) * FIELDS_IN_POINT * sizeof(double);
|
||||||
float *slice = (float *)malloc(size);
|
double *slice = (double *)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
|
// Start of a slice
|
||||||
slice[0] = cos(0);
|
slice[0] = cos(0);
|
||||||
slice[1] = sin(0);
|
slice[1] = sin(0);
|
||||||
|
@ -93,7 +80,7 @@ float *CoilSegment::calculateSlice() {
|
||||||
slice[4] = 1;
|
slice[4] = 1;
|
||||||
slice[5] = 1;
|
slice[5] = 1;
|
||||||
|
|
||||||
float degreeByPoint = -180. / (sliceDetalization + 1);
|
double degreeByPoint = -180. / (sliceDetalization + 1);
|
||||||
|
|
||||||
for (uint32_t i = 1; i <= sliceDetalization; i ++) {
|
for (uint32_t i = 1; i <= sliceDetalization; i ++) {
|
||||||
uint32_t offset = FIELDS_IN_POINT * i;
|
uint32_t offset = FIELDS_IN_POINT * i;
|
||||||
|
@ -107,7 +94,7 @@ float *CoilSegment::calculateSlice() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// End of a slice
|
// End of a slice
|
||||||
uint32_t endIndex = (size / sizeof(float) - FIELDS_IN_POINT);
|
uint32_t endIndex = (size / sizeof(double) - FIELDS_IN_POINT);
|
||||||
slice[endIndex + 0] = round_to_presicion(cos(radians(180.)), 5);
|
slice[endIndex + 0] = round_to_presicion(cos(radians(180.)), 5);
|
||||||
slice[endIndex + 1] = round_to_presicion(sin(radians(180.)), 5);
|
slice[endIndex + 1] = round_to_presicion(sin(radians(180.)), 5);
|
||||||
slice[endIndex + 2] = 0;
|
slice[endIndex + 2] = 0;
|
||||||
|
@ -118,15 +105,17 @@ float *CoilSegment::calculateSlice() {
|
||||||
return slice;
|
return slice;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoilSegment::constructSegment(float *slice) {
|
void CoilSegment::constructSegment(double *slice) {
|
||||||
float degreesPerDay = 360.f / DAYS_IN_YEAR;
|
|
||||||
|
double degreesPerDay = 360.f / DAYS_IN_YEAR;
|
||||||
|
|
||||||
for (uint32_t day = 0; day < DAYS_IN_YEAR; day ++) {
|
for (uint32_t day = 0; day < DAYS_IN_YEAR; day ++) {
|
||||||
float daysDegree = day * degreesPerDay;
|
float daysDegree = day * degreesPerDay;
|
||||||
|
// TODO: replace hardcoded value to coil->getWidth();
|
||||||
vec3 daysPosition = vec3(
|
vec3 daysPosition = vec3(
|
||||||
cos(radians(daysDegree)) * coil->getRadius(),
|
cos(radians(daysDegree)) * 200,
|
||||||
10* daysDegree/360.,
|
10* daysDegree/360.,
|
||||||
sin(radians(daysDegree)) * coil->getRadius()
|
sin(radians(daysDegree)) * 200
|
||||||
);
|
);
|
||||||
|
|
||||||
mat4 transform = mat4(1.);
|
mat4 transform = mat4(1.);
|
||||||
|
@ -161,78 +150,14 @@ void CoilSegment::constructSegment(float *slice) {
|
||||||
vertices[currentPointOffset + 1] = point.y;
|
vertices[currentPointOffset + 1] = point.y;
|
||||||
vertices[currentPointOffset + 2] = point.z;
|
vertices[currentPointOffset + 2] = point.z;
|
||||||
|
|
||||||
vertices[currentPointOffset + 3] = 0.5;
|
memcpy(
|
||||||
vertices[currentPointOffset + 4] = 0.5;
|
vertices + currentPointOffset + 3,
|
||||||
vertices[currentPointOffset + 5] = 0.5;
|
slice + slicePointOffset + 3,
|
||||||
|
3
|
||||||
// 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.
|
// Sample layout of 2 slices with 3 points.
|
||||||
// |x |y |z |r |g |b | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
// |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
|
// 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
|
||||||
|
@ -240,48 +165,45 @@ uint64_t CoilSegment::fillEBO(uint64_t EBO) {
|
||||||
// | slice | slice |
|
// | slice | slice |
|
||||||
//
|
//
|
||||||
void CoilSegment::calculate() {
|
void CoilSegment::calculate() {
|
||||||
float *slice = calculateSlice();
|
double *slice = calculateSlice();
|
||||||
|
|
||||||
constructSegment(slice);
|
constructSegment(slice);
|
||||||
exportSegmentToCsv();
|
exportSegmentToCsv();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float *CoilSegment::getVertices() { return vertices; }
|
double *CoilSegment::getVertices() {
|
||||||
|
return vertices;
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t CoilSegment::getVerticesLength() { return verticesLength; }
|
uint64_t CoilSegment::getVerticesLength() {
|
||||||
|
return verticesLength;
|
||||||
uint16_t CoilSegment::getYear() { return year; }
|
}
|
||||||
|
|
||||||
void CoilSegment::render() {
|
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;
|
void CoilSegment::exportSliceToCSV(double *slice) {
|
||||||
|
cout << "x,y,z" << endl;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < sliceDetalization+2; i ++) {
|
for (uint32_t i = 0; i < sliceDetalization+2; i ++) {
|
||||||
uint32_t offset = FIELDS_IN_POINT * i;
|
uint32_t offset = FIELDS_IN_POINT * i;
|
||||||
outFile
|
cout
|
||||||
<< slice[offset + 0] << ","
|
<< slice[offset + 0] << ","
|
||||||
<< slice[offset + 1] << ",0" << endl;
|
<< slice[offset + 1] << ",0" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoilSegment::exportSegmentToCsv() {
|
void CoilSegment::exportSegmentToCsv() {
|
||||||
cout << "Exporting segment to csv" << endl;
|
cout << "x,y,z" << endl;
|
||||||
std::ofstream outFile("./segment_export.csv");
|
|
||||||
|
|
||||||
outFile << "x,y,z" << endl;
|
|
||||||
|
|
||||||
for (uint16_t day = 0; day < DAYS_IN_YEAR; day ++) {
|
for (uint16_t day = 0; day < DAYS_IN_YEAR; day ++) {
|
||||||
uint64_t dayOffset = day * (2+sliceDetalization) * FIELDS_IN_POINT;
|
uint64_t dayOffset = day * (2+sliceDetalization) * FIELDS_IN_POINT;
|
||||||
|
|
||||||
for (uint32_t point_in_slice = 0; point_in_slice < (2+sliceDetalization); point_in_slice ++) {
|
for (uint32_t point_in_slice = 0; point_in_slice < (2+sliceDetalization); point_in_slice ++) {
|
||||||
uint32_t sliceOffset = point_in_slice * FIELDS_IN_POINT;
|
uint32_t sliceOffset = point_in_slice * FIELDS_IN_POINT;
|
||||||
outFile << vertices[dayOffset + sliceOffset + 0] << ","
|
cout << vertices[dayOffset + sliceOffset + 0] << ","
|
||||||
<< vertices[dayOffset + sliceOffset + 1] << ","
|
<< vertices[dayOffset + sliceOffset + 1] << ","
|
||||||
<< vertices[dayOffset + sliceOffset + 2] << endl;
|
<< vertices[dayOffset + sliceOffset + 2] << endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,26 +13,23 @@ class CoilSegment {
|
||||||
int shift;
|
int shift;
|
||||||
uint32_t sliceDetalization;
|
uint32_t sliceDetalization;
|
||||||
bool isLeap;
|
bool isLeap;
|
||||||
float *vertices;
|
double *vertices;
|
||||||
uint64_t verticesLength;
|
uint64_t verticesLength;
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
float* calculateSlice();
|
double* calculateSlice();
|
||||||
void constructSegment(float *slice);
|
void constructSegment(double *slice);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CoilSegment(Coil* coil, uint16_t year, uint16_t height, int shift, uint32_t sliceDetalization, bool isLeap);
|
CoilSegment(Coil* coil, uint16_t year, uint16_t height, int shift, uint32_t sliceDetalization, bool isLeap);
|
||||||
void calculate();
|
void calculate();
|
||||||
void printVertices();
|
void printVertices();
|
||||||
float *getVertices();
|
double *getVertices();
|
||||||
uint64_t getVerticesLength();
|
uint64_t getVerticesLength();
|
||||||
void printSlice(float *slice);
|
void printSlice(double *slice);
|
||||||
void exportSliceToCSV(float *slice);
|
void exportSliceToCSV(double *slice);
|
||||||
void exportSegmentToCsv();
|
void exportSegmentToCsv();
|
||||||
void render();
|
void render();
|
||||||
void fillVBO();
|
|
||||||
uint64_t fillEBO(uint64_t EBO);
|
|
||||||
uint16_t getYear();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COIL_SEGMENT_HPP
|
#endif // COIL_SEGMENT_HPP
|
144
src/main.cpp
144
src/main.cpp
|
@ -3,23 +3,11 @@
|
||||||
#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/coil.hpp"
|
||||||
#include <coil/segment.hpp>
|
#include "coil/segment.hpp"
|
||||||
#include <utils/utils.hpp>
|
|
||||||
|
|
||||||
using std::cerr;
|
#define RAND_0_1 ((double)rand()) / RAND_MAX
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
|
|
||||||
#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);
|
||||||
|
@ -31,108 +19,28 @@ void processInput(GLFWwindow *window) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateVertices(double (&vertices)[24]) {
|
||||||
|
// if (RAND_0_1 < 0.99f) return;
|
||||||
|
double 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));
|
||||||
|
}
|
||||||
|
|
||||||
int main () {
|
int main () {
|
||||||
|
Coil c = Coil(2025, 1);
|
||||||
Coil c = Coil(2025, 1, 5, 50, 10);
|
|
||||||
|
|
||||||
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(DISPLAY_WIDTH, DISPLAY_HEIGHT, "TimeCoil", NULL, NULL);
|
|
||||||
if (window == NULL) {
|
|
||||||
cerr << "Failed to create GLFW window." << endl;
|
|
||||||
gracefulExit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
glfwSetFramebufferSizeCallback(window, framebufferSizeCallback);
|
|
||||||
|
|
||||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
|
||||||
cerr << "Failed to initialize GLAD." << endl;
|
|
||||||
gracefulExit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
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)) {
|
|
||||||
processInput(window);
|
|
||||||
|
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
|
|
||||||
glm::mat4 model = glm::mat4(1.0f);
|
|
||||||
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));
|
|
||||||
|
|
||||||
c.render();
|
|
||||||
// glBindVertexArray(VAO);
|
|
||||||
// glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
|
||||||
glfwPollEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
// CoilSegment cs = CoilSegment(10, 0, false);
|
// CoilSegment cs = CoilSegment(10, 0, false);
|
||||||
// for (auto segment : c.getSegments()) {
|
for (auto segment : c.getSegments()) {
|
||||||
// // segment.printVertices();
|
// segment.printVertices();
|
||||||
// }
|
}
|
||||||
// cs.printVertices();
|
// cs.printVertices();
|
||||||
gracefulExit(0);
|
return 0;
|
||||||
// srand(time(0));
|
// srand(time(0));
|
||||||
// glfwInit();
|
// glfwInit();
|
||||||
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
|
@ -158,10 +66,10 @@ int main () {
|
||||||
|
|
||||||
// unsigned int shaderProgram = prepareShaders();
|
// unsigned int shaderProgram = prepareShaders();
|
||||||
|
|
||||||
// float *vertices = cs.getVertices();
|
// double *vertices = cs.getVertices();
|
||||||
// unsigned int amountOfVerticies = cs.getVerticesLength();
|
// unsigned int amountOfVerticies = cs.getVerticesLength();
|
||||||
// std::cout << amountOfVerticies << std::endl;
|
// std::cout << amountOfVerticies << std::endl;
|
||||||
// // float vertices[] = {
|
// // double vertices[] = {
|
||||||
// // -1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, // upper left
|
// // -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, 0.0f, 1.0f, 0.0f, // bottom left
|
||||||
// // 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // upper right
|
// // 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // upper right
|
||||||
|
@ -184,10 +92,10 @@ int main () {
|
||||||
// glBufferData(GL_ARRAY_BUFFER, amountOfVerticies, vertices, GL_STATIC_DRAW);
|
// glBufferData(GL_ARRAY_BUFFER, amountOfVerticies, vertices, GL_STATIC_DRAW);
|
||||||
// // glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, 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);
|
// glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, 6 * sizeof(double), (void*)0);
|
||||||
// glEnableVertexAttribArray(0);
|
// glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
// glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*) (3 * sizeof(float)));
|
// glVertexAttribPointer(1, 3, GL_DOUBLE, GL_FALSE, 6 * sizeof(double), (void*) (3 * sizeof(double)));
|
||||||
// glEnableVertexAttribArray(1);
|
// glEnableVertexAttribArray(1);
|
||||||
|
|
||||||
// glBindVertexArray(0);
|
// glBindVertexArray(0);
|
||||||
|
@ -200,8 +108,8 @@ int main () {
|
||||||
|
|
||||||
// glUseProgram(shaderProgram);
|
// glUseProgram(shaderProgram);
|
||||||
|
|
||||||
// // float time = glfwGetTime();
|
// // double time = glfwGetTime();
|
||||||
// // float greenValue = sin(time);
|
// // double greenValue = sin(time);
|
||||||
|
|
||||||
|
|
||||||
// // int vertexColorLocation = glGetUniformLocation(shaderProgram, "MyColor");
|
// // int vertexColorLocation = glGetUniformLocation(shaderProgram, "MyColor");
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
float round_to_presicion( float value, int precision ) {
|
double round_to_presicion( double value, int precision ) {
|
||||||
const int adjustment = pow(10,precision);
|
const int adjustment = pow(10,precision);
|
||||||
return floor( value*(adjustment) + 0.5 )/adjustment;
|
return floor( value*(adjustment) + 0.5 )/adjustment;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ void gracefulExit(int code) {
|
||||||
exit(code);
|
exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t prepareShaders() {
|
unsigned int prepareShaders() {
|
||||||
unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
unsigned int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
unsigned int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
float round_to_presicion( float value, int precision );
|
double round_to_presicion( double value, int precision );
|
||||||
|
|
||||||
std::string readFile(std::string path);
|
std::string readFile(std::string path);
|
||||||
|
|
||||||
void gracefulExit(int code);
|
void gracefulExit(int code);
|
||||||
|
|
||||||
uint64_t prepareShaders();
|
unsigned int prepareShaders();
|
Loading…
Reference in New Issue