Author Topic: strange results from getWorldSpaceBounds (sample on jpct wiki) [solved]  (Read 2376 times)

Offline urubu

  • byte
  • *
  • Posts: 11
    • View Profile
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?



« Last Edit: June 15, 2012, 01:17:06 pm by urubu »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: strange results from getWorldSpaceBounds (sample on jpct wiki)
« Reply #1 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?

Offline urubu

  • byte
  • *
  • Posts: 11
    • View Profile
Re: strange results from getWorldSpaceBounds (sample on jpct wiki)
« Reply #2 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.

Offline urubu

  • byte
  • *
  • Posts: 11
    • View Profile
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
I've modified the code in the wiki. Thanks for finding that flaw.