strange results from getWorldSpaceBounds (sample on jpct wiki) [solved]

Started by urubu, June 14, 2012, 06:12:34 PM

Previous topic - Next topic

urubu

I have an object3d that is a cube initially set at (0,0,0).
When I invoke getWorldSpaceBounds for this cube I get (0,0,0) and (1,1,1) that I think is the expected result.

I then do a lot of rotations and translation on this cube. Each individual rotation is always 180dg or -180dg around one of the axis so that the cube local coordinate axis are kept parallel to the world axis (the sides of the cube are always parallel to the screen)

I then calculate the size of the sides of the returned bounding box (using the world bounds) using w=maxX-minX, h=maxY-minY, d=maxZ-minZ. I would expect this to always be 1,1,1 and it is most of the time. The problem is that after some rotations/translations I begin to get strange values for w,h,d like 3,2,1.

Am I missing anything?




EgonOlsen

Sounds strange. I would expect the result to be 1,1,1 (more or less...) all the time and i can't see a flaw in the method in the wiki at first glance. Can you post a simple test case for this?

urubu

I just spotted something that does not sound right.
maxX,maxY,maxZ are initialized with Float.MIN_VALUE. This is defined as the smallest positive float number and the logic of the method does not seem to work if the coordinates have negative numbers.

I did a quick test changing those values to be -150000 and then I always got the expected results.

urubu

I did some more testing and now I am using -Float.MAX_VALUE instead of Float.MIN_VALUE. I am using:

float minX = Float.MAX_VALUE, minY = Float.MAX_VALUE, minZ = Float.MAX_VALUE, maxX = -Float.MAX_VALUE, maxY = -Float.MAX_VALUE, maxZ = -Float.MAX_VALUE;

Instead of:

float minX = Float.MAX_VALUE, minY = Float.MAX_VALUE, minZ = Float.MAX_VALUE, maxX = Float.MIN_VALUE, maxY = Float.MIN_VALUE, maxZ = Float.MIN_VALUE;


This has fixed my problem. I suggest the wiki to be updated.

EgonOlsen

I've modified the code in the wiki. Thanks for finding that flaw.