Hello everyone, Chris here - nub alert also asking for help on a concept

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
kristoff1313
Posts: 3
Joined: April 26th, 2020, 4:19 am

Hello everyone, Chris here - nub alert also asking for help on a concept

Post by kristoff1313 » May 4th, 2020, 3:55 am

Hey anyone who has too much time to read what I am about to puke up on here. I have been picking up a new hobby on a whim. Programming in C++. but wait there's more! 3d in c++, I'm in. Then I found Chili's personality on the youtubes (bonus!) <sigh> man he's got memes....I've liked it so much I patreon'd cause it is worth it. it's cheaper than guitar lessons monthly.

I said about 20 years ago I wanted to make a game instead of dying inside programming reports in c++ 6.0 and running a damn IBM mainframe operations with people twice my age. Id like to set out and do that. I can't decide which game I want to do yet but think like a DnD style turn based game 2d view except for action 3d FPS fighting maybe if it's possible. DnD, yeah i don't know why.. it was cool back int eh day til a few got high and started stabbing each other IRL. It's jsut one of the few things I never threw away after moving 50 times in my life. So i guess that is my reason why.
So i am starting out small and following the tutorials and breaking stuff and fixing it, while trying to remember the correct way of doing it. I don't have anyone I can code with that i know, so I am reaching out here.

I have went through to tutorial 15 or 16 and working 30+ days in a row I am mentally fried. I installed VS 2019 and using v142 tools and just c++ and a little direct X and windows SDK for setup.
I got a repo set up and branched for this test.: https://github.com/apeproject/MAGE.git
I walked through the ChiliFramework and formatted to my style. It didn't need it but I am OCD sometimes.

I eventually plan on writing my own some day that i know the inner workings of a 3d engine. Completely unnecessary but, <bobby duke>-" I want that". A friend and I wrote a simple one back in the day when D3d9 and .net were having sex and you could write all this in beginner c# to run slower. The whole thing was to make a damn matrix screen saver with scrolling gifs and flashing and colors. He was definitely high and I was at least on a contact high getting to this as a great idea after modding diablo II for 14 hours several nights in a row. Or was it COD4.. it was all a blur. I only remember driving off the highway at 10am going to get breakfast the last morning. We had super speed to make you motion sick and then made a tiny chicken blow up in a bloody mess that was 20 times its size on screen. That was the pinnacle for us with that game. (we're all good no cops or highway retainers were damaged in that trip)

so after that minimal intro, and saying how green I am, I am trying to figure out a order of screen draw and bounds checking routine that I cannot shake. Chili challenged about find out about other bounds for collision but I am taking it little further i guess. The array factor and then using a poop ton of if statements to check boxes overlapping areas and then merging their colors for like a screen saver type app is the goal. I'm about 90% with what tools I know so far. I'm starting with squares, then random rectangles then circles and moving shapes (expand, contracting objects) if I keep it alive on the side. I am stuck on the overlapping area call cycling through the boxes in order they are drawn to screen. if you compile and run it you will see where I can't figure out what i am missing.

this little apps should be simple enough and probably not sure if it will be useful for anything else but learning tool for myself (or anyone else that wants it).

I look forward to meeting any of you and any knowledge I can get in the exchange!
Attachments
MAGE.zip
(67.1 KiB) Downloaded 126 times

kristoff1313
Posts: 3
Joined: April 26th, 2020, 4:19 am

Re: Hello everyone, Chris here - nub alert also asking for help on a concept

Post by kristoff1313 » May 4th, 2020, 6:24 am

adding updated clean up script i use with 7zip, like what chili has listed but i needed moar.
drag/drop solution folder onto the batch and it does the work

echo Using Directory you dropped on my ****, "%~1"
echo y|del %~1\*.txt
echo y|del %~1\*.sdf
rmdir /s /q "%~1\Release"
rmdir /s /q "%~1\Debug"
rmdir /s /q "%~1\x64"
rmdir /s /q "%~1\Engine\Release"
rmdir /s /q "%~1\Engine\Debug"
rmdir /s /q "%~1\Engine\x64"
rmdir /s /q "%~1\.git"
rmdir /s /q "%~1\.vs"
rmdir /s /q "%~1\License
echo y|del "%~1\.gitattributes"
echo y|del "%~1\.gitignore"
REM and zip that ****
@ECHO ON
FOR /F "TOKENS=*" %%F IN ('DIR /B /A-D "%~1"') DO "C:\Program Files\7-Zip\7z.exe" a -r "%~1.zip" "%~1" -sdel
EXIT /b=0

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

Re: Hello everyone, Chris here - nub alert also asking for help on a concept

Post by albinopapa » May 4th, 2020, 9:21 am

Nooo, don't remove the .git directory and .gitignore man. The .git directory holds all past commit info so you can or a team mate can go back if you/they f*ck something up. The .gitignore file is used to ignore crap files that don't need to be included when you sync your project with the git repository.

Anyway, your if block for overlap:

Code: Select all

if (boxes[i].left < boxes[j].right && 
	!(boxes[i].left < boxes[j].left && 
	boxes[i].right < boxes[j].right)) { // i's left overlaps j's right only
	overlapX1 = boxes[i].left;
	overlapX2 = boxes[j].right;
	}	else if (boxes[i].right > boxes[j].left && 
	!(boxes[i].right > boxes[j].right && 
	boxes[i].left > boxes[j].left)){ // i's right overlaps j's left only
	overlapX1 = boxes[j].left;
	overlapX2 = boxes[i].right;
	} else if (boxes[i].left < boxes[j].left && 
	boxes[i].right > boxes[j].right) { // i is covering j left and right
	overlapX1 = boxes[j].left;
	overlapX2 = boxes[j].right;
	}	else { // i is covered by j left and right
	overlapX1 = boxes[i].left;
	overlapX2 = boxes[i].right;
	}
	// Y VALUES
