added intersection and uvs correction functions
This commit is contained in:
@@ -12,6 +12,28 @@ public:
|
||||
bool create_buffers(GLvoid* idx, GLvoid* vertices, int isize, int vsize);
|
||||
void draw_fill() const;
|
||||
void draw_stroke() const;
|
||||
protected:
|
||||
glm::vec2 quad_mid_point(glm::vec2 a, glm::vec2 b, glm::vec2 c, glm::vec2 d)
|
||||
{
|
||||
float den = (a.x-c.x)*(b.y-d.y) - (a.y-c.y)*(b.x-d.x);
|
||||
float numx = (a.x*c.y-a.y*c.x)*(b.x-d.x) - (a.x-c.x)*(b.x*d.y-b.y*d.x);
|
||||
float numy = (a.x*c.y-a.y*c.x)*(b.y-d.y) - (a.y-c.y)*(b.x*d.y-b.y*d.x);
|
||||
return glm::vec2(numx, numy) / den;
|
||||
}
|
||||
void adjust_quad_uvs(vertex_t& va, vertex_t& vb, vertex_t& vc, vertex_t& vd)
|
||||
{
|
||||
static float d[4];
|
||||
static vertex_t* v[4];
|
||||
v[0] = &va; v[1] = &vb; v[2] = &vc; v[3] = &vc;
|
||||
auto mid = quad_mid_point(va.pos, vb.pos, vc.pos, vd.pos);
|
||||
for (int i = 0; i < 4; i++)
|
||||
d[i] = glm::distance(glm::vec2(v[i]->pos), mid);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
float q = (d[i] + d[(i + 2) % 4]) / d[(i + 2) % 4];
|
||||
v[i]->uvs = glm::vec4(glm::vec2(v[i]->uvs), 0, 1) * q;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Plane : public Shape
|
||||
|
||||
Reference in New Issue
Block a user