I Don't Watch 3D Fund, But....

The Partridge Family were neither partridges nor a family. Discuss.
goldengamesTM

I Don't Watch 3D Fund, But....

Post by goldengamesTM » December 6th, 2017, 6:28 pm

So Let's Get Some Things Straight: I Don't And Will Never Watch 3D Fund, And I'm Not That Smart. We Good? Good. I Feel That I Am Experienced Enough To Start Developing My Own Stuff, And I Want To Make A 3D Engine.

Rules:

1. I Can't Watch Any Chili Vids Between Now And When The Challenge Is Complete. ( Not Even The Main Series )

2. The Challange Is Complete When I Make A Full 3D Game Or Program.

3. I CAN Look To The Forum For Help

Let's Get Started:

So As Always, I Made A Concept Project On Scratch:


tris2.PNG
tris2.PNG (2 KiB) Viewed 4038 times
tris3.PNG
tris3.PNG (2.94 KiB) Viewed 4038 times
https://scratch.mit.edu/projects/190675551/

All Of That Was Made Just Using A Triangle Fill Algorithm ( Got The Idea Cause I Heard Chili Say Something About "Triangle Rasterization" In The Main Series Somewhere Around Lesson 18ish )

Now Tomorrows Task Is To Try To Translate That Crap Into C++, And Make It Real.

Ok, So It's Been 2 Days, And I Have Been Spending Those Days Trying To Draw A Slanted Line, But I Can't Do It! Any Help Appreciated.

My First Attempt Drew A Slanted Line, But Would Only Draw Them Perfectly Slanted.

Code: Select all

void DrawLine(int x0, int y0, int x1, int y1)
{
       int x = x0;
       int y = y0;
       for(int i = 0; i < 800; i++)
       {
               if( x < x1 )
               {
                      if( y < y1 )
                      {
                              y++
                              x++
                              PutPixel(x, y, 255, 255, 255);
                      }
               }
       }
}
Attempt No.2, Fail No.2:

Code: Select all

void DrawLine(int x1, int y1, int x2, int y2, Color c)
   {
      int dx = x2 - x1;
      int dy = y2 - y1;
      int m = dy / dx;
      int b = y1 - m*x1;
      for (int x = x1; x <= x2; x++)
      {
         int y = m*x + b;
         PutPixel(x, y, c);
      }
   }


Eureka! I Don't Know What I Did, But It Worked!

Code: Select all

	void DrawLine(float x1, float y1, float x2, float y2, Color c)
	{
		float dx = (x2 - x1);
		float dy = (y2 - y1);
		float m = dy/dx;
		float b = y1 - m*x1;
		for (float x = x1; x <= x2; x++)
		{
			float y = m*x + b;
			PutPixel(x, y, c);
		}
	}
Spot The Difference?

Code: Select all

void DrawLine(int x1, int y1, int x2, int y2, Color c)
   {
      int dx = x2 - x1;
      int dy = y2 - y1;
      int m = dy / dx;
      int b = y1 - m*x1;
      for (int x = x1; x <= x2; x++)
      {
         int y = m*x + b;
         PutPixel(x, y, c);
      }
   }
It Wasn't Long Before I Realized That Specific Angles Only Put Down Every Other Pixel, So I Put The Code Back To Normal, And Watch The Slanted Line Portion Of Old Beginner Lesson 10 And Got This Via Monkey See Monkey Do:

Code: Select all

	void DrawLine(int x1, int  y1, int  x2, int y2, Color c)
	{
        int dx = (x2 - x1);
		int  dy = (y2 - y1);
		float m = (float) dy/ (float) dx;
		float b = y1 - m* (float) x1;
		for (int x = x1; x <= x2; x++)
		{
			float y = m*x + b;
			PutPixel(x, y, c);
		}
	}
Now I Need To Draw A Triangle, Easy Right? Just Draw From The First Vert To The Next, And Then Loop Back To The First Vert ( Vert Means Vertice ). Well You See That Would Work, But Not With The Line Drawing Code That We Have Now. This Is What That Would Look Like...


....\..........
......\........
........\......
..........\....
............\..
............/..
........../....

Notice How The "Triangle's" Last Two Verts Don't Join? That's Because We Need To Do Some Tweaking To Our Line Code.

Ok, I'm Done With That, And I Would Show You The Functs, But We Have Enough Code In This Post, So... Here's The exe...
Defense On Earth 1 (BETA).zip
(463.41 KiB) Downloaded 199 times
Ok, So I Have The Triangles, I Have The Wireframe, But Now I Need To Learn How To Fill The Triangles. I Want To Fill Them One Of 2 Ways:
  • 1. I Want To Keep Drawing Triangles Of Slightly Smaller Dimensions Each Time
    2. I Can Make Lines That Fill Up The Triangle And Get Smaller Each Time
But, There's A Problem, I Don't Know How To Detect The Edges Of The Triangle...

*Read In SpongeBob Guys Voice* Two Days Later...
I Should Have Know, albinopapa's Got My Back. I Stole Some Of His Code, Put It In A Modified Framework (With Surface Buffer (If That's What That's Called)), Modified His Code And... BOW! Just Like That, I Have The "Thing" Rendered. I Spent Some Time Coming Up With A Way To Make The Back Triangles Not Visible, And I'm Done ( I Replaced The .zip Download Above With The New One). Now I Am Working On Rotation, Lighting And Rendering A Skybox.

Wait For It, Wait For It, Aanndd... FUCK YEAH!! We Have Made The Rotation, The "Skybox", Back Face Culling, And Now... We Have A Thing That You Can Control ( Replaced The Shit Up Top Again )!

Thanks To:
albinopapa: Basically Wrote All The Code
chili: Framework, Forum, Tits... I Mean Tuts
And Some Other Nameless Forumers. ( Jk: DicheBach, albinopapa (Again), And cameron )

But, This Wouldn't Be A Me Game Unless Something Dies In It, So Let's Go!
Last edited by goldengamesTM on December 22nd, 2017, 4:28 am, edited 19 times in total.

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

Re: I Don't Watch 3D Fund, But....

Post by chili » December 7th, 2017, 3:51 pm

Well, if you can draw a triangle you can do flat shaded graphics. Gonna need to learn about stuff like rotation and dot product though.
Chili

goldengamesTM

Re: I Don't Watch 3D Fund, But....

Post by goldengamesTM » December 7th, 2017, 4:17 pm

Yeah, I Don't Know What that Means....

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: I Don't Watch 3D Fund, But....

Post by albinopapa » December 8th, 2017, 12:32 am

What you have is rasterized triangles with mostly static points. If you want to be able use them in a game, you are most likely going to want to rotate them, so you must figure out how to rotate(spin or turn ) and transloate ( move ) each triangle vertex. Dot product is used in calculating lighting effects. If you have learned the Pythagorean theorem ( C^2 = A^2 + B^2 ) then you pretty much already now how to calculate the Dot Product of two vectors. It's just C = A^2 + B^2.

When you do the dot product between the direction of a light source and the normal of a surface (both vectors must have a length of 1) you get a value from -1 to 1 which tells you how intense the light being reflected should be.

If this is over your head, then you should at least watch Chili's old Advanced tutorials ( Vectors and Matrices ) portions.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

goldengamesTM

Re: I Don't Watch 3D Fund, But....

Post by goldengamesTM » December 8th, 2017, 2:43 pm

Thank You, But I See Lighting Way In The Future, But I Have A Good Idea For Rotation...
Last edited by goldengamesTM on December 12th, 2017, 2:28 pm, edited 1 time in total.

goldengamesTM

Re: I Don't Watch 3D Fund, But....

Post by goldengamesTM » December 8th, 2017, 3:27 pm

chili wrote:Well, if you can draw a triangle you can do flat shaded graphics. Gonna need to learn about stuff like rotation and dot product though.
Well, I Would If I Could Draw A Slanted Line, Could You Help?

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: I Don't Watch 3D Fund, But....

Post by albinopapa » December 8th, 2017, 6:15 pm

He covers how to draw a line in this video. Don't worry, it's not a 3D Fundamentals video, so you're good. It's lesson 10 from his old Beginner series.

PS: I copied the url from the point where he's about to go over how to draw lines at any angle, so click, watch and implement.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

goldengamesTM

Re: I Don't Watch 3D Fund, But....

Post by goldengamesTM » December 8th, 2017, 9:12 pm

Thank god for you.
Last edited by goldengamesTM on December 12th, 2017, 2:28 pm, edited 1 time in total.

goldengamesTM

Re: I Don't Watch 3D Fund, But....

Post by goldengamesTM » December 9th, 2017, 1:39 am

Hmm, it didn’t work, here’s my code...

Code: Select all

void DrawLine(int x1, int y1, int x2, int y2, Color c)
	{
		int dx = x2 - x1;
		int dy = y2 - y1;
		int m = dy / dx;
		int b = y1 - m*x1;
		for (int x = x1; x <= x2; x++)
		{
			int y = m*x + b;
			PutPixel(x, y, c);
		}
	}

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: I Don't Watch 3D Fund, But....

Post by albinopapa » December 9th, 2017, 6:36 am

Well, that's half the function, there's still the other half. That covers the case when dy > dx, the other half deals with the case where dx > dy.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply