On lesson 12 when you make the grid for the tic tac toe game I put the exact same code but my grid looks like this http://i.imgur.com/qGt2x.png
I think I might of messed something up in the DrawLine function.
Could someone give me the code for DrawLine?
Lesson 12 Tic Tac Toe Line Problen
Re: Lesson 12 Tic Tac Toe Line Problen
Here is the code in the DrawLine function that is in the D3DGraphics.cpp file. Don't forget to put
" void DrawLine( int x1, int y1, int x2, int y2, int r, int g, int bl ) " in the D3DGraphic.h file.
" void DrawLine( int x1, int y1, int x2, int y2, int r, int g, int bl ) " in the D3DGraphic.h file.
Code: Select all
void D3DGraphics::DrawLine( 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*y + 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 );
}
}
}
CraigSpaz
Re: Lesson 12 Tic Tac Toe Line Problen
I'd guess you have something messed in the draw line too. Or maybe just missed some of the Y values to draw the lines.
But I wouldn't recommend just copy pasting the code. Part of coding is to solve it your self, at least try. Instead of just copy pasting it , try to compare the codes and see what you did wrong and rewrite it yourself.
But I wouldn't recommend just copy pasting the code. Part of coding is to solve it your self, at least try. Instead of just copy pasting it , try to compare the codes and see what you did wrong and rewrite it yourself.
ʕ •ᴥ•ʔ
Re: Lesson 12 Tic Tac Toe Line Problen
Word. If you can't manage a non-optimized line drawing algorithm then you might as well forget about programming anything 3D.LuX wrote:But I wouldn't recommend just copy pasting the code. Part of coding is to solve it your self, at least try. Instead of just copy pasting it , try to compare the codes and see what you did wrong and rewrite it yourself.
Chili