Created
November 10, 2017 16:59
-
-
Save JSiapo/2f9b6adce64292d59f6d051bff7b817c to your computer and use it in GitHub Desktop.
Algoritmo DDA para líneas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void DDA (GLint x1,GLint y1,GLint x2,GLint y2) | |
{ | |
float ax,ay,x,y,res; | |
GLint i; | |
if(abs(x2-x1)>=abs(y2-y1)) | |
//si la variacion en x es mayor o igual que la variacion en y | |
res=abs(x2-x1); | |
else | |
//si la variacion en y es mayor que la variacion en x | |
res=abs(y2-y1); | |
ax=(x2-x1)/res;//el valor a aumentar en x | |
ay=(y2-y1)/res;//el valor a aumentar en y | |
//se realiza casteo a float porque los resultados de la división es un real | |
x=(float)x1; | |
y=(float)y1; | |
i=0; | |
while(i<=res) | |
{ | |
setPixel(roundf(x),roundf(y)); | |
x=x+ax; | |
y=y+ay; | |
i++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment