fixed wrong rotation side
This commit is contained in:
parent
a6f9581a70
commit
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.
|
@ -6,12 +6,14 @@ include(FetchContent)
|
|||
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})
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
#include "coil.hpp"
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <coil/coil.hpp>
|
||||
#include <coil/segment.hpp>
|
||||
#include <utils/utils.hpp>
|
||||
|
||||
Coil::Coil(uint32_t currentYear, uint32_t amountOfSegments)
|
||||
: currentYear(currentYear) {
|
||||
|
@ -14,4 +19,18 @@ std::vector<CoilSegment> &Coil::getSegments() {
|
|||
|
||||
double Coil::getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
void Coil::render() {
|
||||
prepareShaders();
|
||||
uint64_t VBO;
|
||||
glGenBuffers(1, (unsigned int*) &(VBO));
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
for (CoilSegment segment : segments) {
|
||||
double* vertices = segment.getVertices();
|
||||
uint64_t verticesLength = segment.getVerticesLength();
|
||||
glBufferData(GL_ARRAY_BUFFER, verticesLength, vertices, GL_STATIC_DRAW);
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ class Coil {
|
|||
Coil(uint32_t currentYear, uint32_t amountOfSegments);
|
||||
std::vector<CoilSegment> &getSegments();
|
||||
double getWidth();
|
||||
void render();
|
||||
};
|
||||
|
||||
#endif // COIL_HPP
|
|
@ -1,13 +1,15 @@
|
|||
#include "segment.hpp"
|
||||
#include "coil.hpp"
|
||||
#include "glm/ext/matrix_float4x4.hpp"
|
||||
#include "glm/ext/matrix_transform.hpp"
|
||||
#include "glm/trigonometric.hpp"
|
||||
#include <glm/ext/matrix_float4x4.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/trigonometric.hpp>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#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)
|
||||
|
@ -66,10 +68,6 @@ void CoilSegment::printVertices() {
|
|||
}
|
||||
}
|
||||
|
||||
double round_to_presicion( double value, int precision ) {
|
||||
const int adjustment = pow(10,precision);
|
||||
return floor( value*(adjustment) + 0.5 )/adjustment;
|
||||
}
|
||||
|
||||
double *CoilSegment::calculateSlice() {
|
||||
uint32_t size = (/*start and end of a slize*/2 + sliceDetalization) * FIELDS_IN_POINT * sizeof(double);
|
||||
|
@ -129,7 +127,7 @@ void CoilSegment::constructSegment(double *slice) {
|
|||
|
||||
transform = rotate(
|
||||
transform,
|
||||
radians(daysDegree),
|
||||
-radians(daysDegree),
|
||||
vec3(
|
||||
0.0,
|
||||
1.0,
|
||||
|
@ -178,23 +176,12 @@ double *CoilSegment::getVertices() {
|
|||
return vertices;
|
||||
}
|
||||
|
||||
uint16_t CoilSegment::getVerticesLength() {
|
||||
uint64_t CoilSegment::getVerticesLength() {
|
||||
return verticesLength;
|
||||
}
|
||||
|
||||
void CoilSegment::printSlice(double *slice) {
|
||||
for (uint32_t i = 0; i < sliceDetalization+2; i ++) {
|
||||
uint32_t offset = FIELDS_IN_POINT * i;
|
||||
cout << "Point ("
|
||||
<< slice[offset + 0] << ", "
|
||||
<< slice[offset + 1] << ", "
|
||||
<< slice[offset + 2] << ", "
|
||||
<< ") rgb("
|
||||
<< slice[offset + 3] << ", "
|
||||
<< slice[offset + 4] << ", "
|
||||
<< slice[offset + 5] << ")"
|
||||
<< endl;
|
||||
}
|
||||
void CoilSegment::render() {
|
||||
|
||||
}
|
||||
|
||||
void CoilSegment::exportSliceToCSV(double *slice) {
|
||||
|
|
|
@ -14,7 +14,7 @@ class CoilSegment {
|
|||
uint32_t sliceDetalization;
|
||||
bool isLeap;
|
||||
double *vertices;
|
||||
uint32_t verticesLength;
|
||||
uint64_t verticesLength;
|
||||
|
||||
void init();
|
||||
double* calculateSlice();
|
||||
|
@ -25,10 +25,11 @@ class CoilSegment {
|
|||
void calculate();
|
||||
void printVertices();
|
||||
double *getVertices();
|
||||
uint16_t getVerticesLength();
|
||||
uint64_t getVerticesLength();
|
||||
void printSlice(double *slice);
|
||||
void exportSliceToCSV(double *slice);
|
||||
void exportSegmentToCsv();
|
||||
void render();
|
||||
};
|
||||
|
||||
#endif // COIL_SEGMENT_HPP
|
77
src/main.cpp
77
src/main.cpp
|
@ -1,7 +1,5 @@
|
|||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
@ -21,32 +19,6 @@ 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(double (&vertices)[24]) {
|
||||
// if (RAND_0_1 < 0.99f) return;
|
||||
double a[] = {
|
||||
|
@ -60,55 +32,6 @@ void updateVertices(double (&vertices)[24]) {
|
|||
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 () {
|
||||
Coil c = Coil(2025, 1);
|
||||
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
double round_to_presicion( double 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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
double round_to_presicion( double value, int precision );
|
||||
|
||||
std::string readFile(std::string path);
|
||||
|
||||
void gracefulExit(int code);
|
||||
|
||||
unsigned int prepareShaders();
|
Loading…
Reference in New Issue