DDA


/*
 * main.c
 *
 * Created on: Apr 29, 2014
 * Author: akshaythakare
 */

#include <stdio.h>
#include <stdlib.h>
#include <openGL/gl.h>
#include <openGL/glu.h>
#include <GLUT/glut.h>

float x1,x2,y1,y2;

void DDA()
{

 float xk,yk,dx,dy,temp,step,xinc,yinc;

 x1=10;x2=100;y1=10;y2=100;
 dx = x2-x1;
 dy=y2-y1;

 if(x1>x2&&y1>y2)
 {
 temp = x1;
 x1 = x2;
 x2 = temp;
 temp = y1;
 y1 = y2;
 y2 = temp;
 }

 xk=x1;yk=y1;

 if(dx>dy)
 step = dx;
 else
 step = dy;

 xinc = dx/step;
 yinc = dy/step;

 glBegin(GL_POINTS);
 glVertex2f(x1,x2);

 while(xk<x2&&yk<y2)
 {
 xk += xinc;
 yk += yinc;
 glVertex2f(xk,yk);
 }
 glEnd();
 return;

}

void disp()
{
 glClearColor(0,0,0,0);
 glClear(GL_COLOR_BUFFER_BIT);
 glColor3f(1,1,1);
 DDA();
 glFlush();
}


int main(int argv, char ** argc)
{
 printf("\nEnter x1 = ");
 scanf("%f",&x1);
 printf("\nEnter y1 = ");
 scanf("%f",&y1);
 printf("\nEnter x2 = ");
 scanf("%f",&x2);
 printf("\nEnter y2 = ");
 scanf("%f",&y2);

 glutInit(&argv,argc);
 glutInitWindowSize(300,300);
 glutCreateWindow("DDA");
 gluOrtho2D(0,300,0,300);
 glutDisplayFunc(disp);
 glutMainLoop();
 return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s