added rounded rectangle, first iteration works but still needs improved corners
This commit is contained in:
@@ -47,7 +47,7 @@ void Plane::create_impl(float w, float h, int div, GLushort *idx, Shape::vertex_
|
||||
{
|
||||
count[0] = div * div * 6;
|
||||
count[1] = 8;
|
||||
ioff[0] = (GLvoid*)(8 * sizeof(GLushort));
|
||||
ioff[0] = (GLvoid*)(count[1] * sizeof(GLushort));
|
||||
ioff[1] = (GLvoid*)0;
|
||||
|
||||
const float dx = w / div;
|
||||
@@ -98,7 +98,7 @@ void Circle::create_impl(float radius, int div, GLushort* idx, Shape::vertex_t*
|
||||
count[0] = div * 3;
|
||||
count[1] = div * 2;
|
||||
ioff[0] = (GLvoid*)0;
|
||||
ioff[1] = (GLvoid*)(div * 3 * sizeof(GLushort));
|
||||
ioff[1] = (GLvoid*)(count[0] * sizeof(GLushort));
|
||||
|
||||
auto pidx = idx;
|
||||
auto pidx2 = idx + div * 3;
|
||||
@@ -127,7 +127,7 @@ void Circle::create_impl(float radius_out, float radius_in, int div, GLushort* i
|
||||
count[0] = div * 6;
|
||||
count[1] = div * 4;
|
||||
ioff[0] = (GLvoid*)0;
|
||||
ioff[1] = (GLvoid*)(div * 6 * sizeof(GLushort));
|
||||
ioff[1] = (GLvoid*)(count[0] * sizeof(GLushort));
|
||||
|
||||
auto pidx = idx;
|
||||
auto pidx2 = idx + div * 6;
|
||||
@@ -155,3 +155,72 @@ void Circle::create_impl(float radius_out, float radius_in, int div, GLushort* i
|
||||
*pidx2++ = ((i+1)*2+1) % (div*2);// C
|
||||
}
|
||||
}
|
||||
|
||||
void Rounded::create_impl(float w, float h, float r, int div, GLushort* idx, GLushort* idx_tmp, Shape::vertex_t* vertices)
|
||||
{
|
||||
count[0] = (10 + div * 4) * 3;
|
||||
count[1] = (4 + div * 4) * 2;
|
||||
ioff[0] = (GLvoid*)0;
|
||||
ioff[1] = (GLvoid*)(count[0] * sizeof(GLushort));
|
||||
|
||||
float X[] = { -w/2, -w/2+r, w/2-r, w/2 };
|
||||
float Y[] = { -h/2, -h/2+r, h/2-r, h/2 };
|
||||
|
||||
auto V = [&](int x, int y) -> Shape::vertex_t {
|
||||
return { glm::vec4(X[x], Y[y], 0, 1), glm::vec2(X[x]/w, Y[y]/h) + 0.5f };
|
||||
};
|
||||
*vertices++ = V(1,0);
|
||||
*vertices++ = V(2,0);
|
||||
|
||||
*vertices++ = V(0,1);
|
||||
*vertices++ = V(1,1);
|
||||
*vertices++ = V(2,1);
|
||||
*vertices++ = V(3,1);
|
||||
|
||||
*vertices++ = V(0,2);
|
||||
*vertices++ = V(1,2);
|
||||
*vertices++ = V(2,2);
|
||||
*vertices++ = V(3,2);
|
||||
|
||||
*vertices++ = V(1,3);
|
||||
*vertices++ = V(2,3);
|
||||
|
||||
auto Q = [&](int a, int b, int c, int d) {
|
||||
*idx++ = a;
|
||||
*idx++ = b;
|
||||
*idx++ = c;
|
||||
*idx++ = a;
|
||||
*idx++ = c;
|
||||
*idx++ = d;
|
||||
};
|
||||
Q(0, 3, 4, 1);
|
||||
Q(2, 6, 7, 3);
|
||||
Q(3, 7, 8, 4);
|
||||
Q(4, 8, 9, 5);
|
||||
Q(7,10,11, 8);
|
||||
|
||||
auto corner = [&](int c, int a, int b, int n) {
|
||||
idx_tmp[0] = a;
|
||||
idx_tmp[div] = b;
|
||||
auto v = vertices-12;
|
||||
for (int i = 1; i < div; i++)
|
||||
{
|
||||
float t = (float)(i) / div;
|
||||
auto p = glm::normalize(glm::mix(v[a].pos.xyz(), v[b].pos.xyz(), t));
|
||||
v[n].pos = glm::vec4(p * r + v[c].pos.xyz(), 1);
|
||||
v[n].uvs = glm::normalize(glm::mix(v[a].uvs, v[b].uvs, t)) * glm::vec2(r/w, r/h) + v[c].uvs;
|
||||
idx_tmp[i] = n;
|
||||
n++;
|
||||
}
|
||||
for (int i = 0; i < div; i++)
|
||||
{
|
||||
*idx++ = c;
|
||||
*idx++ = idx_tmp[i];
|
||||
*idx++ = idx_tmp[i+1];
|
||||
}
|
||||
};
|
||||
corner(3, 0, 2, 12 + (div-1)*0);
|
||||
corner(7, 6,10, 12 + (div-1)*1);
|
||||
corner(8,11, 9, 12 + (div-1)*2);
|
||||
corner(4, 5, 1, 12 + (div-1)*3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user