I thought I would try to upload this code to github, and then post about the problem here, but that won't work for me either. I have tried several times to follow the video exactly, but after I've created a github page and try to push to it, I'm greeted with the message: "Exception of type 'Microsoft.TeamFoundation.Git.Contracts.GitRemoteRefNotFoundException' was thrown."
So, since I can't seem to get github working properly, here is the fuction I added in graphics(the zipped solution was appearently to large to upload, don't know if I'm doing anything wrong there):
Code: Select all
void Graphics::DrawLine(int x0, int y0, int x1, int y1, Color c)
{
float xDiff = x1 - x0; //The line is based in 0's coordinates, so if corresponding 1's coordinates are bigger,
float yDiff = y1 - y0; //we want the Diff to be positive, and if they are smaller, we want the Diff to be negative.
float xIncrement; //This in return means that the corresponding increment will be correspondingly positive or negative,
float yIncrement; //and the line is drawn from 0's coordinates in the right direction. If we switch 0's and 1's coordinates in the evaluation above, the "polarity" of the incrementors are flipped, and the line is drawn mirrored to where it is actually supposed to be.
if (abs(xDiff) > abs(yDiff)) //Checks what Diff is greater, and sets that one to either 1 or -1. The other Diff will then always be between 1 and -1(never more then abs() = 1. This makes sure the line is whole, and not dotted.
{
xIncrement = xDiff / abs(xDiff); //Sets xIncrement equal to either 1 or -1, depending on whether it is positive or negative.
yIncrement = yDiff / abs(xDiff); //By setting yIncrement this way, we can increment both xIncrement and yIncrement at the same rate until they reach the end of the line.
}
else
{
yIncrement = yDiff / abs(yDiff); //Sets yIncrement equal to either 1 or -1, depending on whether it is positive or negative.
xIncrement = xDiff / abs(yDiff); //By setting xIncrement this way, we can increment both xIncrement and yIncrement at the same rate until they reach the end of the line.
}
for (float i = 0; i <= std::max(abs(xDiff), abs(yDiff)); ++i) //This loop draws 1 pixel every itteration, moving it slightly closer to 0's coordinates every time.
{
if (x0 + i * xIncrement >= 0 && x0 + i * xIncrement <= ScreenWidth - 1 && y0 + i * yIncrement >= 0 && y0 + i * yIncrement <= ScreenHeight - 1) //Safety check for pixels off the screen
{
PutPixel(x0 + i * xIncrement, y0 + i * yIncrement, c);
}
}
}
"clean" version with no comments:
void Graphics::DrawLine(int x0, int y0, int x1, int y1, Color c)
{
float xDiff = x1 - x0;
float yDiff = y1 - y0;
float xIncrement;
float yIncrement;
if (abs(xDiff) > abs(yDiff))
{
xIncrement = xDiff / abs(xDiff);
yIncrement = yDiff / abs(xDiff);
}
else
{
yIncrement = yDiff / abs(yDiff);
xIncrement = xDiff / abs(yDiff);
}
for (float i = 0; i <= std::max(abs(xDiff), abs(yDiff)); ++i)
{
if (x0 + i * xIncrement >= 0 && x0 + i * xIncrement <= ScreenWidth - 1 && y0 + i * yIncrement >= 0 && y0 + i * yIncrement <= ScreenHeight - 1)
{
PutPixel(x0 + i * xIncrement, y0 + i * yIncrement, c);
}
}
}
PS: Sorry for the obnoxious(?) amounts of comments, but I tried to explain this to myself in as much detail as possible, in case I need to modify it in the future.
Also, I use floats because I learned about them before embarking on c++ with chili, so I haven't seen any videos past 15