Open GL - algoritmos de rotacion

 
Vista:

algoritmos de rotacion

Publicado por Julio Omar (2 intervenciones) el 25/04/2008 07:55:03
Hola

necesito saber como aplicar los algoritmos de rotacion, escalacion, translacion de una linea, conosco mas o menos la matematica de algebra lineal que se requere para hacer esto pero no comprendo como pasarlo a codigo, trabajo en MFC + glut en visual c++ 6.0,

el algoritmo que estoy utilizando para dibujar la linea es el DDA, por una funcion

void linea_DDA(float x0, float y0, float x1, float y1)

esta funcion recibe el punto inicial y el punto final y dibuja los pixeles para hacer la linea

como hago todos esos calculos matriciales en c++?
la idea es no utilizar las funciones que trae glut para estas transformaciones sino hacerlo de manera manual.

cualquier comentario sera bien recibido
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

algoritmos de rotacion

Publicado por Angel Aguilar (1 intervención) el 29/03/2019 15:26:29
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//#include <GL/gl.h>
//#include <GL/glu.h>
#include <GL/glut.h>
#include <thread>
 
typedef struct{
    float x,y;
}TPoint;
 
TPoint p1,p2;
int refreshMillis = 100;      // Refresh period in milliseconds
float ax,ay,x,y,res;
int i;
 
void DDA(int nothing)
{
	p1.x=-10.0; p1.y=-10.0;
	p2.x=10.0; p2.y=10.0;
 
	float m;
	//calculate the slope and parameter b
	m=(p2.y-p1.y)/(p2.x-p1.x);
 
	if(abs(p2.x-p1.x)>=abs(p2.y-p1.y))
	//si la variacion en x es mayor o igual que la variacion en y
		res=abs(p2.x-p1.x);
	else
	//si la variacion en y es mayor que la variacion en x
		res=abs(p2.y-p1.y);
	ax=(p2.x-p1.x)/res;//el valor a aumentar en x
	ay=(p2.y-p1.y)/res;//el valor a aumentar en y
	//se realiza casteo a float porque los resultados de la división es un real
	x=(float)p1.x;
	y=(float)p1.y;
}
 
void Timer(int value)
{
	i=0;
	if(i<=res)
	{
		x=x+ax;
		y=y+ay;
		i++;
	}
	glutPostRedisplay();    // Post a paint request to activate display()
	glutTimerFunc(refreshMillis, Timer, 0); // subsequent timer call at milliseconds	
}
 
void display(void)
{
	glClear (GL_COLOR_BUFFER_BIT);
	glPushMatrix();
	//std::this_thread::sleep_for(std::chrono::milliseconds(100));
	glBegin(GL_LINE_LOOP);
	glVertex3f(x,y,0.0);
	glVertex3f(x+1,y,0.0);
	glVertex3f(x+1,y+1,0.0);
	glVertex3f(x,y+1,0.0);
	glEnd();
	glPopMatrix();
	glutSwapBuffers();
}
 
void init (void)
{
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-15.0,15.0,-15.0,15.0,-15.0,15.0);
	glMatrixMode(GL_MODELVIEW);
}
 
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize (400,400);
    glutInitWindowPosition (100,100);
    glutCreateWindow ("Algoritmo DDA");
 
    DDA(1);
    init ();
    glutTimerFunc(0, Timer, 0);
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;   /* ISO C requires main to return int. */
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar