27 #include "eng3d/curve.hpp"
28 #include "eng3d/shader.hpp"
29 #include "eng3d/primitive.hpp"
32 #include <glm/vec2.hpp>
33 #include <glm/mat4x4.hpp>
37 this->create_line(points, normals, width);
42 this->create_line(points, normals, width);
47 this->quads = std::make_unique<Eng3D::TriangleList>(positions, tex_coords);
50 void Eng3D::Curve::add_quad(glm::vec3 c1, glm::vec3 c2, glm::vec3 c3, glm::vec3 c4) {
51 positions.reserve(positions.size() + 6);
52 tex_coords.reserve(tex_coords.size() + 6);
53 positions.push_back(c1);
54 tex_coords.push_back(glm::vec2(0.f, 0.f));
55 positions.push_back(c2);
56 tex_coords.push_back(glm::vec2(0.f, 1.f));
57 positions.push_back(c3);
58 tex_coords.push_back(glm::vec2(1.f, 1.f));
59 positions.push_back(c3);
60 tex_coords.push_back(glm::vec2(1.f, 1.f));
61 positions.push_back(c4);
62 tex_coords.push_back(glm::vec2(1.f, 0.f));
63 positions.push_back(c1);
64 tex_coords.push_back(glm::vec2(0.f, 0.f));
67 void Eng3D::Curve::create_line(
const std::vector<glm::vec3>& points,
const std::vector<glm::vec3>& normals,
float width) {
68 glm::vec3 prev_c1, prev_c2, prev_c3, prev_c4;
69 for(
size_t i = 0; i < points.size() - 1; i++) {
71 auto p2 = points[i + 1];
72 auto normal = normals[i];
75 glm::vec3 p1t2 = p2 - p1;
77 glm::vec3 ortho = glm::cross(p1t2, normal);
79 ortho = glm::normalize(ortho);
81 glm::vec3 c1 = p1 - ortho * width * 0.5f;
82 glm::vec3 c2 = p1 + ortho * width * 0.5f;
84 c1 = glm::mix(c1, prev_c3, .5f);
85 c2 = glm::mix(c2, prev_c4, .5f);
88 this->add_quad(prev_c1, prev_c2, prev_c4, prev_c3);
90 glm::vec3 c3 = p2 - ortho * width * 0.5f;
91 glm::vec3 c4 = p2 + ortho * width * 0.5f;
97 this->add_quad(prev_c1, prev_c2, prev_c4, prev_c3);
100 #if defined(E3D_BACKEND_OPENGL) || defined(E3D_BACKEND_GLES)
102 if(this->quads.get() ==
nullptr)
106 #elif defined E3D_BACKEND_RGX
void upload(const Eng3D::OpenGL::VAO &vao, const Eng3D::OpenGL::VBO &vbo, const Eng3D::OpenGL::EBO &ebo, const void *buffer, size_t n_buffer, size_t sz_buffer, size_t sz_buffer_vert, size_t sz_buffer_tex, size_t v_len, size_t t_len, size_t c_len, const void *indices, size_t n_indices, size_t sz_indices, bool has_color)
void draw(const Eng3D::OpenGL::VAO &vao, MeshMode mode, const void *indices, size_t n_indices, const void *buffer, size_t n_buffer, int instances)
void add_line(std::vector< glm::vec3 > points, std::vector< glm::vec3 > normals, float width)