Professional Documents
Culture Documents
Transformación Geométrica: #Define #Include #Include #Include #Include
Transformación Geométrica: #Define #Include #Include #Include #Include
6000459
Transformación Geométrica
#define nodos 6
#include<cstdlib>
#include "glut.h"
#include<math.h>
#include<iostream>
using namespace std;
int anc = 800, alt = 600, T = 0, E = 0, R = 0;
float Tx = 1, Ty = 0, tam = 0, Sx = 0.9999, Sy = 0.9999, angulo = 0.05;
float matrix[nodos][2] = {//LA figura vertice centro 3
{150,50},{100,150},{200,250},{300,150},{250,50},{150,50}
};
void pixel(float xi, float yi, float xf, float yf, float R, float G, float B) {
glLineWidth(3);
glBegin(GL_LINES);//cambiamos puntos a lineas
glColor3f(R, G, B);
glVertex2d(xi, yi);
glVertex2d(xf, yf);
glEnd();
glFlush();
}
void plano(float m[nodos][2]) {
for (int i = 0; i < nodos - 1; i++) {
pixel(m[i][0], m[i][1], m[i + 1][0], m[i + 1][1], 1, 0, 0);
}
}
void traslacion(float m[nodos][2]) {
float tras[3][3] = { {1,0,Tx},{0,1,Ty},{0,0,1} };
if (m[3][0] < anc && m[3][1] == 50) {
Tx = 1, Ty = 0;
}
else if (m[3][0] == anc && m[3][1] < alt) {
Tx = 0, Ty = 1;
}
else if (m[3][0] > 150 && m[3][1] == alt) {
Tx = -1, Ty = 0;
}
else if (m[3][0] == 150 && m[3][1] > alt) {
Tx = 0, Ty = -1;
}
float p1 = m[3][0], p2 = m[3][1];
for (int i = 0; i < nodos; i++) {
m[i][0] = ((m[i][0] * tras[0][0]) + (m[i][1] * tras[0][1]) +
tras[0][2]);
m[i][1] = ((m[i][0] * tras[1][0]) + (m[i][1] * tras[1][1]) +
tras[1][2]);
}
plano(m);
}
void escala(float m[nodos][2]) {
else {
R = 0;
}
glutPostRedisplay();
break;
}
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
if (T + E + R == 0) {
plano(matrix);
}
if (T == 1) {
Daniel Eduardo Pedroza Pedraza
6000459
traslacion(matrix);
}
if (E == 1) {
escala(matrix);
}
if (R == 1) {
rotar(matrix);
}
glFlush;
glutSwapBuffers();
glutPostRedisplay();
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowSize(anc, alt);
glutInitWindowPosition(75, 50);
glutCreateWindow("Transformaciones 2d");
glClearColor(0, 0, 0, 1);
gluOrtho2D(0, anc, 0, alt);
glutDisplayFunc(display);
glutKeyboardFunc(teclado);
glutMainLoop();
return 0;
}