Collision/ bounding box issue

hey everyone,



so me and few of my friends are using Jme to build a simple Labyrinth board game for our CS class, and we are making the physics engine(albeit very simple) for it currently.



for those of you who don’t know what game im talking about, heres a pic from google of a board, it will be pretty obvious after looking at it

http://blog.makezine.com/labyrinthxymechanism.jpg



so far im able to rotate the board, and apply gravity to the ball, and when it collides, the ball bounces up, and eventually comes to a pretty much equal state(theres a bug there, but not as important)



our main problem is that it doesn’t seem that the collision detection is working correctly. im pretty sure i just missed something, but heres what we are doing in a nut shell:



the ball has a boundingsphere, the board has an OrientedBoundingBox.

when the board rotates, so does the boundingbox. or so i think, i’ve tried everything from creating a new model bound every frame(bad but hell im desparate) calling updateModelbounds, each frame, and tried calling getWorldBounds().transform() and gave it the same quaternion im passing the board.



when i rotate the board however, and apply a x or z force to move the ball laterally, it does some very strange things. the ball “collides” with an invisible bounding box(i have Debugger.drawbounds on) or so it seems, and when the board is tilted, it goes down, but only until the ball leaves the space where the board originally starts at, and then falls through the board not detecting anymore collisions.



if you think you need to see the source, its only a few files right now, but its pretty unorganized.



any help would be greatly appreciated!



irishguy

Just to be sure: are You using jmephysics for this ?

did you call updateGeometricState anywhere?

@winkman: no im not using Jmephysics, because our project is to make the physics of the game. we are just using simply newtonian formulas and vector math to calculate stuff.



@HamsterOfDeath: yes i am calling updateGeometricState, on all of the objects in the game just to be sure, and still no joy. :frowning:





any other ideas, or do i need to upload some code?

No idea, so let us take a look at the code, i'd say.



edit: a simplified example to show off the problem would be preferred

Bounds are not really suited for this kind of collision detection (esp. because of the rotation). Box-sphere collision is quite easy, maybe you should just implement it yourself?



Another option would be to use jME Physics 2 :slight_smile: - it's hard enough to use a physics engine :wink:

so before i get to the code, i made one possibly important discovery about whats going wrong.



ok so heres my new problem, collision is working, but when i rotate the board, the path the ball travels is the opposite!!! :-o



for instance, when i rotate the board around its center counterclockwise, the invisible board seems to rotate clockwise!!!

so then the ball bounces up into the air along an invisible surface ,instead of down the boards surface.



so obviously, im rotating the board wrong.



i have tried rotating the board using the .setLocalRotation(quaternion) for both the board, and separately tried rotating the node. same effect, but no fix, and really wouldn't expect it either.



so here is my board update routine.


    public void update(float interpolation)
    {
       resultQuat.fromAngles(FastMath.DEG_TO_RAD*ourX, FastMath.DEG_TO_RAD*ourY, FastMath.DEG_TO_RAD*ourZ);
       
       this.setLocalRotation(resultQuat);
       
       this.updateModelBound();
       this.updateRenderState();
       this.updateWorldBound();
       this.updateGeometricState(interpolation, true);
       



the ourX, Y , and Z variables are set by the inputhandler and processed every frame.

hopefully you guys see whats going wrong, if not i'll post the entire project,(6 files so far) if need be.

again thanks guys,

alright i’m putting up the project in a zip file for you guys to download



http://irishguy.110mb.com/ourProject.zip



the source should easily import into eclipse if you have it. also, the code is pretty messy. sorry for this.  :oops:



anyways, run it and tell me what you guys think is wrong.



again thanks in advance.



edit:

oh yea. buttons and controls.

WASD for camera, it follows a dome shaped path

QZ for zoom out zoom in respectively

IJKL for board rotation.

M to apply a Z force to the ball(comes at the camera)

B drops the board. (for testing purposes)

Alright mate,



I just browsed through your code quickly and just couple of observations. In Labyrinth.java in line 89 to detect collision between two bounds you use:


if (ball.getWorldBound().intersects(board.getWorldBound()))



if you want to detect collision between two bounds why not use

if(ball.hasCollision(board, false))



Its really simple and fast and works well for me. Another thing, you have not called scene.updateGeometricState(0f, true) in the whole loop (if(dropBall)) starting at line 80. I would place this at line 131 - uncommenting yours. My guess would be this is the cause of the problem.

irishguy said:

for instance, when i rotate the board around its center counterclockwise, the invisible board seems to rotate clockwise!!!

That's what I meant with rotation issues: Oriented bounding boxed do not guarantee to rotate like the mesh. Most likely OBBs are not suited for this case.

@hawk – yea i had those in there and changed them out for some reason. i tried them and it didn't seem to work though  :frowning: oh well.



@irrisor – ok so i see what you mean now. but how do i do detection otherwise? i've looked at the testCollision tree example and tried to implement triangle collision detection but that doesn't work either. what now?

If this is a school assignment, you could create your bounding volumes yourself… and manage them and then know exactly if they are oriented in the right direction or not. Just a though 

irishguy said:

@irrisor -- ok so i see what you mean now. but how do i do detection otherwise? i've looked at the testCollision tree example and tried to implement triangle collision detection but that doesn't work either. what now?

using triangle collisions should word - but it would be quite costly. As I already wrote I would recommend the same as duenez.