add transform mode and tollbar button, implement polygon clipping with uvs interpolation and cube faces projection with near plane clipping, add duplicate points removal template function, implement Spere mesh surface section creation.

This commit is contained in:
2018-11-12 18:19:03 +01:00
parent eb1c8d6b7a
commit 18067726b5
12 changed files with 512 additions and 81 deletions

View File

@@ -185,7 +185,7 @@ bool RectShape::create(float w, float h)
return create_buffers(idx, vertices, sizeof(idx), sizeof(vertices));
}
void Plane::create_impl(float w, float h, int div, GLushort *idx, Shape::vertex_t *vertices)
void Plane::create_impl(float w, float h, int div, GLushort *idx, vertex_t *vertices)
{
count[0] = div * div * 6;
count[1] = (div + 1) * 4;
@@ -317,8 +317,8 @@ void ui::Plane::update_vertices(const glm::vec4* data, const glm::vec2* uvs, con
{
static vertex_t vertices[4];
glm::vec2 mid;
segments_intersect(xy(data[0]), xy(data[2]), xy(data[1]), xy(data[3]), mid);
glm::vec2 mid, hit_uv;
segments_intersect(xy(data[0]), xy(data[2]), xy(data[1]), xy(data[3]), mid, hit_uv);
static float d[4];
for (int i = 0; i < 4; i++)
d[i] = glm::distance(xy(data[i]), mid);
@@ -442,7 +442,7 @@ void Circle::create_impl(float radius_out, float radius_in, int div, GLushort* i
//}
}
void Rounded::create_impl(float w, float h, float r, int div, GLushort* idx, GLushort* idx_tmp, Shape::vertex_t* vertices)
void Rounded::create_impl(float w, float h, float r, int div, GLushort* idx, GLushort* idx_tmp, vertex_t* vertices)
{
count[0] = (10 + div * 4) * 3;
count[1] = (4 + div * 4) * 2;
@@ -454,7 +454,7 @@ void Rounded::create_impl(float w, float h, float r, int div, GLushort* idx, GLu
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 {
auto V = [&](int x, int y) -> 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);
@@ -522,7 +522,7 @@ void Rounded::create_impl(float w, float h, float r, int div, GLushort* idx, GLu
*idx2++ = 2;
}
void Slice9::create_impl(float w, float h, float r, float tr, GLushort *idx, Shape::vertex_t *vertices)
void Slice9::create_impl(float w, float h, float r, float tr, GLushort *idx, vertex_t *vertices)
{
count[0] = 3 * 3 * 6;
count[1] = 4 * 2;
@@ -533,7 +533,7 @@ void Slice9::create_impl(float w, float h, float r, float tr, GLushort *idx, Sha
float Y[] = { -h/2, -h/2+r, h/2-r, h/2 };
float T[] = { 0, tr, 1-tr, 1 };
auto V = [&](int x, int y) -> Shape::vertex_t {
auto V = [&](int x, int y) -> vertex_t {
return { glm::vec4(X[x], Y[y], 0, 1), glm::vec2(T[x], T[y]) };
};
@@ -565,22 +565,31 @@ void Slice9::create_impl(float w, float h, float r, float tr, GLushort *idx, Sha
*idx++ = 12; // D
*idx++ = 0; // A
}
void Sphere::create_impl(int rings, int sectors, float radius, GLushort *idx, Shape::vertex_t *vertices)
void Sphere::create_impl(int rings, int sectors, float radius,
float lat_start, float lat_end, float lon_start, float lon_end,
GLushort *idx, vertex_t *vertices)
{
count[0] = rings * sectors * 6;
count[1] = 0;
ioff[0] = (GLvoid*)0;
ioff[1] = (GLvoid*)0;
lat_start += M_PI_2;
lat_end += M_PI_2;
lon_start -= M_PI_2;
lon_end -= M_PI_2;
float lat_size = (lat_end - lat_start);
float lon_size = (lon_end - lon_start);
float const R = 1.f / (float)(rings-1);
float const S = 1.f / (float)(sectors-1);
int r, s;
auto v = vertices;
for(r = 0; r < rings; r++) for(s = 0; s < sectors; s++) {
float const y = (float)sin( -M_PI_2 + M_PI * r * R );
float const x = (float)cos(2*M_PI * s * S) * (float)sin( M_PI * r * R );
float const z = (float)sin(2*M_PI * s * S) * (float)sin( M_PI * r * R );
float lat = lat_start + r * lat_size * R;
float lon = lon_start + s * lon_size * S;
float const y = (float)sin(lat - M_PI_2);
float const x = (float)cos(lon) * (float)sin(lat);
float const z = (float)sin(lon) * (float)sin(lat);
*v++ = { glm::vec4(x, y, z, 1) * radius, glm::vec2(s*S, r*R) };
}