Compare commits
10 Commits
97fcc6cdda
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| fef2ce8f2b | |||
| 2215208c46 | |||
| ef2a366e8e | |||
| 8b84258c1a | |||
| 5ae1c82ef6 | |||
| fc51065d85 | |||
| 1e11e66d16 | |||
| 701ff99000 | |||
| dd3ee57fcb | |||
| e7bfc4af89 |
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
.gitignore
vendored
1
.gitignore
vendored
@@ -35,3 +35,4 @@
|
||||
build/
|
||||
|
||||
*.csv
|
||||
.cache/
|
||||
|
||||
13
.vscode/launch.json
vendored
Normal file
13
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug",
|
||||
"program": "${workspaceFolder}/build/TimeCoil",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/build"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -3,10 +3,12 @@ project(TimeCoil)
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
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
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/camera/camera.cpp
|
||||
)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
@@ -18,14 +20,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
|
||||
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(OpenGL REQUIRED)
|
||||
target_link_libraries(TimeCoil glfw OpenGL::GL glm)
|
||||
find_package(OpenGL 3.3 REQUIRED)
|
||||
find_package(glm REQUIRED)
|
||||
target_link_libraries(TimeCoil glfw OpenGL::GL glm::glm)
|
||||
|
||||
6
build.sh
6
build.sh
@@ -1,2 +1,6 @@
|
||||
#!/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
|
||||
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
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 col;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
out vec3 frag_col;
|
||||
|
||||
void main()
|
||||
{
|
||||
frag_col = col;
|
||||
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||
}
|
||||
128
src/camera/camera.cpp
Normal file
128
src/camera/camera.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <camera/camera.hpp>
|
||||
#include <glm/ext/scalar_constants.hpp>
|
||||
#include <glm/geometric.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
Camera::Camera(
|
||||
CameraType type, glm::vec3 pos, glm::vec3 up, float yaw,
|
||||
float pitch, float radialAngle, float speed, float angularSpeed,
|
||||
float sensitivity, float coilCenter, float segmentHeight
|
||||
)
|
||||
:
|
||||
type(type), pos(pos), worldUp(up), yaw(yaw), pitch(pitch),
|
||||
radialAngle(radialAngle), angularSpeed(angularSpeed),
|
||||
speed(speed), sensitivity(sensitivity), coilCenter(coilCenter), segmentHeight(segmentHeight)
|
||||
{}
|
||||
|
||||
glm::mat4 Camera::getViewMatrix() { return glm::lookAt(pos, pos + front, up); }
|
||||
|
||||
void Camera::processKeyboardInput(CameraMovement direction) {
|
||||
if (lastTime == -1) {
|
||||
lastTime = glfwGetTime();
|
||||
}
|
||||
float deltaTime = glfwGetTime() - lastTime;
|
||||
float velocity = speed * deltaTime;
|
||||
float angularVelocity = angularSpeed * deltaTime;
|
||||
|
||||
switch (type) {
|
||||
case CameraType::FREE: {
|
||||
switch (direction) {
|
||||
case CameraMovement::STOP:
|
||||
break;
|
||||
case CameraMovement::FORWARD:
|
||||
pos += front * velocity;
|
||||
break;
|
||||
case CameraMovement::BACKWARD:
|
||||
pos -= front * velocity;
|
||||
break;
|
||||
case CameraMovement::LEFT:
|
||||
pos -= right * velocity;
|
||||
break;
|
||||
case CameraMovement::RIGHT:
|
||||
pos += right * velocity;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CameraType::SPINNING: {
|
||||
switch (direction) {
|
||||
case CameraMovement::LEFT:
|
||||
radialAngle += angularVelocity;
|
||||
pos = glm::vec3(1.2 * coilCenter * cos(radialAngle), radialAngle/(2*glm::pi<float>()) * segmentHeight + 3, 1.2*coilCenter * sin(radialAngle));
|
||||
break;
|
||||
case CameraMovement::RIGHT:
|
||||
radialAngle -= angularVelocity;
|
||||
pos = glm::vec3(1.2 * coilCenter * cos(radialAngle), radialAngle/(2*glm::pi<float>()) * segmentHeight + 3, 1.2*coilCenter * sin(radialAngle));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
lastTime = glfwGetTime();
|
||||
|
||||
updateCameraVectors();
|
||||
}
|
||||
|
||||
void Camera::processMouseInput(GLFWwindow *window, double mouseX, double mouseY) {
|
||||
switch (type) {
|
||||
case CameraType::FREE: {
|
||||
float dX = 0, dY = 0;
|
||||
if (prevX == -1 && prevY == -1) {
|
||||
prevX = mouseX;
|
||||
prevY = mouseY;
|
||||
}
|
||||
dX = sensitivity * (mouseX - prevX);
|
||||
dY = -sensitivity * (mouseY - prevY);
|
||||
|
||||
yaw += dX;
|
||||
pitch += dY;
|
||||
|
||||
pitch = glm::clamp(pitch, (float)-89., (float)89.);
|
||||
prevX = mouseX;
|
||||
prevY = mouseY;
|
||||
}
|
||||
case CameraType::SPINNING: {
|
||||
|
||||
}
|
||||
}
|
||||
updateCameraVectors();
|
||||
|
||||
}
|
||||
|
||||
void Camera::setCameraType(CameraType type) {
|
||||
if (this->type == CameraType::FREE && type == CameraType::SPINNING) {
|
||||
radialAngle = atan2(pos.z, pos.x);
|
||||
}
|
||||
this->type = type;
|
||||
|
||||
updateCameraVectors();
|
||||
}
|
||||
|
||||
CameraType Camera::getCameraType() { return type; }
|
||||
|
||||
void Camera::updateCameraVectors() {
|
||||
glm::vec3 front;
|
||||
|
||||
switch (type) {
|
||||
case CameraType::FREE: {
|
||||
front.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
|
||||
front.y = sin(glm::radians(pitch));
|
||||
front.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
|
||||
break;
|
||||
}
|
||||
case CameraType::SPINNING: {
|
||||
float x = coilCenter * cos(radialAngle);
|
||||
float y = radialAngle/(2*glm::pi<float>()) * segmentHeight;
|
||||
float z = coilCenter * sin(radialAngle);
|
||||
|
||||
front = -glm::vec3(x, y, z);
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->front = glm::normalize(front);
|
||||
right = glm::normalize(glm::cross(front, worldUp));
|
||||
up = glm::normalize(glm::cross(right, front));
|
||||
}
|
||||
46
src/camera/camera.hpp
Normal file
46
src/camera/camera.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef COIL_CAMERA_HPP
|
||||
#define COIL_CAMERA_HPP
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
enum CameraType { FREE = 0, SPINNING };
|
||||
|
||||
inline CameraType& operator++ (CameraType& type) {
|
||||
type = static_cast<CameraType>(type + 1 > 1? 0 : type + 1);
|
||||
return type;
|
||||
}
|
||||
|
||||
enum CameraMovement {
|
||||
STOP,
|
||||
FORWARD,
|
||||
BACKWARD,
|
||||
LEFT,
|
||||
RIGHT
|
||||
};
|
||||
|
||||
class Camera {
|
||||
float pitch, yaw, radialAngle;
|
||||
float prevX = -1, prevY = -1;
|
||||
glm::vec3 pos, front, up, right, worldUp;
|
||||
CameraType type;
|
||||
float lastTime = -1;
|
||||
|
||||
float speed, angularSpeed, sensitivity;
|
||||
float coilCenter, segmentHeight;
|
||||
|
||||
public:
|
||||
Camera(CameraType type, glm::vec3 pos, glm::vec3 up, float yaw, float pitch, float radialAngle, float speed, float angularSpeed, float sensitivity, float coilCenter, float segmentHeight);
|
||||
|
||||
glm::mat4 getViewMatrix();
|
||||
void processKeyboardInput(CameraMovement direction = CameraMovement::STOP);
|
||||
void processMouseInput(GLFWwindow *window, double offsetX, double offsetY);
|
||||
|
||||
void setCameraType(CameraType type);
|
||||
CameraType getCameraType();
|
||||
|
||||
private:
|
||||
void updateCameraVectors();
|
||||
};
|
||||
|
||||
#endif // COIL_CAMERA_HPP
|
||||
@@ -1,36 +1,142 @@
|
||||
#include <glad/glad.h>
|
||||
#include <coil/coil.hpp>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <coil/coil.hpp>
|
||||
#include <coil/segment.hpp>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <glad/glad.h>
|
||||
#include <iostream>
|
||||
#include <utils/utils.hpp>
|
||||
|
||||
Coil::Coil(uint32_t currentYear, uint32_t amountOfSegments)
|
||||
: currentYear(currentYear) {
|
||||
Coil::Coil(uint32_t currentYear, uint32_t amountOfSegments, float segmentHeight, uint32_t sliceDetalization, float radius, float width)
|
||||
: radius(radius), width(width), segmentHeight(segmentHeight), 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, 3,false));
|
||||
|
||||
segments.push_back(CoilSegment(this, year, segmentHeight, i, sliceDetalization));
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<CoilSegment> &Coil::getSegments() {
|
||||
return segments;
|
||||
}
|
||||
std::vector<CoilSegment> &Coil::getSegments() { return segments; }
|
||||
|
||||
double Coil::getWidth() {
|
||||
return width;
|
||||
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);
|
||||
|
||||
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() {
|
||||
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);
|
||||
|
||||
|
||||
glBindVertexArray(VAO);
|
||||
uint64_t verticesLength = 0;
|
||||
for (CoilSegment &segment : segments) {
|
||||
verticesLength += segment.getVerticesLength();
|
||||
}
|
||||
|
||||
float *vertices = (float *) malloc(verticesLength * sizeof(float));
|
||||
if (vertices == NULL) {
|
||||
std::cerr << "Couldn't allocate memory for vertices." << std::endl;
|
||||
}
|
||||
fillVBO(vertices);
|
||||
free(vertices);
|
||||
uint32_t indicesAmount = fillEBO();
|
||||
|
||||
glDrawElements(GL_TRIANGLES, indicesAmount,
|
||||
GL_UNSIGNED_INT, 0);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
void Coil::fillVBO(float *vertices) {
|
||||
uint64_t verticesSize = 0;
|
||||
for (CoilSegment &segment : segments) {
|
||||
float *segmentVertices = segment.getVertices();
|
||||
uint32_t segmentVerticesLength = segment.getVerticesLength();
|
||||
uint32_t segmentVerticesSize = segmentVerticesLength * sizeof(float);
|
||||
|
||||
memcpy(&vertices[verticesSize], segmentVertices, segmentVerticesSize);
|
||||
verticesSize += segmentVerticesLength;
|
||||
}
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, verticesSize * sizeof(float), vertices, GL_STATIC_DRAW);
|
||||
}
|
||||
uint32_t Coil::fillEBO() {
|
||||
uint32_t indicesLength = 0;
|
||||
|
||||
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;
|
||||
|
||||
uint32_t yearOffset = 0;
|
||||
|
||||
for (uint32_t segmentNumber = 0; segmentNumber < segments.size(); segmentNumber++) {
|
||||
CoilSegment &segment = segments[segmentNumber];
|
||||
uint32_t slicePointsAmount = segment.getSlicePointsAmount();
|
||||
|
||||
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;
|
||||
if (segmentNumber == segments.size() - 1 && day == segment.getDaysAmount() - 1) {
|
||||
continue;
|
||||
}
|
||||
// First triangle
|
||||
indices[currentIndex] = currentPointIndex;
|
||||
currentIndex++;
|
||||
indices[currentIndex] = currentPointIndex + slicePointsAmount;
|
||||
currentIndex++;
|
||||
indices[currentIndex] = currentPointIndex + 1;
|
||||
currentIndex++;
|
||||
// Second triangle
|
||||
|
||||
indices[currentIndex] = currentPointIndex + 1;
|
||||
currentIndex++;
|
||||
if (pointOfSlice == segment.getSlicePointsAmount() - 1) {
|
||||
indices[currentIndex] = currentPointIndex - (slicePointsAmount - 1);
|
||||
currentIndex++;
|
||||
indices[currentIndex] = currentPointIndex;
|
||||
} else {
|
||||
indices[currentIndex] = currentPointIndex + slicePointsAmount + 1;
|
||||
currentIndex++;
|
||||
indices[currentIndex] = currentPointIndex + slicePointsAmount;
|
||||
}
|
||||
currentIndex++;
|
||||
}
|
||||
}
|
||||
yearOffset += segment.getVerticesAmount();
|
||||
}
|
||||
if (currentIndex != indicesLength) {
|
||||
std::cerr << "currentIndex == indicesLength assertion failed" << std::endl;
|
||||
std::cerr << currentIndex << " " << indicesLength << std::endl;
|
||||
}
|
||||
|
||||
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(uint32_t) * indicesLength, indices, GL_STATIC_DRAW);
|
||||
|
||||
free(indices);
|
||||
return indicesLength;
|
||||
}
|
||||
@@ -1,26 +1,35 @@
|
||||
#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
|
||||
// (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
|
||||
double radius;
|
||||
float radius;
|
||||
// distance between coil slices edges
|
||||
double width;
|
||||
double segmentHeight;
|
||||
float width;
|
||||
float segmentHeight;
|
||||
uint32_t currentYear;
|
||||
std::vector<CoilSegment> segments;
|
||||
|
||||
GLuint VBO, VAO, EBO;
|
||||
|
||||
public:
|
||||
Coil(uint32_t currentYear, uint32_t amountOfSegments);
|
||||
Coil(uint32_t currentYear, uint32_t amountOfSegments, float segmentHeight, uint32_t sliceDetalization, float radius, float width);
|
||||
std::vector<CoilSegment> &getSegments();
|
||||
double getWidth();
|
||||
float getWidth();
|
||||
float getRadius();
|
||||
|
||||
void render();
|
||||
void fillVBO(float *vertices);
|
||||
uint32_t fillEBO();
|
||||
void initGLBuffers();
|
||||
};
|
||||
|
||||
#endif // COIL_HPP
|
||||
@@ -1,8 +1,10 @@
|
||||
#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>
|
||||
|
||||
@@ -10,10 +12,6 @@
|
||||
#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;
|
||||
@@ -28,184 +26,179 @@ 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();
|
||||
}
|
||||
Coil* coil,
|
||||
uint16_t year,
|
||||
uint16_t height,
|
||||
int shift,
|
||||
uint32_t sliceDetailization
|
||||
):
|
||||
coil(coil), year(year),
|
||||
height(height), shift(shift),
|
||||
sliceDetailization(sliceDetailization),
|
||||
slicePointsAmount(sliceDetailization + 2),
|
||||
//evil shit
|
||||
leap(year % 4 == 0? year % 100 == 0? year % 400 == 0 : true : false) {
|
||||
init();
|
||||
// calculate();
|
||||
}
|
||||
|
||||
void CoilSegment::init () {
|
||||
verticesLength = DAYS_IN_YEAR * FIELDS_IN_POINT * (sliceDetalization+2);
|
||||
vertices = (double *) calloc(verticesLength, sizeof(double));
|
||||
if (vertices == NULL) {
|
||||
cerr << "Allocation failed" << endl;
|
||||
exit(-1);
|
||||
}
|
||||
// cout << "Initialized CoilSegment"
|
||||
// << "(year: " << year
|
||||
// << ", height: " << height
|
||||
// << ", shift: " << shift
|
||||
// << ", isLeap: " << isLeap <<")" << endl;
|
||||
verticesLength = getDaysAmount() * slicePointsAmount * FIELDS_IN_POINT;
|
||||
vertices = (float *) malloc(verticesLength * sizeof(float));
|
||||
if (vertices == NULL) {
|
||||
cerr << "Allocation failed" << endl;
|
||||
exit(-1);
|
||||
}
|
||||
calculate();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
for (uint16_t day = 0; day < getDaysAmount(); 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double *CoilSegment::calculateSlice() {
|
||||
uint32_t size = (/*start and end of a slize*/2 + sliceDetalization) * FIELDS_IN_POINT * sizeof(double);
|
||||
double *slice = (double *)malloc(size);
|
||||
// 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 *CoilSegment::calculateSlice() {
|
||||
uint32_t size = slicePointsAmount * 3 * sizeof(float);
|
||||
float *slice = (float *)malloc(size);
|
||||
|
||||
double degreeByPoint = -180. / (sliceDetalization + 1);
|
||||
// Start of a slice
|
||||
slice[0] = cos(0);
|
||||
slice[1] = sin(0);
|
||||
slice[2] = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
float degreeByPoint = 180. / (sliceDetailization + 1);
|
||||
|
||||
// End of a slice
|
||||
uint32_t endIndex = (size / sizeof(double) - 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;
|
||||
for (uint32_t i = 1; i <= sliceDetailization; i ++) {
|
||||
uint32_t offset = 3 * i;
|
||||
|
||||
return slice;
|
||||
slice[offset + 0] = round_to_precision(cos(radians(degreeByPoint * i)), 5);
|
||||
slice[offset + 1] = round_to_precision(sin(radians(degreeByPoint * i)), 5);
|
||||
slice[offset + 2] = 0;
|
||||
}
|
||||
|
||||
// End of a slice
|
||||
uint32_t endIndex = (size / sizeof(float) - 3);
|
||||
slice[endIndex + 0] = round_to_precision(cos(radians(180.)), 5);
|
||||
slice[endIndex + 1] = round_to_precision(sin(radians(180.)), 5);
|
||||
slice[endIndex + 2] = 0;
|
||||
|
||||
return slice;
|
||||
}
|
||||
|
||||
void CoilSegment::constructSegment(double *slice) {
|
||||
void CoilSegment::constructSegment(float *slice) {
|
||||
float degreesPerDay = 360.f / getDaysAmount();
|
||||
|
||||
double degreesPerDay = 360.f / DAYS_IN_YEAR;
|
||||
for (uint32_t day = 0; day < getDaysAmount(); day ++) {
|
||||
float daysDegree = day * degreesPerDay;
|
||||
vec3 daysPosition = vec3(
|
||||
cos(radians(daysDegree)) * coil->getRadius(),
|
||||
height * daysDegree/360. + shift * height,
|
||||
sin(radians(daysDegree)) * coil->getRadius()
|
||||
);
|
||||
|
||||
for (uint32_t day = 0; day < DAYS_IN_YEAR; day ++) {
|
||||
float daysDegree = day * degreesPerDay;
|
||||
// TODO: replace hardcoded value to coil->getWidth();
|
||||
vec3 daysPosition = vec3(
|
||||
cos(radians(daysDegree)) * 200,
|
||||
10* daysDegree/360.,
|
||||
sin(radians(daysDegree)) * 200
|
||||
);
|
||||
mat4 transform = mat4(1.);
|
||||
|
||||
mat4 transform = mat4(1.);
|
||||
transform = translate(
|
||||
transform,
|
||||
daysPosition
|
||||
);
|
||||
|
||||
transform = translate(
|
||||
transform,
|
||||
daysPosition
|
||||
);
|
||||
transform = rotate(
|
||||
transform,
|
||||
-radians(daysDegree),
|
||||
vec3(
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
)
|
||||
);
|
||||
|
||||
transform = rotate(
|
||||
transform,
|
||||
-radians(daysDegree),
|
||||
vec3(
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
)
|
||||
);
|
||||
for (uint32_t slicePoint = 0; slicePoint < slicePointsAmount; slicePoint ++) {
|
||||
uint32_t slicePointOffset = 3 * slicePoint;
|
||||
vec4 point(
|
||||
slice[slicePointOffset + 0],
|
||||
slice[slicePointOffset + 1],
|
||||
slice[slicePointOffset + 2],
|
||||
1
|
||||
);
|
||||
|
||||
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;
|
||||
point = transform * point;
|
||||
uint64_t currentPointOffset = day * slicePointsAmount * FIELDS_IN_POINT + slicePointOffset*2;
|
||||
vertices[currentPointOffset + 0] = point.x;
|
||||
vertices[currentPointOffset + 1] = point.y;
|
||||
vertices[currentPointOffset + 2] = point.z;
|
||||
|
||||
memcpy(
|
||||
vertices + currentPointOffset + 3,
|
||||
slice + slicePointOffset + 3,
|
||||
3
|
||||
);
|
||||
}
|
||||
}
|
||||
vertices[currentPointOffset + 3] = daysDegree/360.;
|
||||
vertices[currentPointOffset + 4] = daysDegree/360.;
|
||||
vertices[currentPointOffset + 5] = daysDegree/360.;
|
||||
}
|
||||
}
|
||||
free(slice);
|
||||
}
|
||||
// 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 |
|
||||
// | point | point | point | point | point | point |
|
||||
// | slice | slice |
|
||||
//
|
||||
//
|
||||
void CoilSegment::calculate() {
|
||||
double *slice = calculateSlice();
|
||||
|
||||
constructSegment(slice);
|
||||
exportSegmentToCsv();
|
||||
float *slice = calculateSlice();
|
||||
|
||||
constructSegment(slice);
|
||||
}
|
||||
|
||||
double *CoilSegment::getVertices() {
|
||||
return vertices;
|
||||
}
|
||||
float *CoilSegment::getVertices() { return vertices; }
|
||||
|
||||
uint64_t CoilSegment::getVerticesLength() {
|
||||
return verticesLength;
|
||||
}
|
||||
uint64_t CoilSegment::getVerticesLength() { return verticesLength; }
|
||||
|
||||
void CoilSegment::render() {
|
||||
uint64_t CoilSegment::getVerticesAmount() { return verticesLength / FIELDS_IN_POINT; }
|
||||
|
||||
}
|
||||
uint16_t CoilSegment::getYear() { return year; }
|
||||
|
||||
void CoilSegment::exportSliceToCSV(double *slice) {
|
||||
cout << "x,y,z" << endl;
|
||||
|
||||
for (uint32_t i = 0; i < sliceDetalization+2; i ++) {
|
||||
uint32_t offset = FIELDS_IN_POINT * i;
|
||||
cout
|
||||
<< slice[offset + 0] << ","
|
||||
<< slice[offset + 1] << ",0" << endl;
|
||||
}
|
||||
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 < slicePointsAmount; i ++) {
|
||||
uint32_t offset = FIELDS_IN_POINT * i;
|
||||
outFile
|
||||
<< slice[offset + 0] << ","
|
||||
<< slice[offset + 1] << ",0" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void CoilSegment::exportSegmentToCsv() {
|
||||
cout << "x,y,z" << endl;
|
||||
cout << "Exporting segment to csv" << endl;
|
||||
std::ofstream outFile("./segment_export.csv");
|
||||
|
||||
for (uint16_t day = 0; day < DAYS_IN_YEAR; day ++) {
|
||||
uint64_t dayOffset = day * (2+sliceDetalization) * FIELDS_IN_POINT;
|
||||
outFile << "x,y,z" << endl;
|
||||
|
||||
for (uint32_t point_in_slice = 0; point_in_slice < (2+sliceDetalization); point_in_slice ++) {
|
||||
uint32_t sliceOffset = point_in_slice * FIELDS_IN_POINT;
|
||||
cout << vertices[dayOffset + sliceOffset + 0] << ","
|
||||
<< vertices[dayOffset + sliceOffset + 1] << ","
|
||||
<< vertices[dayOffset + sliceOffset + 2] << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (uint16_t day = 0; day < getDaysAmount(); day ++) {
|
||||
uint64_t dayOffset = day * slicePointsAmount * FIELDS_IN_POINT;
|
||||
|
||||
for (uint32_t point_in_slice = 0; point_in_slice < slicePointsAmount; 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t CoilSegment::getDaysAmount() { return leap? 366 : 365; }
|
||||
|
||||
bool const CoilSegment::isLeap() { return leap; }
|
||||
|
||||
uint32_t CoilSegment::getSliceDetailization() { return sliceDetailization; }
|
||||
|
||||
uint32_t CoilSegment::getSlicePointsAmount() { return sliceDetailization + 2; }
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// x, y, z, r, g, b
|
||||
#define FIELDS_IN_POINT 6
|
||||
|
||||
class Coil;
|
||||
|
||||
class CoilSegment {
|
||||
@@ -11,25 +14,32 @@ class CoilSegment {
|
||||
uint16_t height;
|
||||
// Number of a segments, counting from the central (which is 0)
|
||||
int shift;
|
||||
uint32_t sliceDetalization;
|
||||
bool isLeap;
|
||||
double *vertices;
|
||||
uint32_t sliceDetailization;
|
||||
uint32_t slicePointsAmount;
|
||||
bool leap;
|
||||
float *vertices;
|
||||
uint64_t verticesLength;
|
||||
|
||||
void init();
|
||||
double* calculateSlice();
|
||||
void constructSegment(double *slice);
|
||||
float* calculateSlice();
|
||||
void constructSegment(float *slice);
|
||||
|
||||
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);
|
||||
void calculate();
|
||||
void printVertices();
|
||||
double *getVertices();
|
||||
float *getVertices();
|
||||
uint64_t getVerticesLength();
|
||||
void printSlice(double *slice);
|
||||
void exportSliceToCSV(double *slice);
|
||||
uint64_t getVerticesAmount();
|
||||
void printSlice(float *slice);
|
||||
void exportSliceToCSV(float *slice);
|
||||
void exportSegmentToCsv();
|
||||
void render();
|
||||
uint16_t getYear();
|
||||
|
||||
uint16_t getDaysAmount();
|
||||
bool const isLeap();
|
||||
uint32_t getSliceDetailization();
|
||||
uint32_t getSlicePointsAmount();
|
||||
};
|
||||
|
||||
#endif // COIL_SEGMENT_HPP
|
||||
214
src/main.cpp
214
src/main.cpp
@@ -1,134 +1,132 @@
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#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 <coil/coil.hpp>
|
||||
#include <coil/segment.hpp>
|
||||
#include <utils/utils.hpp>
|
||||
#include <camera/camera.hpp>
|
||||
|
||||
#define RAND_0_1 ((double)rand()) / RAND_MAX
|
||||
using std::cerr;
|
||||
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) {
|
||||
glViewport(10, 10, width-10, height-10);
|
||||
}
|
||||
|
||||
void processInput(GLFWwindow *window) {
|
||||
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
float coilRadius = 100;
|
||||
float coilWidth = 10;
|
||||
float segmentHeight = 10;
|
||||
|
||||
// vertices = a;
|
||||
memcpy(vertices, a, sizeof(a));
|
||||
Camera cam = Camera(CameraType::FREE, glm::vec3(0., 0., 70.),
|
||||
glm::vec3(0., 1., 0.), -90, 0, 0, 40,
|
||||
1, 0.1, coilRadius + (coilWidth / 2), segmentHeight);
|
||||
|
||||
void processClickInput(GLFWwindow* window, int key, int scancode, int action, int mods) {
|
||||
if (key == GLFW_KEY_R && action == GLFW_PRESS) {
|
||||
CameraType type = cam.getCameraType();
|
||||
++type;
|
||||
std::cout << type << std::endl;
|
||||
cam.setCameraType(type);
|
||||
}
|
||||
}
|
||||
|
||||
void processPressInput(GLFWwindow *window) {
|
||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
return;
|
||||
}
|
||||
|
||||
CameraMovement dir;
|
||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||
dir = CameraMovement::FORWARD;
|
||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||
dir = CameraMovement::BACKWARD;
|
||||
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
||||
dir = CameraMovement::LEFT;
|
||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||
dir = CameraMovement::RIGHT;
|
||||
|
||||
cam.processKeyboardInput(dir);
|
||||
}
|
||||
|
||||
void processMousePosCallback(GLFWwindow *window, double deltaX, double deltaY) {
|
||||
cam.processMouseInput(window, deltaX, deltaY);
|
||||
}
|
||||
|
||||
int main () {
|
||||
Coil c = Coil(2025, 1);
|
||||
Coil coil = Coil(2024, 500, segmentHeight, 8, coilRadius, coilWidth);
|
||||
|
||||
// CoilSegment cs = CoilSegment(10, 0, false);
|
||||
for (auto segment : c.getSegments()) {
|
||||
// segment.printVertices();
|
||||
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);
|
||||
}
|
||||
// cs.printVertices();
|
||||
return 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();
|
||||
|
||||
// double *vertices = cs.getVertices();
|
||||
// unsigned int amountOfVerticies = cs.getVerticesLength();
|
||||
// std::cout << amountOfVerticies << std::endl;
|
||||
// // double 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_DOUBLE, GL_FALSE, 6 * sizeof(double), (void*)0);
|
||||
// glEnableVertexAttribArray(0);
|
||||
|
||||
// glVertexAttribPointer(1, 3, GL_DOUBLE, GL_FALSE, 6 * sizeof(double), (void*) (3 * sizeof(double)));
|
||||
// glEnableVertexAttribArray(1);
|
||||
|
||||
// glBindVertexArray(0);
|
||||
|
||||
// while(!glfwWindowShouldClose(window)) {
|
||||
// processInput(window);
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSetFramebufferSizeCallback(window, framebufferSizeCallback);
|
||||
glfwSetCursorPosCallback(window, processMousePosCallback);
|
||||
glfwSetKeyCallback(window, processClickInput);
|
||||
// glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
|
||||
// glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
// glClear(GL_COLOR_BUFFER_BIT);
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||
cerr << "Failed to initialize GLAD." << endl;
|
||||
gracefulExit(-1);
|
||||
}
|
||||
|
||||
// glUseProgram(shaderProgram);
|
||||
uint64_t shaderProgram = prepareShaders();
|
||||
glUseProgram(shaderProgram);
|
||||
|
||||
// // double time = glfwGetTime();
|
||||
// // double greenValue = sin(time);
|
||||
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));
|
||||
|
||||
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
coil.initGLBuffers();
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
while(!glfwWindowShouldClose(window)) {
|
||||
processPressInput(window);
|
||||
|
||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
glm::mat4 view = glm::mat4(1.0f);
|
||||
model = glm::rotate(model, glm::radians(0.0f), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
view = cam.getViewMatrix();
|
||||
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");
|
||||
// // glUniform4f(vertexColorLocation, 0, greenValue, 0, 1);
|
||||
// glBindVertexArray(VAO);
|
||||
coil.render();
|
||||
|
||||
// // 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);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
// glBindVertexArray(0);
|
||||
// glfwSwapBuffers(window);
|
||||
// glfwPollEvents();
|
||||
// }
|
||||
|
||||
// glDeleteVertexArrays(1, &VAO);
|
||||
// glDeleteBuffers(1, &VBO);
|
||||
// glDeleteProgram(shaderProgram);
|
||||
// gracefulExit(0);
|
||||
gracefulExit(0);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
#ifndef COIL_UI_H
|
||||
#define COIL_UI_H
|
||||
|
||||
class UI {
|
||||
void draw();
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif // COIL_UI_H
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
double round_to_presicion( double value, int precision ) {
|
||||
float round_to_precision( float value, int precision ) {
|
||||
const int adjustment = pow(10,precision);
|
||||
return floor( value*(adjustment) + 0.5 )/adjustment;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ void gracefulExit(int code) {
|
||||
exit(code);
|
||||
}
|
||||
|
||||
unsigned int prepareShaders() {
|
||||
uint64_t prepareShaders() {
|
||||
unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||
unsigned int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
double round_to_presicion( double value, int precision );
|
||||
float round_to_precision( float value, int precision );
|
||||
|
||||
std::string readFile(std::string path);
|
||||
|
||||
void gracefulExit(int code);
|
||||
|
||||
unsigned int prepareShaders();
|
||||
uint64_t prepareShaders();
|
||||
Reference in New Issue
Block a user