Jump to content

Initial rotation on physics-enabled objects


mediabounds
 Share

Recommended Posts

I'm getting up-to-speed on developing with Babylon.js and I'm having a problem with physics simulations and initial rotation on a mesh:

post-9762-0-61804200-1406048082.gif

 

You'll notice that the box and the ball bounce off the air above the "ground."

 

My expectation is that both the box and the ball would land on the surface of the ground. It works as expected if there is no initial rotation. The greater the rotation, the more obvious the problem. Here's how I'm rotating the ground:

var ground = BABYLON.Mesh.CreateBox("ground", 10, scene);ground.rotate(BABYLON.Axis.Z, .3, BABYLON.Space.LOCAL);ground.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, {mass:0, friction:0.5, restitution: 0.4});

If it helps, here's all the code I'm using to create the scene:

var createPrototypeScene = function(engine) {var scene = new BABYLON.Scene(engine);var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 10, -40), scene);var light0 = new BABYLON.DirectionalLight("Omni", new BABYLON.Vector3(-2, -5, 2), scene);var light1 = new BABYLON.PointLight("Omni", new BABYLON.Vector3(2, -5, -2), scene);camera.setTarget(new BABYLON.Vector3(0, 0, 0));scene.enablePhysics(null, new BABYLON.CannonJSPlugin());// Create the groundvar ground = BABYLON.Mesh.CreateBox("ground", 10, scene);ground.rotate(BABYLON.Axis.Z, .3, BABYLON.Space.LOCAL);ground.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, {mass:0, friction:0.5, restitution: 0.4});// Create the ballvar ball = BABYLON.Mesh.CreateSphere("ball", 16, 1, scene);ball.material = new BABYLON.StandardMaterial("ball", scene);ball.material.wireframe = true;ball.position = new BABYLON.Vector3(3, 20, 0);ball.setPhysicsState(BABYLON.PhysicsEngine.SphereImpostor, { mass: 5 });var box = BABYLON.Mesh.CreateBox("box", 3, scene);box.position = new BABYLON.Vector3(0, 15, 0);box.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, {mass: 1});return scene;}

Thanks!

 

Link to comment
Share on other sites

Quite strange really, I took wingnut example, and added another box and sphere 1 pixel bigger, then I parented them to the first ones, and the problem got a bit better. I think that maybe cannon.js creates something like a "invizible box" that makes the original one a bit larger but it gets unseen (just specullating of course).

Where's the example: http://www.babylonjs.com/playground/#26L9IU#1

Link to comment
Share on other sites

I think this problem is linked to the physic body size calculation. In CannonJs (and in OimoJs), all registered mesh is linekd to a 'body' : an invisible object linked to the physic engine.

 

Here is how the body size is processed with CannonJs : 

bbox = mesh.getBoundingInfo().boundingBox;var min = bbox.minimumWorld;var max = bbox.maximumWorld;var box = max.subtract(min).scale(0.5);

This code does not take into account the rotation at all (the maximum point of a box is ok when the box is not rotated).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...