Compare commits
8 Commits
dd3ee57fcb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| fef2ce8f2b | |||
| 2215208c46 | |||
| ef2a366e8e | |||
| 8b84258c1a | |||
| 5ae1c82ef6 | |||
| fc51065d85 | |||
| 1e11e66d16 | |||
| 701ff99000 |
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.
7
.vscode/launch.json
vendored
7
.vscode/launch.json
vendored
@@ -1,16 +1,13 @@
|
||||
{
|
||||
// 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>",
|
||||
"program": "${workspaceFolder}/build/TimeCoil",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
"cwd": "${workspaceFolder}/build"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -8,6 +8,7 @@ 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
|
||||
@@ -19,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
|
||||
|
||||
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,32 +1,28 @@
|
||||
#include <cstdint>
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <coil/coil.hpp>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#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, uint32_t sliceDetalization, float radius, float width)
|
||||
: radius(radius), width(width), 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, sliceDetalization,false));
|
||||
segments.push_back(CoilSegment(this, year, segmentHeight, i, sliceDetalization));
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<CoilSegment> &Coil::getSegments() {
|
||||
return segments;
|
||||
}
|
||||
std::vector<CoilSegment> &Coil::getSegments() { return segments; }
|
||||
|
||||
float Coil::getWidth() {
|
||||
return width;
|
||||
}
|
||||
float Coil::getWidth() { return width; }
|
||||
|
||||
float Coil::getRadius() {
|
||||
return radius;
|
||||
}
|
||||
float Coil::getRadius() { return radius; }
|
||||
|
||||
void Coil::initGLBuffers() {
|
||||
|
||||
@@ -39,12 +35,11 @@ void Coil::initGLBuffers() {
|
||||
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);
|
||||
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)));
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float),
|
||||
(void *)(3 * sizeof(float)));
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
glBindVertexArray(0);
|
||||
@@ -52,15 +47,96 @@ void Coil::initGLBuffers() {
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
@@ -5,8 +5,9 @@
|
||||
#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
|
||||
@@ -20,11 +21,14 @@ class Coil {
|
||||
GLuint VBO, VAO, EBO;
|
||||
|
||||
public:
|
||||
Coil(uint32_t currentYear, uint32_t amountOfSegments, uint32_t sliceDetalization, float radius, float width);
|
||||
Coil(uint32_t currentYear, uint32_t amountOfSegments, float segmentHeight, uint32_t sliceDetalization, float radius, float width);
|
||||
std::vector<CoilSegment> &getSegments();
|
||||
float getWidth();
|
||||
float getRadius();
|
||||
|
||||
void render();
|
||||
void fillVBO(float *vertices);
|
||||
uint32_t fillEBO();
|
||||
void initGLBuffers();
|
||||
};
|
||||
|
||||
|
||||
@@ -12,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;
|
||||
@@ -34,33 +30,30 @@ CoilSegment::CoilSegment(
|
||||
uint16_t year,
|
||||
uint16_t height,
|
||||
int shift,
|
||||
uint32_t sliceDetalization,
|
||||
bool isLeap
|
||||
) :
|
||||
uint32_t sliceDetailization
|
||||
):
|
||||
coil(coil), year(year),
|
||||
height(height), shift(shift),
|
||||
sliceDetalization(sliceDetalization), isLeap(isLeap) {
|
||||
sliceDetailization(sliceDetailization),
|
||||
slicePointsAmount(sliceDetailization + 2),
|
||||
//evil shit
|
||||
leap(year % 4 == 0? year % 100 == 0? year % 400 == 0 : true : false) {
|
||||
init();
|
||||
calculate();
|
||||
// calculate();
|
||||
}
|
||||
|
||||
void CoilSegment::init () {
|
||||
verticesLength = DAYS_IN_YEAR * FIELDS_IN_POINT * (sliceDetalization+2);
|
||||
vertices = (float *) calloc(verticesLength, sizeof(float));
|
||||
verticesLength = getDaysAmount() * slicePointsAmount * FIELDS_IN_POINT;
|
||||
vertices = (float *) malloc(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 ++) {
|
||||
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] << ", " <<
|
||||
@@ -73,59 +66,41 @@ void CoilSegment::printVertices() {
|
||||
|
||||
|
||||
float *CoilSegment::calculateSlice() {
|
||||
uint32_t size = (/*start and end of a slize*/2 + sliceDetalization) * FIELDS_IN_POINT * sizeof(float);
|
||||
uint32_t size = slicePointsAmount * 3 * 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);
|
||||
float degreeByPoint = 180. / (sliceDetailization + 1);
|
||||
|
||||
for (uint32_t i = 1; i <= sliceDetalization; i ++) {
|
||||
uint32_t offset = FIELDS_IN_POINT * i;
|
||||
for (uint32_t i = 1; i <= sliceDetailization; i ++) {
|
||||
uint32_t offset = 3 * 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 + 0] = round_to_precision(cos(radians(degreeByPoint * i)), 5);
|
||||
slice[offset + 1] = round_to_precision(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);
|
||||
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;
|
||||
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;
|
||||
float degreesPerDay = 360.f / getDaysAmount();
|
||||
|
||||
for (uint32_t day = 0; day < DAYS_IN_YEAR; day ++) {
|
||||
for (uint32_t day = 0; day < getDaysAmount(); day ++) {
|
||||
float daysDegree = day * degreesPerDay;
|
||||
vec3 daysPosition = vec3(
|
||||
cos(radians(daysDegree)) * coil->getRadius(),
|
||||
10* daysDegree/360.,
|
||||
height * daysDegree/360. + shift * height,
|
||||
sin(radians(daysDegree)) * coil->getRadius()
|
||||
);
|
||||
|
||||
@@ -146,8 +121,8 @@ void CoilSegment::constructSegment(float *slice) {
|
||||
)
|
||||
);
|
||||
|
||||
for (uint32_t slicePoint = 0; slicePoint < (2 + sliceDetalization); slicePoint ++) {
|
||||
uint32_t slicePointOffset = FIELDS_IN_POINT * slicePoint;
|
||||
for (uint32_t slicePoint = 0; slicePoint < slicePointsAmount; slicePoint ++) {
|
||||
uint32_t slicePointOffset = 3 * slicePoint;
|
||||
vec4 point(
|
||||
slice[slicePointOffset + 0],
|
||||
slice[slicePointOffset + 1],
|
||||
@@ -156,83 +131,18 @@ void CoilSegment::constructSegment(float *slice) {
|
||||
);
|
||||
|
||||
point = transform * point;
|
||||
uint64_t currentPointOffset = day * (2+sliceDetalization) * FIELDS_IN_POINT + slicePointOffset;
|
||||
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;
|
||||
|
||||
vertices[currentPointOffset + 3] = 0.5;
|
||||
vertices[currentPointOffset + 4] = 0.5;
|
||||
vertices[currentPointOffset + 5] = 0.5;
|
||||
|
||||
// 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);
|
||||
}
|
||||
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
|
||||
@@ -243,26 +153,23 @@ void CoilSegment::calculate() {
|
||||
float *slice = calculateSlice();
|
||||
|
||||
constructSegment(slice);
|
||||
exportSegmentToCsv();
|
||||
|
||||
}
|
||||
|
||||
float *CoilSegment::getVertices() { return vertices; }
|
||||
|
||||
uint64_t CoilSegment::getVerticesLength() { return verticesLength; }
|
||||
|
||||
uint64_t CoilSegment::getVerticesAmount() { return verticesLength / FIELDS_IN_POINT; }
|
||||
|
||||
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 ++) {
|
||||
for (uint32_t i = 0; i < slicePointsAmount; i ++) {
|
||||
uint32_t offset = FIELDS_IN_POINT * i;
|
||||
outFile
|
||||
<< slice[offset + 0] << ","
|
||||
@@ -276,10 +183,10 @@ void CoilSegment::exportSegmentToCsv() {
|
||||
|
||||
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 (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 < (2+sliceDetalization); point_in_slice ++) {
|
||||
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] << ","
|
||||
@@ -287,3 +194,11 @@ void CoilSegment::exportSegmentToCsv() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,8 +14,9 @@ class CoilSegment {
|
||||
uint16_t height;
|
||||
// Number of a segments, counting from the central (which is 0)
|
||||
int shift;
|
||||
uint32_t sliceDetalization;
|
||||
bool isLeap;
|
||||
uint32_t sliceDetailization;
|
||||
uint32_t slicePointsAmount;
|
||||
bool leap;
|
||||
float *vertices;
|
||||
uint64_t verticesLength;
|
||||
|
||||
@@ -21,18 +25,21 @@ class CoilSegment {
|
||||
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();
|
||||
float *getVertices();
|
||||
uint64_t getVerticesLength();
|
||||
uint64_t getVerticesAmount();
|
||||
void printSlice(float *slice);
|
||||
void exportSliceToCSV(float *slice);
|
||||
void exportSegmentToCsv();
|
||||
void render();
|
||||
void fillVBO();
|
||||
uint64_t fillEBO(uint64_t EBO);
|
||||
uint16_t getYear();
|
||||
|
||||
uint16_t getDaysAmount();
|
||||
bool const isLeap();
|
||||
uint32_t getSliceDetailization();
|
||||
uint32_t getSlicePointsAmount();
|
||||
};
|
||||
|
||||
#endif // COIL_SEGMENT_HPP
|
||||
192
src/main.cpp
192
src/main.cpp
@@ -1,7 +1,6 @@
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
@@ -12,6 +11,7 @@
|
||||
#include <coil/coil.hpp>
|
||||
#include <coil/segment.hpp>
|
||||
#include <utils/utils.hpp>
|
||||
#include <camera/camera.hpp>
|
||||
|
||||
using std::cerr;
|
||||
using std::cout;
|
||||
@@ -25,16 +25,48 @@ 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);
|
||||
float coilRadius = 100;
|
||||
float coilWidth = 10;
|
||||
float segmentHeight = 10;
|
||||
|
||||
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, 5, 50, 10);
|
||||
Coil coil = Coil(2024, 500, segmentHeight, 8, coilRadius, coilWidth);
|
||||
|
||||
srand(time(0));
|
||||
glfwInit();
|
||||
@@ -53,6 +85,9 @@ int main () {
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSetFramebufferSizeCallback(window, framebufferSizeCallback);
|
||||
glfwSetCursorPosCallback(window, processMousePosCallback);
|
||||
glfwSetKeyCallback(window, processClickInput);
|
||||
// glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||
cerr << "Failed to initialize GLAD." << endl;
|
||||
@@ -68,159 +103,30 @@ int main () {
|
||||
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);
|
||||
|
||||
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
coil.initGLBuffers();
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
while(!glfwWindowShouldClose(window)) {
|
||||
processInput(window);
|
||||
processPressInput(window);
|
||||
|
||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
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(5.0f), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
view = glm::translate(view, glm::vec3(0.0f, 0.0f, -89.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));
|
||||
|
||||
c.render();
|
||||
// glBindVertexArray(VAO);
|
||||
// glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||
coil.render();
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
// CoilSegment cs = CoilSegment(10, 0, false);
|
||||
// for (auto segment : c.getSegments()) {
|
||||
// // segment.printVertices();
|
||||
// }
|
||||
// cs.printVertices();
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
float round_to_presicion( float value, int precision ) {
|
||||
float round_to_precision( float value, int precision ) {
|
||||
const int adjustment = pow(10,precision);
|
||||
return floor( value*(adjustment) + 0.5 )/adjustment;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
|
||||
float round_to_presicion( float value, int precision );
|
||||
float round_to_precision( float value, int precision );
|
||||
|
||||
std::string readFile(std::string path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user