www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: urubu on June 14, 2012, 06:12:34 pm

Title: strange results from getWorldSpaceBounds (sample on jpct wiki) [solved]
Post by: urubu on June 14, 2012, 06:12:34 pm
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?



Title: Re: strange results from getWorldSpaceBounds (sample on jpct wiki)
Post by: EgonOlsen on June 14, 2012, 08:33:14 pm
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?
Title: Re: strange results from getWorldSpaceBounds (sample on jpct wiki)
Post by: urubu on June 15, 2012, 12:58:19 am
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.
Title: Re: strange results from getWorldSpaceBounds (sample on jpct wiki) [solved]
Post by: urubu on June 15, 2012, 01:04:30 pm
I did some more testing and now I am using -Float.MAX_VALUE instead of Float.MIN_VALUE. I am using:
Code: [Select]
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:
Code: [Select]
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.
Title: Re: strange results from getWorldSpaceBounds (sample on jpct wiki) [solved]
Post by: EgonOlsen on June 16, 2012, 10:37:04 am
I've modified the code in the wiki. Thanks for finding that flaw.