-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDrawingUtils.cpp
More file actions
42 lines (36 loc) · 1.57 KB
/
DrawingUtils.cpp
File metadata and controls
42 lines (36 loc) · 1.57 KB
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
39
40
41
42
#include "DrawingUtils.h"
#include "Drawing.h"
#include "OpenGLUtils.h"
#include <iostream>
#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
void handleCursorMovement(GLFWwindow* window, double& prevXpos, double& prevYpos, std::vector<std::vector<float>>& circles, GLuint VBO, GLuint VAO, float radius, int sides) {
double xpos, ypos;
glfwGetCursorPos(window, &xpos, &ypos);
int width, height;
glfwGetFramebufferSize(window, &width, &height);
float x1 = static_cast<float>(prevXpos) / width * 2.0f - 1.0f;
float y1 = -static_cast<float>(prevYpos) / height * 2.0f + 1.0f;
float x2 = static_cast<float>(xpos) / width * 2.0f - 1.0f;
float y2 = -static_cast<float>(ypos) / height * 2.0f + 1.0f;
std::vector<float> currentCircle = DrawingCircle::drawCircle(x2, y2, radius, sides);
updateVertexBuffer(VBO, currentCircle);
drawCircle(VAO, VBO, currentCircle, GL_TRIANGLE_FAN);
if (ImGui::IsAnyItemHovered())
{
return;
}
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS) {
int num_samples = std::max(static_cast<int>(sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) / radius), 1);
for (int i = 0; i <= num_samples; ++i) {
float t = static_cast<float>(i) / num_samples;
float vx = x1 * (1 - t) + x2 * t;
float vy = y1 * (1 - t) + y2 * t;
std::vector<float> currentCircle = DrawingCircle::drawCircle(vx, vy, radius, sides);
circles.push_back(currentCircle);
}
}
prevXpos = xpos;
prevYpos = ypos;
}