Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post Posted: April 11th, 2017, 10:35 am 
 

Joined: November 12th, 2016, 3:15 pm
Posts: 20
Hi,

the Ball doesn't bounce. I think it is because the GetRect function returns bullshit numbers. I added the program.

misterchi


Attachments:
FartAnnoyed.zip [756.3 KiB]
Downloaded 5 times
Top 
 Profile  
Reply with quote  
 Post Posted: April 11th, 2017, 1:59 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2669
Location: Oklahoma, United States
Take a look at these constructors, the second and third are incorrect.

Code:
RectF::RectF(float left, float right, float top, float bottom)
   :
   left(left),
   right(right),
   top(top),
   bottom(bottom)
{
}

RectF::RectF(Vec2 & topleft, Vec2 & bottomright) {
   RectF(topleft.x, bottomright.x, topleft.y, bottomright.y);
}

RectF::RectF(Vec2 & topleft, float height, float width) {
   RectF(topleft, topleft + Vec2(width, height));
}

_________________
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


Top 
 Profile  
Reply with quote  
 Post Posted: April 11th, 2017, 2:13 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2669
Location: Oklahoma, United States
Spoiler:
Code:
RectF::RectF( Vec2 & topleft, Vec2 & bottomright ) :
   RectF( topleft.x, bottomright.x, topleft.y, bottomright.y ){
}

RectF::RectF( Vec2 & topleft, float height, float width ) :
   RectF( topleft, topleft + Vec2( width, height ) ){
}

Using your coding style it should look something like this. I point that out simply because I find that the "one true brace" style makes code HARDER to look through. Sometimes it does look nicer, but I almost missed the fact the two constructors were messed up.

I find this to be more easily readable
Spoiler:
Code:
RectF::RectF( Vec2 & topleft, Vec2 & bottomright )
   :
   RectF( topleft.x, bottomright.x, topleft.y, bottomright.y )
{
}

RectF::RectF( Vec2 & topleft, float height, float width )
   :
   RectF( topleft, topleft + Vec2( width, height ) )
{
}


To each their own though. I'm not suggesting you change your style, I'm merely stating an opinion.

_________________
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


Top 
 Profile  
Reply with quote  
 Post Posted: April 12th, 2017, 8:43 am 
 

Joined: November 12th, 2016, 3:15 pm
Posts: 20
Hi albinopapa,

now I changed the constructors and it works fine. Thanks! But I don't understand why the constructors without ":" don't work. Thanks for your feedback about my codingstyle, too. It helps a lot.

misterchi


Top 
 Profile  
Reply with quote  
 Post Posted: April 12th, 2017, 2:23 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2669
Location: Oklahoma, United States
There are two parts to a constructor, the initializer list and the function body. The initializer list portion is everything between the : and the {} and is responsible for initializing class/struct members. The function body portion is treated like any other function and is used for initializing members that are more complicated to initialize like arrays for instance.

Putting RectF(5, 5, 10, 10) inside the function body would be similar to writing:
int{5};
instead of
int a = int{5}

You are making a temp RectF, but because of scoping rules, it is destroyed at the closing brace '}' because you never assigned it to anything, like
Code:
 *this = RectF(5, 5, 10, 10);
. Initialization through calling a constructor in the initializer list is built in to the standard, so it's understood that when calling a constructor in the initializer list you are telling the compiler to use a different constructor to initialize this object.

Hopefully, that explanation was helpful.

_________________
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


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 5 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: