Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


pointers to build Bounding box

This topic is 6308 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m building a bounding box hierarchy for collision detection using a BBox class to build a hierarchy for a diamond shaped object. The diamond first creates the first bounding box and then calls on its sort and split functions,to sort its triangles and split up evenly to make two new boxes. I send the split box function two poniter address which it should change into the min and max extends of my new bounding box (Which are stored as vectors), but I getting the following error when I try to compile diamond.cpp: "cannot convert parameter 1 from ''class CVector** '' to class CVector * '' " This is the code in the diamond class giving me an error //create box to completly enclose diamond box[0] box[0]=BBox(numTriangles,triangles,vertices,initPos); //create new vectors to store min and max extends of child boxes CVector newMin=CVector(0,0,0); CVector newMax=CVector(0,0,0); //create pointers to the above vectors CVector *newMinR; newMinR=&newMin; CVector *newMaxR; newMaxR=&newMax; //sort the triangles stored in box[0] box[0].XSortTriangles(); //send the address of the two vectors split box //this should change them to the correct value box[0].splitBox(&newMinR,&newMaxR); THE LAST LINE HERE GIVES THE AFFORMENTIONED ERROR. Anyone know what I''m doing wrong?? the function Split box accepts two pointers as arguments?? void BBox::splitBox(CVector *newMinR,CVector *newMaxR)

Share this post

Link to post
Share on other sites
SplitBox takes a pointer, you are passing it the address of a pointer. The address of a pointer is a pointer to a pointer, or in this case a CVector **. You can either change the paramiter in splitBox to
void BBox::splitBox(CVector **newMinR,CVector **newMaxR)

and in splitBox *newMinR = temp; will change the pointer passed in by the caller to point to temp. *newMinR->x will allow you to access CVector''s x member. This is ugly as hell, which is why you should use this syntax when changing a pointer passed as a paramiter. It is generally considered bad form to do this, as you are really begging for a memory leak.

You could also have splitBox(CVector *&newMinR,CVector *&newMaxR)
in this case you would just call as splitBox(min,max) and min and max would be changed to point to new things automagically. Then calling min = new CVector(0,0,0); will leak, unless you keep a backup pointer, and make sure to delete the backup if, and only if, splitBox changes what min points to.

You don''t seem to have any need for this, as all you really seem to want is two CVectors set to the min and max extents. In this case, just use splitBox(CVector &min, CVector &max) and call it with splitBox(newMin,newMax);

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!