Is there a reason why the default constructor for things like btVector3 doesn't initialize it to (0,0,0). I've written vector classes before and my implementations always had the constructor look something like this: Vector3(float x = 0.0f, float y = 0.0f, float z = 0.0f) so it would by default initialize the coords to (0,0,0)
I've been assuming it does and I finally got to test my game with Valgrind and found an amazing amount of uninitialized value errors because of this. Now every time I use a btVector3 I have to manually go in and set it to (0,0,0)? I have a lot of places where btVector3 objects are member variables of functions.
btVector3 and others not initialized to (0,0,0) by default?!
-
- Posts: 7
- Joined: Sat Jan 29, 2011 4:14 am
-
- Posts: 456
- Joined: Tue Dec 25, 2007 1:06 pm
Re: btVector3 and others not initialized to (0,0,0) by defau
I believe that this is done for speed (and not only for btVector3, for btQuaternion and btTransform too).
-
- Posts: 7
- Joined: Sun Jan 30, 2011 4:15 pm
Re: btVector3 and others not initialized to (0,0,0) by defau
Hah, I just ran into the exact same problem! Except it manifested itself in setting collision shapes with vertices in crazy far away positions, resulting in rigid bodies that didn't move. Very hard to find.
"Performance" is not a good reason for this, in my opinion. There should be a default constructor (as 80% of users will probably find useful), and those 20% looking to improve performance should initialise on creation.
"Performance" is not a good reason for this, in my opinion. There should be a default constructor (as 80% of users will probably find useful), and those 20% looking to improve performance should initialise on creation.
-
- Posts: 456
- Joined: Tue Dec 25, 2007 1:06 pm
Re: btVector3 and others not initialized to (0,0,0) by defau
It's always possible to extend these classes to get the behavior you're looking for in a backward compatible way (this is what I'm currently doing with the btTransform class). Some of the Bullet demos were probably made to show the performance of the library with a lot of bodies, and (maybe) that can be the reason of such a choice, but I agree with you (I like efficiency more than speed). Initialise on creation is good, but not comfortable in many cases (containers?).hymerman wrote:"Performance" is not a good reason for this, in my opinion. There should be a default constructor (as 80% of users will probably find useful), and those 20% looking to improve performance should initialise on creation.
-
- Posts: 141
- Joined: Tue Sep 16, 2008 11:31 am
Re: btVector3 and others not initialized to (0,0,0) by defau
Inventing stats does not make it truehymerman wrote:"Performance" is not a good reason for this, in my opinion. There should be a default constructor (as 80% of users will probably find useful), and those 20% looking to improve performance should initialise on creation.

-
- Posts: 7
- Joined: Sun Jan 30, 2011 4:15 pm
Re: btVector3 and others not initialized to (0,0,0) by defau
Sure, I understand why it's been done that way, I'm just saying I'd prefer a default constructor (and guessing that most other users would too). But then I like to do convoluted things like fill containers using std::generate or std::transform instead of default constructing and overwriting, to gain performance when I need to. I didn't mean literally 80% and 20%, I was just paraphrasing the 80/20 rule, but that wink tells me you know that 
