Problems with BEPU in windows phone

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
jbosch
Posts: 43
Joined: Sat May 29, 2010 4:42 pm
Contact:

Problems with BEPU in windows phone

Post by jbosch »

Hi,

I published a game based on bepu physics engine in the windows phone 7 marketplace. The game runs smoothly in the emulator, but in the real device, some "strange" things happen: the ball changes its direction suddenly, the performance decreases a lot when the ball hits the first pin, even sometimes the ball crosses the ground and falls under it... I feel frustrate because I can't debug this behaviour in the emulator. Any idea?

http://www.youtube.com/watch?v=_76CCogvxDk
Jesús Bosch
XNA BLOG: http://geeks.ms/blogs/jbosch
Danthekilla
Posts: 136
Joined: Sun Jan 17, 2010 11:35 am

Re: Problems with BEPU in windows phone

Post by Danthekilla »

Well the first problem is that you need to test it on a device as the emulator can be up to 25 times faster than a device.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Problems with BEPU in windows phone

Post by Norbo »

You might want to verify that the vertices and indices that the collision mesh is being made from matches between platforms. Strange behavior with the content loading has been reported before on the device that doesn't appear in the emulator, although I have no idea what would cause it.

The BEPUphysicsDrawer can draw the TriangleMesh object used to construct your model. It will draw whatever the collision mesh is; this might reveal something wonky.
jbosch
Posts: 43
Joined: Sat May 29, 2010 4:42 pm
Contact:

Re: Problems with BEPU in windows phone

Post by jbosch »

I can't find any way to speed up the game when the ball hits the pins. Any idea?

thanks
Jesús Bosch
XNA BLOG: http://geeks.ms/blogs/jbosch
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Problems with BEPU in windows phone

Post by Norbo »

Is it a performance problem, or are you just trying to make the actual simulation appear to move faster? If it's the latter, you could try increasing the gravity some until it feels right (careful, if you go too high, you can introduce instability which may require more iterations or a smaller timestep to fix).

For performance, you can try messing with the collision response setting's iteration count. Very low counts (1-4) will be quicker than the default (10), but you'll have to test to see how low you can go before the lack of accuracy becomes apparent.

If I remember right, you're using cylinders for the pins, which should be fine. If I remember wrong and you're actually using ConvexHulls, you might try simplifying the collision mesh some or using cylinders.

However, 10 pins and a ball should really run fine, even on a phone. If there are performance problems, it's probably something less obvious.
jbosch
Posts: 43
Joined: Sat May 29, 2010 4:42 pm
Contact:

Re: Problems with BEPU in windows phone

Post by jbosch »

Hi, after many tests with the device, I've seen two main things:

-I cant undersrand the differences in the behavior.
-My pins are set to kynematic before each launch.When the ball is in a short distance, I make them dynamic, and it seems that causes problems. But if I dont do this, some pins start dancing and some fall. Is there a better solution for this?
-I also create new instances of ball and pins each turn. This probably generates garbage, but I need to do so because if not I cant find the way to "reset" the physical properties of the entities.

Can you sugest something better? Thanks.
Jesús Bosch
XNA BLOG: http://geeks.ms/blogs/jbosch
jbosch
Posts: 43
Joined: Sat May 29, 2010 4:42 pm
Contact:

Re: Problems with BEPU in windows phone

Post by jbosch »

Norbo wrote:Is it a performance problem, or are you just trying to make the actual simulation appear to move faster? If it's the latter, you could try increasing the gravity some until it feels right (careful, if you go too high, you can introduce instability which may require more iterations or a smaller timestep to fix).

For performance, you can try messing with the collision response setting's iteration count. Very low counts (1-4) will be quicker than the default (10), but you'll have to test to see how low you can go before the lack of accuracy becomes apparent.

If I remember right, you're using cylinders for the pins, which should be fine. If I remember wrong and you're actually using ConvexHulls, you might try simplifying the collision mesh some or using cylinders.

However, 10 pins and a ball should really run fine, even on a phone. If there are performance problems, it's probably something less obvious.
By the way, how do we change the collision detection settings? Thanks
Jesús Bosch
XNA BLOG: http://geeks.ms/blogs/jbosch
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Problems with BEPU in windows phone

Post by Norbo »

I also create new instances of ball and pins each turn. This probably generates garbage, but I need to do so because if not I cant find the way to "reset" the physical properties of the entities.
That does create garbage, but it's 'rare' (once every several seconds) and a pretty small amount of garbage so it might not even be something to be worried about. If you do want to get rid of it, the only thing you should have to do to reset them is set the position, orientation, linear velocity, and angular velocity back to their starting values. Linear/angular velocity's initial values are both zero vectors.
My pins are set to kynematic before each launch.When the ball is in a short distance, I make them dynamic, and it seems that causes problems. But if I dont do this, some pins start dancing and some fall. Is there a better solution for this?
Does the dancing happen on Windows/WP7 emulator? If it's only happening on an actual device, the best solution (and the only one guaranteed to work, unfortunately) is to try and figure out what's up with the device. Making them dynamic shouldn't really cause issues either.

If the dancing happens on the emulator as well, then it's more likely related to the size ratios of cylinders/triangles involved. I'd have to see the exact behavior in action to know, but the size ratio issue is pretty common.
By the way, how do we change the collision detection settings? Thanks
Collision detection settings can be found in the space.SimulationSettings.CollisionDetection class. Collision response settings (including the iteration count) can be found in the space.SimulationSettings.CollisionResponse class.
jbosch
Posts: 43
Joined: Sat May 29, 2010 4:42 pm
Contact:

Re: Problems with BEPU in windows phone

Post by jbosch »

Hi there,

I followed your recommendations,and the performance has improved a 300%

Now I created a new problem, and it is that the ball does not move very reallistically. It seems like it is not being affected by the gravity or something similar. Please have a look at this video:

http://www.easy-share.com/1913001082/Sc ... 17-11-2010 18.49.49.wmv

Do you know which could be the reason for that behaviour and how to solve it?

Thanks in advance.
Jesús Bosch
XNA BLOG: http://geeks.ms/blogs/jbosch
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Problems with BEPU in windows phone

Post by Norbo »

I can't really tell for sure, but it almost looks like the ball is kinematic.

By the way, are you using a content processor to collect collision mesh data? If not, I would recommend it.
Post Reply