3D fundamentals snake

The Partridge Family were neither partridges nor a family. Discuss.
paulboon
Posts: 14
Joined: February 11th, 2017, 3:02 pm

Re: 3D fundamentals snake

Post by paulboon » June 29th, 2017, 8:49 pm

sorry i didn't respond for so long.
i'll upload a cleaned solution but i think meeting on discord would be faster to quikly explain.
btw i'm not receiving emails from this thread altough it says i'm subscribed?
Last edited by paulboon on June 29th, 2017, 9:43 pm, edited 1 time in total.

paulboon
Posts: 14
Joined: February 11th, 2017, 3:02 pm

Re: 3D fundamentals snake

Post by paulboon » June 29th, 2017, 9:13 pm

this is the solution
maybe i made a mistake cleaning it but i couldn't find the video were it explained the steps for cleaning.

i'll be sitting in the general discord chat for a couple hours to that way talking back and forth would be a lot quicker
Attachments
Engine.zip
(1.75 MiB) Downloaded 126 times

paulboon
Posts: 14
Joined: February 11th, 2017, 3:02 pm

Re: 3D fundamentals snake

Post by paulboon » June 29th, 2017, 9:53 pm

notification emails were landing in spam.
fixed it now so i'll respond quicker in the future

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

Re: 3D fundamentals snake

Post by albinopapa » July 1st, 2017, 3:17 am

Haven't gotten to the missing pixel issue, BUT you are leaking memory (BADLY). Each frame you are allocating a new LitShader and never deleting it. In Release mode, mem was leaking about 1 MB every 8 seconds on my computer.
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

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

Re: 3D fundamentals snake

Post by chili » July 1st, 2017, 5:42 am

Nice to see some stuff being made with the 3D Fundamentals graphics subsystem. Like papa, I'm not sure about some of the design / coding decisions you've made, but the fact that you are trying to do it yourself and get that understanding of how the theory works is very impressive, so keep up the good work.
Chili

paulboon
Posts: 14
Joined: February 11th, 2017, 3:02 pm

Re: 3D fundamentals snake

Post by paulboon » July 1st, 2017, 8:10 am

Issue solved.
The probem was the counter variable in EdgeWalker being an int instead of a float which caused rounding issues.
also i was rounding it down in the constructor which wasn't nescessary and left gaps.

struct EdgeWalker : public IEdgeCodeGetter {
int counter;<------------should be: float counter
std::map<EdgeWalkerCode, float> posMap;
std::map<EdgeWalkerCode, float> incsMap;
Last edited by paulboon on July 1st, 2017, 8:12 am, edited 1 time in total.

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

Re: 3D fundamentals snake

Post by albinopapa » July 1st, 2017, 8:12 am

Sweet, glad you figured that one out. Don't forget about the memory leak, I dare say that's the most important issue.
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

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

Re: 3D fundamentals snake

Post by albinopapa » July 1st, 2017, 8:36 am

I'm going to go out on a limb here and say you came from a managed language, maybe something like C# or Java judging by your code. You do object oriented programming and some of your struct/classes are pretty abstract, like the Vector classes, so I feel you have experience with OOP languages. C++ offers operator overloading which would eliminate your math functions from your Vector and Matrix classes and make the code a lot more readable IMO. Also, you can use the constructor instead of having to make a separate copy function, a bonus is the copy constructor and copy assignment operator are usually made for you, so you don't have to declare or define them.

Something like this:

Code: Select all

Vector3 lerp( const Vector3 &Dest, float Weight )const
{
	return *this + ( ( Dest - *this ) * Weight );
}
would be a lot more readable than:

Code: Select all

Vector3 lerp(Vector3& v, float weight)
{
	return c().add( v.c().sub( ( *this ) ).scale( weight ) );
}
I spent more time than I'd like to admit trying to refactor the code to using overloaded operators, however, I found there were going to be places that I would mess up on. The reason being your math functions take in a reference and return a new instance of a Vector2/Vector3.

In some places in your code, you use the return value, and in some places you don't. Since your math functions also modify the instance, you are having to make copies in order to leave the original as-is. As I said, you can do this with the constructor instead of having to create a separate function. If you kept your code the same and removed the c() function, it would look like:

Code: Select all

Vector3 lerp(Vector3& v, float weight)
{
	return Vector3( *this ).add( Vector3( v ).sub( ( *this ) ).scale( weight ) );
}
Anyway, it's your style, just wanted to point out somethings that you might not have known.

I would suggest more than anything to look into passing parameters by const reference, especially those std::vectors. Most of the time you are creating them as you pass them, so it may not make a difference in those places as the std::vectors are move constructed into those parameters. Just something you might look into, passing by const reference and move semantics.
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

paulboon
Posts: 14
Joined: February 11th, 2017, 3:02 pm

Re: 3D fundamentals snake

Post by paulboon » July 1st, 2017, 8:43 am

I prefer overloaded operators too but i couldn't get them to work.
I was getting a lot of compiler errors for reasons i didn't understand so i took the easy way out.

paulboon
Posts: 14
Joined: February 11th, 2017, 3:02 pm

Re: 3D fundamentals snake

Post by paulboon » July 1st, 2017, 8:49 am

btw what do you mean with "std vectors are move constructed"?

Post Reply