Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glut.h>
- #include <bits/stdc++.h>
- const double PI = M_PI;
- bool touch(float x1, float y1, float x2, float y2, float r1, float r2) {
- double d = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
- return (d <= r1 + r2);
- }
- void drawCircle(double cx, double cy, double r, int segments) {
- glBegin(GL_LINE_LOOP);
- for (int i = 0; i < segments; i++) {
- double theta = 2.0 * PI * i / segments;
- double x = r * cos(theta);
- double y = r * sin(theta);
- glVertex2f(cx + x, cy + y);
- }
- glEnd();
- }
- void drawFilledCircle(double cx, double cy, double r, int segments) {
- glBegin(GL_POLYGON);
- for (int i = 0; i < segments; i++) {
- double theta = 2.0 * PI * i / segments;
- double x = r * cos(theta);
- double y = r * sin(theta);
- glVertex2f(cx + x, cy + y);
- }
- glEnd();
- }
- void drawLeftPenaltyArc(double cx, double cy, double r, int segments) {
- double startAngle = -0.87;
- double endAngle = 0.87;
- glBegin(GL_LINE_STRIP);
- for (int i = 0; i <= segments; i++) {
- double theta = startAngle + (endAngle - startAngle) * i / segments;
- double x = r * cos(theta);
- double y = r * sin(theta);
- glVertex2f(cx + x, cy + y);
- }
- glEnd();
- }
- void drawRightPenaltyArc(double cx, double cy, double r, int segments) {
- double startAngle = 3.14 - 0.87;
- double endAngle = 3.14 + 0.87;
- glBegin(GL_LINE_STRIP);
- for (int i = 0; i <= segments; i++) {
- double theta = startAngle + (endAngle - startAngle) * i / segments;
- double x = r * cos(theta);
- double y = r * sin(theta);
- glVertex2f(cx + x, cy + y);
- }
- glEnd();
- }
- void drawGoalInsideArea(double x, double y) {
- double goalWidth = 2.5;
- double goalHeight = 10.5;
- glBegin(GL_LINE_LOOP);
- glVertex2f(x, y);
- glVertex2f(x + goalWidth, y);
- glVertex2f(x + goalWidth, y + goalHeight);
- glVertex2f(x, y + goalHeight);
- glEnd();
- }
- void display() {
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(1, 1, 1);
- glBegin(GL_LINE_LOOP);
- glVertex2f(0, 0);
- glVertex2f(105, 0);
- glVertex2f(105, 68);
- glVertex2f(0, 68);
- glEnd();
- glBegin(GL_LINES);
- glVertex2f(52.5, 0);
- glVertex2f(52.5, 68);
- glEnd();
- drawCircle(52.5, 34, 9.15, 100);
- glBegin(GL_LINE_LOOP);
- glVertex2f(0, 13.85);
- glVertex2f(16.5, 13.85);
- glVertex2f(16.5, 54.15);
- glVertex2f(0, 54.15);
- glEnd();
- glBegin(GL_LINE_LOOP);
- glVertex2f(105, 13.85);
- glVertex2f(88.5, 13.85);
- glVertex2f(88.5, 54.15);
- glVertex2f(105, 54.15);
- glEnd();
- drawLeftPenaltyArc(10.65, 34, 9.15, 100);
- drawRightPenaltyArc(94.35, 34, 9.15, 100);
- glPointSize(5.0);
- glBegin(GL_POINTS);
- glVertex2f(11, 34);
- glEnd();
- glBegin(GL_POINTS);
- glVertex2f(94, 34);
- glEnd();
- glBegin(GL_POINTS);
- glVertex2f(52.5, 34);
- glEnd();
- double leftGoalY = 34 - (10.5 / 2);
- double rightGoalY = 34 - (10.5 / 2);
- drawGoalInsideArea(0, leftGoalY);
- drawGoalInsideArea(105 - 2.5, rightGoalY);
- glutSwapBuffers();
- }
- void init() {
- glClearColor(0.0f, 0.5f, 0.0f, 1.0f);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D(0.0, 105.0, 0.0, 68.0);
- }
- int main(int argc, char** argv) {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(1050, 680);
- glutCreateWindow("Campo de Futebol 2D");
- init();
- glutDisplayFunc(display);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement