Skip to content

Instantly share code, notes, and snippets.

@DieTime
Created March 25, 2020 19:59
Show Gist options
  • Save DieTime/59690232c7fad22751911004e17238f5 to your computer and use it in GitHub Desktop.
Save DieTime/59690232c7fad22751911004e17238f5 to your computer and use it in GitHub Desktop.
float cx = (x + x2 + x3) / 3;
float cy = (y + y2 + y3) / 3;
float l1 = std::sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
float l2 = std::sqrt((x2 - cx) * (x2 - cx) + (y2 - cy) * (y2 - cy));
float l3 = std::sqrt((x3 - cx) * (x3 - cx) + (y2 - cy) * (y2 - cy));
float dx = 2 * (x - cx) / l1 * (width / (float)glutGet(GLUT_WINDOW_WIDTH));
float dy = 2 * (y - cy) / l1 * (width / (float)glutGet(GLUT_WINDOW_HEIGHT));
float dx2 = 2 * (x2 - cx) / l2 * (width / (float)glutGet(GLUT_WINDOW_WIDTH));
float dy2 = 2 * (y2 - cy) / l2 * (width / (float)glutGet(GLUT_WINDOW_HEIGHT));
float dx3 = 2 * (x3 - cx) / l3 * (width / (float)glutGet(GLUT_WINDOW_WIDTH));
float dy3 = 2 * (y3 - cy) / l3 * (width / (float)glutGet(GLUT_WINDOW_HEIGHT));
glBegin(GL_TRIANGLE_STRIP);
glVertex2f(x + dx, y + dy);
glVertex2f(x - dx, y - dy);
glVertex2f(x2 + dx2, y2 + dy2);
glVertex2f(x2 - dx2, y2 - dy2);
glVertex2f(x3 + dx3, y3 + dy3);
glVertex2f(x3 - dx3, y3 - dy3);
glVertex2f(x + dx, y + dy);
glVertex2f(x - dx, y - dy);
glEnd();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment