fix brush projection to eliminate seams, still problems with big brushes and need to implement erase

This commit is contained in:
2017-08-13 16:59:58 +01:00
parent 060e08a891
commit 90ee185dcd
7 changed files with 123 additions and 90 deletions

View File

@@ -212,10 +212,25 @@ void Plane::create_impl(float w, float h, int div, GLushort *idx, Shape::vertex_
void ui::Plane::update_vertices(const glm::vec4* data)
{
static vertex_t vertices[4];
glm::vec2 mid;
segments_intersect(data[0].xy, data[2].xy, data[1].xy, data[3].xy, mid);
static float d[4];
for (int i = 0; i < 4; i++)
d[i] = glm::distance(data[i].xy(), mid);
vertices[0] = { data[0],{ 0, 0 } }; // A
vertices[1] = { data[1],{ 0, 1 } }; // B
vertices[2] = { data[2],{ 1, 1 } }; // C
vertices[3] = { data[3],{ 1, 0 } }; // D
for (int i = 0; i < 4; i++)
{
float q = (d[i] + d[(i + 2) % 4]) / d[(i + 2) % 4];
vertices[i].uvs *= q;
vertices[i].pos.z = q;
}
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
static GLushort idx[6 + 8]{
@@ -457,4 +472,4 @@ void ui::DynamicShape::update_vertices(vertex_t* vertices, int vcount)
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_t) * vcount, vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
}