Skip to content

Instantly share code, notes, and snippets.

@0xKD
Created January 2, 2013 10:36
Show Gist options
  • Save 0xKD/4433678 to your computer and use it in GitHub Desktop.
Save 0xKD/4433678 to your computer and use it in GitHub Desktop.
DDA in C++
#include <iostream>
#define ROUND(a) ((int)(a + 0.5))
using namespace std;
int drawDDA(int x1,int y1,int x2,int y2)
{
float x = x1, y = y1;
int len = (x2-x1)>(y2-y1)?(x2-x1):(y2-y1);
float dx = (x2-x1)/(float)len;
float dy = (y2-y1)/(float)len;
cout<<"x = "<<ROUND(x)<<", y = "<<ROUND(y)<<"\n";
for (int k=0; k < len; k++)
{
x += dx;
y += dy;
cout<<"x = "<<ROUND(x)<<", y = "<<ROUND(y)<<"\n";
}
return 0;
}
int main()
{
drawDDA(2,5,10,20);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment