Factored distance calculation into separate utility class

This commit is contained in:
2011-06-23 12:07:45 -04:00
parent d8e97ff0c9
commit 54b46d77d2
6 changed files with 35 additions and 22 deletions

View File

@ -1,5 +1,6 @@
#include "drawutils.h"
#include <cmath>
#include "mathutils.h"
SDL_Surface* DrawUtils::load(string file)
{
@ -58,15 +59,12 @@ void DrawUtils::draw_line(SDL_Surface* dest, Sint16 x1, Sint16 y1, Sint16 x2, Si
SDL_Rect pen;
dx = static_cast<float>(x2-x1);
dy = static_cast<float>(y2-y1);
len = sqrt(dx*dx + dy*dy);
len = MathUtils::distance(x1,y1,x2,y2);
// changing dx and dy's meanings. Now they represent the amount we move
// each step in our drawing loop
dx /= len;
dy /= len;
dx = static_cast<float>(x2-x1) / len;
dy = static_cast<float>(y2-y1) / len;
int j = static_cast<int>(len);