Factored distance calculation into separate utility class
This commit is contained in:
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user