lesson 10 line graphic error plz help (solved by Conflictus)

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
farie
Posts: 2
Joined: January 19th, 2013, 8:14 pm

lesson 10 line graphic error plz help (solved by Conflictus)

Post by farie » January 19th, 2013, 8:24 pm

if i go on a certain point my line will become very weird looking
link picture:
http://i.imgur.com/wASJPHY.jpg
and from that point to the left :
http://i.imgur.com/pcFJBZG.jpg
on the bottom it is the same this is the code i used it is i think the same as in the video:
in the D3DGraphics.h:
void Line (int x1,int y1, int x2, int y2, int r, int g ,int bl);
in the D3DGraphics.cpp
void D3DGraphics::Line (int x1,int y1, int x2, int y2, int r, int g ,int bl)
{
int dx = x2 - x1;
int dy = y2 - y1;


if ( abs( dy ) > abs( dx ) )
{
if(y1 > y2)
{
int temp = y2;
y2 = y1;
y1 = temp;
temp = x2;
x2 = x1;
x1 = temp;
}
float m = (float)dx / (float)dy;
float b = x1 - m*y1;
for(int y = y1; y <= y2; y++ )
{
int x = m*x + b + 0.5f;
PutPixel(x,y,r,g,bl);
}
}
else
{
if(x1 > x2)
{
int temp = y2;
y2 = y1;
y1 = temp;
temp = x2;
x2 = x1;
x1 = temp;
}
float m = (float)dy / (float)dx;
float b = y1 - m*x1;
for(int x = x1; x <= x2; x++)
{
int y = m*x + b + 0.5f;
PutPixel(x,y,r,g,bl);
}
}
}
i first had this code in the Game.h but it also didn't work there
the code in the Game.cpp
Game::Game( HWND hWnd,const KeyboardServer& kServer )
: gfx ( hWnd ),
kbd( kServer ),
x(500),
y(300)

{}
rest of the code that was already there.
if (kbd.DownIsPressed())y++;
if (kbd.UpIsPressed())y--;
if (kbd.LeftIsPressed())x--;
if (kbd.RightIsPressed())x++;

gfx.Line(400,300,x,y,255,255,255);
in the game.h file i have put some other functions but i dont think that matters but still:
void Crosshair( int x,int y,int r, int g, int b){
gfx.PutPixel( x, y, r,g,b);
gfx.PutPixel( x-5, y, r,g,b);
gfx.PutPixel( x-4, y, r,g,b);
gfx.PutPixel( x-3, y, r,g,b);
gfx.PutPixel( x+3, y, r,g,b);
gfx.PutPixel( x+4, y, r,g,b);
gfx.PutPixel( x+5, y, r,g,b);
gfx.PutPixel( x, y-5, r,g,b);
gfx.PutPixel( x, y-4, r,g,b);
gfx.PutPixel( x, y-3, r,g,b);
gfx.PutPixel( x, y+5, r,g,b);
gfx.PutPixel( x, y+4, r,g,b);
gfx.PutPixel( x, y+3, r,g,b);
}

/*void Line (int x1,int y1, int x2, int y2, int r, int g ,int bl)
{
int dx = x2 - x1;
int dy = y2 - y1;


if ( abs( dy ) > abs( dx ) )
{
if(y1 > y2)
{
int temp = y2;
y2 = y1;
y1 = temp;
temp = x2;
x2 = x1;
x1 = temp;
}
float m = (float)dx / (float)dy;
float b = x1 - m*y1;
for(int y = y1; y <= y2; y++ )
{
int x = m*x + b + 0.5f;
gfx.PutPixel(x,y,r,g,bl);
}
}
else
{
if(x1 > x2)
{
int temp = y2;
y2 = y1;
y1 = temp;
temp = x2;
x2 = x1;
x1 = temp;
}
float m = (float)dy / (float)dx;
float b = y1 - m*x1;
for(int x = x1; x <= x2; x++)
{
int y = m*x + b + 0.5f;
gfx.PutPixel(x,y,r,g,bl);
}
}
}*/
//i have put this in comment lines so it doesnt work.

void Squire(int xbegin, int ybegin, int xend, int yend, int r, int g, int b, bool full){
int xstart=xbegin;
int ystart=ybegin;
while (xbegin!=xend){
gfx.PutPixel(xbegin,ybegin,r,g,b);
xbegin++;
if (xbegin==xend && ybegin!=yend){
xbegin=xstart;
if(full)
{
ybegin++;
}



else
{
ybegin=yend;
}
}


}
ybegin=ystart;
xbegin=xstart;
while (ybegin!=yend && !full){
gfx.PutPixel(xbegin,ybegin,r,g,b);
ybegin++;
if (ybegin==yend && xbegin!=xend){
ybegin=ystart;
xbegin=xend;

}


}



}
plz can somebody say what is the error?
Last edited by farie on January 20th, 2013, 2:29 pm, edited 1 time in total.

Conflictus
Posts: 53
Joined: January 7th, 2013, 8:09 am

Re: lesson 10 line graphic error plz help

Post by Conflictus » January 19th, 2013, 9:26 pm

There's an error in D3DGraphics.cpp. I'm uncertain if it's the only one, but i'd say pay close attention to the X and Y variables.

farie
Posts: 2
Joined: January 19th, 2013, 8:14 pm

Re: lesson 10 line graphic error plz help

Post by farie » January 19th, 2013, 9:43 pm

thanks for your help.
I found the error i didn't notice it when looking over it last times.
really thank u.

Post Reply