Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <gl/freeglut.h>
- #include <cmath>
- #include <iostream>
- GLint winWidth = 800, winHeight = 800;
- GLfloat xx0 = 13.0, yy0 = 11.0, zz0 = 14.0;
- GLfloat xref = 3.0, yref = 1.0, zref = 4.0;
- GLfloat Vx = 8.0, Vy = 0.0, Vz = -8.0;
- GLfloat xwMin = -10.0, ywMin = -10.0, xwMax = 10.0, ywMax = 10.0;
- GLfloat dnear = 0.0, dfar = 20.0;
- void init(void)
- {
- glClearColor(1.0, 1.0, 1.0, 0.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(xx0, yy0, zz0, xref, yref, zref, Vx, Vy, Vz);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(xwMin, xwMax, ywMin, ywMax, dnear, dfar);
- }
- class Punct
- {
- public:
- float x, y, z;
- Punct(int xx, int yy, int zz)
- {
- x = xx;
- y = yy;
- z = zz;
- }
- Punct()
- {
- x = y = z = 0;
- }
- };
- void desen()
- {
- Punct A(3, 1, 0), B(-2, 2, 4), C(0, 0, 4);
- glLineWidth(3.0);
- glPointSize(3.0);
- //a) determinati punctul M astfel incat sa fie in interiorul triunghiului ABC sau pe laturi
- Punct M;
- M.x = (B.x + C.x) / 2;
- M.y = (B.y + C.y) / 2;
- M.z = (B.z + C.z) / 2;
- glPointSize(10.0);
- glBegin(GL_POINTS);
- glColor3f(1.0, 0.5, 0.5);
- glVertex3i(M.x, M.y, M.z);
- glEnd();
- //b) deteminati D in planul triunghiului asa incat ABDC(atentie la ordine!!!) sa fie un patrulater convex
- Punct D; //am construit punctul D a.i. sa fie simetricul varfului A
- D.x = 2 * M.x - A.x;
- D.y = 2 * M.y - A.y;
- D.z = 2 * M.z - A.z;
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- glBegin(GL_POLYGON);
- glColor3f(1.0, 0.0, 0.0);
- glVertex3i(A.x, A.y, A.z);
- glColor3f(0.0, 1.0, 0.0);
- glVertex3i(B.x, B.y, B.z);
- glColor3f(1.0, 0.0, 1.0);
- glVertex3i(D.x, D.y, D.z);
- glColor3f(0.0, 0.0, 1.0);
- glVertex3i(C.x, C.y, C.z);
- glEnd();
- //c) construiti normala n la patrulaterul ABDC
- Punct Normala;
- Normala.x = (A.y * B.z + B.y * C.z + C.y * A.z) - (C.y * B.z + A.y * C.z + B.y * A.z);
- Normala.y = (C.x * B.z + A.x * C.z + B.x * A.z) - (A.x * B.z + B.x * C.z + C.x * A.z);
- Normala.z = (A.x * B.y + B.x * C.y + C.x * A.y) - (C.x * B.y + A.x * C.y + B.x * A.y);
- float radical = std::sqrt(Normala.x * Normala.x + Normala.y * Normala.y + Normala.z * Normala.z);
- Normala.x = Normala.x / radical;
- Normala.y = Normala.y / radical;
- Normala.z = Normala.z / radical;
- std::cout << "Normala la patrulater este n = " << Normala.x << "i + " << Normala.y << "j + "<< Normala.z << "k.\n";
- //d) folosind M si n construiti un punct O1 in fata patrulaterului si un punct O2 in spatele acestuia.
- Punct O1(M.x * 7 * Normala.x, M.y * 7 * Normala.y, M.z * 7 * Normala.z);
- Punct O2(M.x * (-7) * Normala.x, M.y * (-7) * Normala.y, M.z * (-7) * Normala.z);
- std::cout << "Punctul O1 de coordonate" << O1.x << "," << O1.y << ", " << O1.z << "\n";
- std::cout << "Punctul O2 de coordonate" << O2.x << "," << O2.y << ", " << O2.z << "\n";
- glFlush();
- }
- void main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
- glutInitWindowPosition(50, 50);
- glutInitWindowSize(winWidth, winHeight);
- glutCreateWindow("Poligoane in context 3D. Fata si spatele unui poligon");
- init();
- glClear(GL_COLOR_BUFFER_BIT);
- glutDisplayFunc(desen);
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment