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:
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);
}
}
}
}
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);
}
}
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);
}
}
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);
}
}
....\..........
......\........
........\......
..........\....
............\..
............/..
........../....
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...
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
*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!