00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "BresenhamLineScan.h"
00012
00013 void BresenhamLineScan::setup(const Vector2<int>& start, const Vector2<int>& end)
00014 {
00015 int dx(end.x - start.x);
00016 int dy(end.y - start.y);
00017 int incX = ((dx>0) ? 1:-1);
00018 int incY = ((dy>0) ? 1:-1);
00019 int absDx(abs(dx));
00020 int absDy(abs(dy));
00021 alongX = (absDy < absDx);
00022 if(alongX)
00023 {
00024 baseError = -absDx;
00025 delta = 2*absDy;
00026 standardOffset.x = incX;
00027 standardOffset.y = 0;
00028 correctionOffset.x = 0;
00029 correctionOffset.y = incY;
00030 numberOfPixels = absDx;
00031 }
00032 else
00033 {
00034 baseError = -absDy;
00035 delta = 2*absDx;
00036 standardOffset.x = 0;
00037 standardOffset.y = incY;
00038 correctionOffset.x = incX;
00039 correctionOffset.y = 0;
00040 numberOfPixels = absDy;
00041 }
00042 resetError = 2*baseError;
00043 }
00044
00045 BresenhamLineScan::BresenhamLineScan(const Vector2<int>& start, const Vector2<int>& end)
00046 {
00047 setup(start, end);
00048 }
00049
00050 BresenhamLineScan::BresenhamLineScan(const double& direction, const CameraInfo& cameraInfo)
00051 {
00052 const Vector2<int> frameUpperLeft(0,0);
00053 const Vector2<int> frameLowerRight(cameraInfo.resolutionWidth-1, cameraInfo.resolutionHeight-1);
00054 Geometry::Line scanLine(frameLowerRight/2, Vector2<double>(cos(direction), sin(direction)));
00055 Vector2<int> lineStart, lineEnd;
00056 Geometry::getIntersectionPointsOfLineAndRectangle(
00057 frameUpperLeft,
00058 frameLowerRight,
00059 scanLine, lineStart, lineEnd);
00060 setup(lineStart, lineEnd);
00061 }
00062
00063 BresenhamLineScan::BresenhamLineScan(const Vector2<int>& start, const double& direction, const CameraInfo& cameraInfo)
00064 {
00065 const Vector2<int> frameUpperLeft(0,0);
00066 const Vector2<int> frameLowerRight(cameraInfo.resolutionWidth-1, cameraInfo.resolutionHeight-1);
00067 Geometry::Line scanLine(start, Vector2<double>(cos(direction), sin(direction)));
00068 Vector2<int> lineStart, lineEnd;
00069 Geometry::getIntersectionPointsOfLineAndRectangle(
00070 frameUpperLeft,
00071 frameLowerRight,
00072 scanLine, lineStart, lineEnd);
00073 Vector2<double> delta((lineEnd - start).x, (lineEnd - start).y);
00074 Vector2<double> directionVector(cos(direction), sin(direction));
00075 if (delta*directionVector >= 0)
00076 setup(start, lineEnd);
00077 else
00078 setup(start, lineStart);
00079 }
00080
00081 BresenhamLineScan::BresenhamLineScan(const Vector2<double>& direction, const CameraInfo& cameraInfo)
00082 {
00083 const Vector2<int> frameUpperLeft(0,0);
00084 const Vector2<int> frameLowerRight(cameraInfo.resolutionWidth-1, cameraInfo.resolutionHeight-1);
00085 Geometry::Line scanLine(frameLowerRight/2, direction);
00086 Vector2<int> lineStart, lineEnd;
00087 Geometry::getIntersectionPointsOfLineAndRectangle(
00088 frameUpperLeft,
00089 frameLowerRight,
00090 scanLine, lineStart, lineEnd);
00091 setup(lineStart, lineEnd);
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110