Lesson 12 Tic Tac Toe Line Problen

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
bmangoogle
Posts: 1
Joined: June 29th, 2012, 1:13 am

Lesson 12 Tic Tac Toe Line Problen

Post by bmangoogle » June 29th, 2012, 1:30 am

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?

Craigspaz
Posts: 33
Joined: June 9th, 2012, 12:23 am

Re: Lesson 12 Tic Tac Toe Line Problen

Post by Craigspaz » June 29th, 2012, 2:21 am

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.

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

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Lesson 12 Tic Tac Toe Line Problen

Post by LuX » June 29th, 2012, 10:44 am

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.
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Lesson 12 Tic Tac Toe Line Problen

Post by chili » June 29th, 2012, 11:01 am

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.
Word. If you can't manage a non-optimized line drawing algorithm then you might as well forget about programming anything 3D. ;)
Chili

Post Reply