ENTITY XYZ
Blitz3D Forums/Blitz3D Programming/ENTITY XYZ
| ||
Has anyone run into any problems with comparing values returned from EntityX or entityY or entityZ? I have an instance where entityx(SPHEREA) does not equal entityx(SPHEREB) dispite the fact that i am displaying the values on the screen and they appear the same. I suspect that there maybe a rounding issue of some sort. I can overcome this easily by rounding to the decimal place that is being displayed ie 1.00001 but i dont know a math function to do the rounding. Is there something im missing? |
| ||
are you using entityx#(SPHEREA)? (with the '#') |
| ||
no i was using them without. but i tried it using the # and there is no difference. I beleive that it is an issue with taking the current location of an object, and the decimal precision is different than the precision of placing an object equal to a value... ie entityX(OBJECT1) returned does not equal the location after moveentity OBJECT1,LOCATIONX,0,0 i have written a roundign function to fix this decimal precision issue. but my concern is that this maybe an issue with other applications of entity functions where the precision may be off a bit. |
| ||
Instead of checking if EntityX/Y/Z are the same for two objects, I find it's best to use EntityDistance, with the distance being the precision of checking. If EntityDistance(ent1,ent2)<0.01 Then ... It can be as accurate or inaccurate as you wish, it takes up less space, and it's quite a fast check too! |
| ||
entity distance gives the distance only. I need to verify that one object is directly over another. Good idea but unfortunatly it doesnt help in this case. thanks though. I have overcomethis by rounding. It seems to work flawlessly. but i still have that extra non native function. I may write soemthing in c++ as a dll and use that to do my rounding. |
| ||
You may even have problems testing for equality on rounded numbers due to the nature of floating point, though it depends how your rounding function works I suppose. For instance you might find 1.345 rounds to 1.35 at two decimal places but a very slightly smaller value will round to 1.34. How about If Abs(x1#-x2#)<Epsilon# Then... as a quick test to see if two values are within a defined epsilon of each other. You can experiment with values for epsilon, but you can set it quite small and still erradicate the sort of precision errors you might get. |
| ||
actually what i was doing was int(VALUE * 100) / 100 it seems to work. the int conversion does a good job of rounding correctly. |