fix some shapes generation and draw a grid of shapes for an overview
This commit is contained in:
@@ -46,15 +46,14 @@ void Shape::draw_stroke() const
|
||||
void Plane::create_impl(float w, float h, int div, GLushort *idx, Shape::vertex_t *vertices)
|
||||
{
|
||||
count[0] = div * div * 6;
|
||||
count[1] = 4;
|
||||
ioff[0] = (GLvoid*)4;
|
||||
count[1] = 8;
|
||||
ioff[0] = (GLvoid*)(8 * sizeof(GLushort));
|
||||
ioff[1] = (GLvoid*)0;
|
||||
|
||||
const float dx = w / div;
|
||||
const float dy = h / div;
|
||||
const float ox = -w * 0.5f;
|
||||
const float oy = -h * 0.5f;
|
||||
int v_index = 0;
|
||||
for (int y = 0; y <= div; y++)
|
||||
{
|
||||
for (int x = 0; x <= div; x++)
|
||||
@@ -65,27 +64,30 @@ void Plane::create_impl(float w, float h, int div, GLushort *idx, Shape::vertex_
|
||||
v.pos.z = 0;
|
||||
v.pos.w = 1;
|
||||
v.uvs = glm::vec2(x, y) / (float)div;
|
||||
vertices[v_index++] = v;
|
||||
*vertices++ = v;
|
||||
}
|
||||
}
|
||||
|
||||
// generate indices
|
||||
auto pidx = idx;
|
||||
*pidx++ = 0;
|
||||
*pidx++ = div;
|
||||
*pidx++ = (div+1)*(div);
|
||||
*pidx++ = (div+1)*(div+1)-1;
|
||||
*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);
|
||||
for (int x = 0; x < div; x++)
|
||||
{
|
||||
*pidx++ = i;
|
||||
*pidx++ = i + div + 1;
|
||||
*pidx++ = i + div + 2;
|
||||
*pidx++ = i;
|
||||
*pidx++ = i + div + 2;
|
||||
*pidx++ = i + 1;
|
||||
*idx++ = i;
|
||||
*idx++ = i + div + 1;
|
||||
*idx++ = i + div + 2;
|
||||
*idx++ = i;
|
||||
*idx++ = i + div + 2;
|
||||
*idx++ = i + 1;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@@ -104,11 +106,9 @@ void Circle::create_impl(float radius, int div, GLushort* idx, Shape::vertex_t*
|
||||
{
|
||||
vertex_t v;
|
||||
float theta = (float)i / div * M_PI * 2.f;
|
||||
v.pos.x = sinf(theta) * radius;
|
||||
v.pos.y = cosf(theta) * radius;
|
||||
v.pos.z = 0;
|
||||
v.pos.w = 1;
|
||||
v.uvs = v.pos.xy() * 0.5f + 0.5f;
|
||||
glm::vec2 uv = { sinf(theta), cosf(theta) };
|
||||
v.pos = glm::vec4(uv * radius, 0, 1);
|
||||
v.uvs = uv * 0.5f + 0.5f;
|
||||
vertices[i+1] = v;
|
||||
|
||||
*pidx++ = 0;
|
||||
@@ -134,10 +134,11 @@ void Circle::create_impl(float radius_out, float radius_in, int div, GLushort* i
|
||||
for (int i = 0; i < div; i++)
|
||||
{
|
||||
float theta = (float)i / div * M_PI * 2.f;
|
||||
vertices[i*2].pos = { sinf(theta) * radius_in, cosf(theta) * radius_in, 0, 1 };
|
||||
vertices[i*2].uvs = vertices[i*2].pos.xy() * 0.5f + 0.5f;
|
||||
vertices[i*2+1].pos = { sinf(theta) * radius_out, cosf(theta) * radius_out, 0, 1 };
|
||||
vertices[i*2+1].uvs = vertices[i*2+1].pos.xy() * 0.5f + 0.5f;
|
||||
glm::vec2 uv = { sinf(theta), cosf(theta) };
|
||||
vertices[i*2].pos = glm::vec4(uv * radius_in, 0, 1);
|
||||
vertices[i*2].uvs = uv * (radius_in/radius_out) * 0.5f + 0.5f;
|
||||
vertices[i*2+1].pos = glm::vec4(uv * radius_out, 0, 1);
|
||||
vertices[i*2+1].uvs = uv * 0.5f + 0.5f;
|
||||
|
||||
*pidx++ = i*2; // A
|
||||
*pidx++ = i*2+1; // B
|
||||
|
||||
Reference in New Issue
Block a user