add Slice9 type
This commit is contained in:
@@ -47,8 +47,8 @@ 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*)(count[1] * sizeof(GLushort));
|
||||
ioff[1] = (GLvoid*)0;
|
||||
ioff[0] = (GLvoid*)0;
|
||||
ioff[1] = (GLvoid*)(count[0] * sizeof(GLushort));
|
||||
|
||||
const float dx = w / div;
|
||||
const float dy = h / div;
|
||||
@@ -69,14 +69,6 @@ void Plane::create_impl(float w, float h, int div, GLushort *idx, Shape::vertex_
|
||||
}
|
||||
|
||||
// generate indices
|
||||
*idx++ = 0; // A
|
||||
*idx++ = (div+1)*(div); // B
|
||||
*idx++ = (div+1)*(div); // B
|
||||
*idx++ = (div+1)*(div+1)-1; // C
|
||||
*idx++ = (div+1)*(div+1)-1; // C
|
||||
*idx++ = div; // D
|
||||
*idx++ = div; // D
|
||||
*idx++ = 0; // A
|
||||
for (int y = 0; y < div; y++)
|
||||
{
|
||||
int i = y * (div+1);
|
||||
@@ -91,6 +83,15 @@ void Plane::create_impl(float w, float h, int div, GLushort *idx, Shape::vertex_
|
||||
i++;
|
||||
}
|
||||
}
|
||||
// outline indices
|
||||
*idx++ = 0; // A
|
||||
*idx++ = (div+1)*(div); // B
|
||||
*idx++ = (div+1)*(div); // B
|
||||
*idx++ = (div+1)*(div+1)-1; // C
|
||||
*idx++ = (div+1)*(div+1)-1; // C
|
||||
*idx++ = div; // D
|
||||
*idx++ = div; // D
|
||||
*idx++ = 0; // A
|
||||
}
|
||||
|
||||
void Circle::create_impl(float radius, int div, GLushort* idx, Shape::vertex_t* vertices)
|
||||
@@ -101,7 +102,7 @@ void Circle::create_impl(float radius, int div, GLushort* idx, Shape::vertex_t*
|
||||
ioff[1] = (GLvoid*)(count[0] * sizeof(GLushort));
|
||||
|
||||
auto pidx = idx;
|
||||
auto pidx2 = idx + div * 3;
|
||||
auto pidx2 = idx + count[0];
|
||||
for (int i = 0; i < div; i++)
|
||||
{
|
||||
vertex_t v;
|
||||
@@ -130,7 +131,7 @@ void Circle::create_impl(float radius_out, float radius_in, int div, GLushort* i
|
||||
ioff[1] = (GLvoid*)(count[0] * sizeof(GLushort));
|
||||
|
||||
auto pidx = idx;
|
||||
auto pidx2 = idx + div * 6;
|
||||
auto pidx2 = idx + count[0];
|
||||
for (int i = 0; i < div; i++)
|
||||
{
|
||||
float theta = (float)i / div * M_PI * 2.f;
|
||||
@@ -163,6 +164,8 @@ void Rounded::create_impl(float w, float h, float r, int div, GLushort* idx, GLu
|
||||
ioff[0] = (GLvoid*)0;
|
||||
ioff[1] = (GLvoid*)(count[0] * sizeof(GLushort));
|
||||
|
||||
auto idx2 = idx + count[0];
|
||||
|
||||
float X[] = { -w/2, -w/2+r, w/2-r, w/2 };
|
||||
float Y[] = { -h/2, -h/2+r, h/2-r, h/2 };
|
||||
|
||||
@@ -200,27 +203,79 @@ void Rounded::create_impl(float w, float h, float r, int div, GLushort* idx, GLu
|
||||
Q(7,10,11, 8);
|
||||
|
||||
auto corner = [&](int c, int a, int b, int n) {
|
||||
auto v = vertices-12;
|
||||
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));
|
||||
auto p = glm::normalize(glm::mix(v[a].pos.xyz()-v[c].pos.xyz(), v[b].pos.xyz()-v[c].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;
|
||||
v[n].uvs = glm::normalize(glm::mix(v[a].uvs-v[c].uvs, v[b].uvs-v[c].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];
|
||||
*idx++ = *idx2++ = idx_tmp[i];
|
||||
*idx++ = *idx2++ = 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);
|
||||
|
||||
*idx2++ = 0;
|
||||
*idx2++ = 1;
|
||||
*idx2++ = 5;
|
||||
*idx2++ = 9;
|
||||
*idx2++ = 11;
|
||||
*idx2++ = 10;
|
||||
*idx2++ = 6;
|
||||
*idx2++ = 2;
|
||||
}
|
||||
|
||||
void Slice9::create_impl(float w, float h, float r, GLushort *idx, Shape::vertex_t *vertices)
|
||||
{
|
||||
count[0] = 3 * 3 * 6;
|
||||
count[1] = 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 };
|
||||
};
|
||||
|
||||
for (int y = 0; y < 4; y++)
|
||||
for (int x = 0; x < 4; x++)
|
||||
*vertices++ = V(x,y);
|
||||
|
||||
for (int y = 0; y < 3; y++)
|
||||
{
|
||||
int i = y * (3+1);
|
||||
for (int x = 0; x < 3; x++)
|
||||
{
|
||||
*idx++ = i;
|
||||
*idx++ = i + 3 + 1;
|
||||
*idx++ = i + 3 + 2;
|
||||
*idx++ = i;
|
||||
*idx++ = i + 3 + 2;
|
||||
*idx++ = i + 1;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
// outline indices
|
||||
*idx++ = 0; // A
|
||||
*idx++ = 3; // B
|
||||
*idx++ = 3; // B
|
||||
*idx++ = 15; // C
|
||||
*idx++ = 15; // C
|
||||
*idx++ = 12; // D
|
||||
*idx++ = 12; // D
|
||||
*idx++ = 0; // A
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user