|
|
|
|
@@ -1,28 +1,29 @@
|
|
|
|
|
#include <cassert>
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <winnt.h>
|
|
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <glm/ext/vector_float2.hpp>
|
|
|
|
|
#include <glm/ext/vector_float4.hpp>
|
|
|
|
|
#include <profileapi.h>
|
|
|
|
|
#include <synchapi.h>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <glad/glad.h>
|
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
|
#include <glm/ext/matrix_clip_space.hpp>
|
|
|
|
|
#include <glm/ext/matrix_transform.hpp>
|
|
|
|
|
#include <glm/ext/vector_float3.hpp>
|
|
|
|
|
#include <glm/matrix.hpp>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <winnt.h>
|
|
|
|
|
|
|
|
|
|
#include "glm/gtc/type_ptr.hpp"
|
|
|
|
|
#include "sync.hpp"
|
|
|
|
|
#include "util.hpp"
|
|
|
|
|
#include "shaders.hpp"
|
|
|
|
|
#include "body.hpp"
|
|
|
|
|
#include "camera.hpp"
|
|
|
|
|
#include "live_plotter.hpp"
|
|
|
|
|
#include "gldebug.hpp"
|
|
|
|
|
|
|
|
|
|
using namespace sync;
|
|
|
|
|
|
|
|
|
|
@@ -69,6 +70,7 @@ bool _glfw_setup();
|
|
|
|
|
void _refresh_win();
|
|
|
|
|
double _time();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern DllExport bool __cdecl start(int win_w, int win_h) {
|
|
|
|
|
if (running) {
|
|
|
|
|
printf("Already running! Call stop before calling stop again\n");
|
|
|
|
|
@@ -112,7 +114,8 @@ extern DllExport bool __cdecl stop() {
|
|
|
|
|
extern DllExport pointid __cdecl create_point(float x, float y, float z) {
|
|
|
|
|
lock(m);
|
|
|
|
|
|
|
|
|
|
// This is stupid. Please fix
|
|
|
|
|
// TODO: This system is really stupid. Please fix
|
|
|
|
|
// Also what happens if there isn't a replaceable point?
|
|
|
|
|
int slot = -1;
|
|
|
|
|
int start_loc = point_buf_i;
|
|
|
|
|
do {
|
|
|
|
|
@@ -125,7 +128,7 @@ extern DllExport pointid __cdecl create_point(float x, float y, float z) {
|
|
|
|
|
|
|
|
|
|
assert(slot > -1);
|
|
|
|
|
|
|
|
|
|
point_buf[slot] = {
|
|
|
|
|
point_buf[slot] = {
|
|
|
|
|
.initialized = false,
|
|
|
|
|
.replaceable = false,
|
|
|
|
|
.startloc = glm::vec3(x, y, z),
|
|
|
|
|
@@ -206,8 +209,8 @@ void _scroll_cb(GLFWwindow* win, double xoffset, double yoffset) { zoom_camera(c
|
|
|
|
|
DWORD _win_thread(LPVOID args) {
|
|
|
|
|
glm::vec2* winsize = (glm::vec2*)args;
|
|
|
|
|
camera = make_camera({ 0, 0, 0 }, 10);
|
|
|
|
|
camera.theta = glm::radians(90.0f);
|
|
|
|
|
camera.phi = glm::radians(30.0f);
|
|
|
|
|
camera.theta = glm::radians(0.0f);
|
|
|
|
|
camera.phi = glm::radians(0.0f);
|
|
|
|
|
viewport = make_viewport(winsize->x, winsize->y, 45.0f);
|
|
|
|
|
if (!_glfw_setup()) {
|
|
|
|
|
printf("Failed to initialize glfw window\n");
|
|
|
|
|
@@ -219,6 +222,17 @@ DWORD _win_thread(LPVOID args) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("Open GL Vendor: %s\n", glGetString(GL_VENDOR));
|
|
|
|
|
printf("Open GL Renderer: %s\n", glGetString(GL_RENDERER));
|
|
|
|
|
printf("Open GL Version: %s\n", glGetString(GL_VERSION));
|
|
|
|
|
printf("Open GL Shader Language Version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
|
|
|
|
|
|
|
|
|
|
// Enable debug messages
|
|
|
|
|
glEnable(GL_DEBUG_OUTPUT);
|
|
|
|
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
|
|
|
|
glDebugMessageCallback(gl_debug_cb, 0);
|
|
|
|
|
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
|
|
|
|
|
|
|
|
|
|
if (!load_shader(&shader, vertex_filepath, fragment_filepath)) {
|
|
|
|
|
printf("Failed to compile shaders\n");
|
|
|
|
|
return -1;
|
|
|
|
|
@@ -243,9 +257,11 @@ DWORD _win_thread(LPVOID args) {
|
|
|
|
|
|
|
|
|
|
bool _glfw_setup() {
|
|
|
|
|
glfwInit();
|
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
|
|
|
|
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
|
|
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
|
|
|
|
|
|
win = glfwCreateWindow(viewport.width, viewport.height, "LivePlotter", NULL, NULL);
|
|
|
|
|
if (win == NULL) {
|
|
|
|
|
printf("Failed to create GLFW window\n");
|
|
|
|
|
@@ -258,6 +274,7 @@ bool _glfw_setup() {
|
|
|
|
|
glfwSetMouseButtonCallback(win, _mouse_button_cb);
|
|
|
|
|
glfwSetScrollCallback(win, _scroll_cb);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_cursor_pos_cb(win, 0, 0);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
@@ -267,6 +284,11 @@ void _refresh_win() {
|
|
|
|
|
set_uniform(shader, "camera_t", world_to_camera(camera));
|
|
|
|
|
set_uniform(shader, "projection_t", camera_to_projection(viewport));
|
|
|
|
|
|
|
|
|
|
/*glm::mat4 cam = world_to_camera(camera);
|
|
|
|
|
glm::mat4 view = camera_to_projection(viewport);
|
|
|
|
|
glUniformMatrix4fv(glGetUniformLocation(shader, "camera_t"), 1, GL_FALSE, glm::value_ptr(cam));
|
|
|
|
|
glUniformMatrix4fv(glGetUniformLocation(shader, "projection_t"), 1, GL_FALSE, glm::value_ptr(view));*/
|
|
|
|
|
|
|
|
|
|
if (trylock(m)) {
|
|
|
|
|
for (int i = 0; i < point_buf_len; i++) {
|
|
|
|
|
Point &p = point_buf[i];
|