Advertisement

Pointer != Pointer

Started by May 26, 2000 01:32 AM
2 comments, last by jLeslie 24 years, 6 months ago
Ok I''ve been working on some boundingbox code to make my 3d models follow the contours of the ground....At the start of the loop I test two variables to see if I need to recalculate anything. BottomCenter, and TopCenter are pointers to a D3DVERTEX struct. PHYSICSCLASS* Ground = cLand->ObjBase; if (BottomCenter->y != Ground->TopCenter->y) { ... } The first time that BottomCenter->y and TopCenter->y are equal the loop still executes anyways....but the next time that they''re the same it doesn''t. Does this have something to do with the fact that they''re pointers? I''ve tried dereferencing them but it doesn''t seem to make any difference, the loop still gets executed the first time the values are equal.
If you are comparing floating point values they may seem to be equal, but aren''t actually equal due to rounding error. Perhaps there is an error in the way that you are setting the two y values. The fact that you are using pointers doesn''t seem like it would make a difference in this case.
Advertisement
If you are having float rounding problems you can try to change the test to something like this:

if (abs(BottomCenter->y - Ground->TopCenter->y) > 0.001)
// or some other 'small' number
{
...
}

Hope that helps


Edited by - chippydip on May 26, 2000 11:49:25 AM
Now I can finally sleep in peace

Edited by - jLeslie on May 26, 2000 3:03:19 PM

This topic is closed to new replies.

Advertisement