I have problem about implement midpoint algorithm with eight octant. The current situation is show in the picture below as y axis is inverted.
so far I manage to make zone 1 working prefect, I have no ideas how to make it work for other zone, I been google and all I find is zone 1 example not in other zone.
here my code for zone 1
void Line2D::MPOct1(const Window& window, const Point2D& start,
const Point2D& end, const float& delta_x, const float& delta_y) const
{
Color color = mStartVtx.GetColor();
int int_delta_x = static_cast<int>(round(delta_x));
int int_delta_y = static_cast<int>(round(delta_y));
int start_x = static_cast<int>(round(start.GetX()));
int start_y = static_cast<int>(round(start.GetY()));
int const end_x = static_cast<int>(round(end.GetX()));
int f = 2 * int_delta_y - int_delta_x;
int f_e = 2 * int_delta_y ;
// should be se due to y axis inverted
int f_ne = 2 * int_delta_y + 2 * int_delta_x;
while (start_x <= end_x )
{
if (f >= 0)
{
window.SetPixel(start_x, start_y, color);
f += f_e;
start_x ++;
}
else
{
window.SetPixel(start_x, start_y, color);
f += f_ne;
start_x ++;
// y axis inveted so --
start_y --;
}
}
}
by default the decision parameter given is 2deltaY -deltaX
and the 8 direction I assume is:
east = 2deltaY
west = -2deltaY
north = 2deltaX (-2deltaX due to inverse of y axis)
south = -2deltaX (2deltaX due to inverse of y axis)
north-east = 2deltaY -2deltaX (2deltaY +2deltaX due to inverse of y axis )
north-west = -2deltaY -2deltaX (-2deltaY +2deltaX due to inverse of y axis )
south-east = 2deltaY +2deltaX (2deltaY -2deltaX due to inverse of y axis )
south-west = -2deltaY +2deltaX (-2deltaY -2deltaX due to inverse of y axis )
anyone can tell me how solve other oct zone, by manipulate update I manage to make zone 1 ,4,5,and 8 work