Page 2 of 3

Re: 3D fundamentals snake

Posted: June 29th, 2017, 8:49 pm
by paulboon
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?

Re: 3D fundamentals snake

Posted: June 29th, 2017, 9:13 pm
by paulboon
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

Re: 3D fundamentals snake

Posted: June 29th, 2017, 9:53 pm
by paulboon
notification emails were landing in spam.
fixed it now so i'll respond quicker in the future

Re: 3D fundamentals snake

Posted: July 1st, 2017, 3:17 am
by albinopapa
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.

Re: 3D fundamentals snake

Posted: July 1st, 2017, 5:42 am
by chili
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.

Re: 3D fundamentals snake

Posted: July 1st, 2017, 8:10 am
by paulboon
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;

Re: 3D fundamentals snake

Posted: July 1st, 2017, 8:12 am
by albinopapa
Sweet, glad you figured that one out. Don't forget about the memory leak, I dare say that's the most important issue.

Re: 3D fundamentals snake

Posted: July 1st, 2017, 8:36 am
by albinopapa
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.

Re: 3D fundamentals snake

Posted: July 1st, 2017, 8:43 am
by paulboon
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.

Re: 3D fundamentals snake

Posted: July 1st, 2017, 8:49 am
by paulboon
btw what do you mean with "std vectors are move constructed"?