if (boxes[i].top < boxes[j].bottom && 
	!(boxes[i].top < boxes[j].top && 
	boxes[i].bottom < boxes[j].bottom)) { // i top cover j bottom only
	overlapY1 = boxes[i].top;
	overlapY2 = boxes[j].bottom;
	} else if (boxes[i].bottom > boxes[j].top && 
	!(boxes[i].bottom > boxes[j].bottom && 
	boxes[i].top > boxes[j].top)){ // i bottom covers j top only
	overlapY1 = boxes[j].top;
	overlapY2 = boxes[i].bottom;
	}	else if (boxes[i].top < boxes[j].top && 
	boxes[i].bottom > boxes[j].bottom) { // i covers j top and bottom
	overlapY1 = boxes[j].top;
	overlapY2 = boxes[j].bottom;
	}	else { // j covers i top and bottom
	overlapY1 = boxes[i].top;
	overlapY2 = boxes[i].bottom;
	}
Is as simple as:

Code: Select all

overlapX1 = std::max( b0.left, b1.left );
overlapY1 = std::max( b0.top, b1.top );
overlapX2 = std::min( b0.right, b1.right );
overlapY2 = std::min( b0.bottom, b1.bottom );
Since you are already checking for overlap, you want to left most edge of either box to be the overlapX1 and least right edge of either box to be overlapX2. Same situation with overlapY1/2.

There are some other things I'd like to bring up about the code:

Code: Select all

bool overLapped = TRUE; // just to make it easier to see in debugging
The TRUE macro is just an integer defined as the number 1. It's better to use the C++ true keyword instead.

Code: Select all

bool overLapped = true;
Also here:

Code: Select all

overLapped = NULL; //wipe for next frame in case there is no overlap, or make  memory leak
overLapped is a stack allocated variable that doesn't require any changing or deallocating before it goes out of scope. Aside from that NULL is meant to nullify pointers and not really meant to set integral values or boolean values. To change a bool, use true or false all lowercase. Types like bool, char, short, int, long, float and double do not need to be cleared at the end of a function when they are declared in that function. Types like int*, are called pointers and they will leak memory if you do not 'delete' them before leaving their scope.

Also, some info on colors. In grade school we are taught that Red, Yellow and Blue were the primary colors, but this isn't actually the case exactly. Red, Yellow and Blue are the primary pigment colors, but Red, Green and Blue are the primary light colors. Even then, some say Cyan, Magenta and Yellow are the primary colors. So as far as the sensors in our eyes we have red, green and blue receptors. In the light spectrum, orange and yellow sit between red and green so yellow is made from mixing red and green light. Light colors are categorized as additive colors and pigments are subtractive colors. This is probably why CYM are considered to be primary. If you mix Cyan and Yellow, you get Green. If you mix Yellow and Magenta you get Red. If you mix Cyan and Magenta you get Blue.

Code: Select all

Cyan   ( 000, 255, 255 ) -
Yellow( 255, 255, 000 ) = 
Green( 000, 255, 000 )

Cyan     ( 000, 255, 255 ) - 
Magenta( 255, 000, 255 ) = 
Blue      ( 000, 000, 255 )

Yellow   ( 255, 255, 000 ) - 
Magenta( 255, 000, 255 ) = 
Red       ( 255, 000, 000 )
In C++, it looks like you can do some bitwise ands to get these conversions.
Color c3 = Colors::Yellow.dword & Colors::Magenta.dword; //

Image

Code: Select all

const auto c3 = Color{
	unsigned char( c1.GetR() & c2.GetR() ),
	unsigned char( c1.GetG() & c2.GetG() ),
	unsigned char( c1.GetB() & c2.GetB() )
};
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

kristoff1313
Posts: 3
Joined: April 26th, 2020, 4:19 am

Re: Hello everyone, Chris here - nub alert also asking for help on a concept

Post by kristoff1313 » May 4th, 2020, 5:06 pm

Thanks for the reply Albinopapa!
for the script, it is just for posting it here. I just re-pull with rebase from git, since I save my progress there to pull it up at work or from home.
I just scrub the directory to keep it super small and just to the relevant code. Should I take it down in case someone else new like me uses it and screws themselves?

For the overlap thing, that makes it nice and tight. I think I will have look up a good reference on the std library. I only seen the random gen and swap thing so far from the tut vids.

I looked on google and dun quite grasp it. is the "TRUE" a macro that just stores or converts to int 1 and it works because bools are just 1 or 0 really on compiled code? But either way, as you say the standard is, I will try to do that from now on, thanks.

understand that sort of. Null a pointer so it doesn't point to memory before i gets destroyed, but variables calls like that in current scope get garbage collected at end of scope execution?(i'll have to look up heap and stack to understand that against what i am writing) Taking in a lot trying to keep it all straight.

The colors, I'm gonna have to take a minute and reread that. i had art electives all up til college and we never went over that since what we learned in grade school.

Thank you for all your feedback, especially for someone essentially just starting out like me.

Chris (kristoff)

Post Reply