Jump to content

Gravity vector in meters, everything else in inches?


octopus
 Share

Recommended Posts

I have created a scene in Babylon and all of my distances are entered as inches. Incidentally, gravity seems to work well when entered as the vector (0,-9.81,0), but those units would be meters. G is approx. 9.81 m/s^2. What is the logic here? Why shouldn't I also enter my gravity vector in inches (0,-386,0)? I am using the Cannon physics engine.

Link to comment
Share on other sites

Hiya Octopus!  What a strange and interesting question!  I love it!

The meters thing MIGHT just be an "industry standard" for those who write physics engines, and maybe that's the ONLY reason.

@schteppe, the author of Cannon.js... IS a member of our forum, and me mentioning his name here... might get him to visit and give his views.

Feel free to visit Cannon.js website, too.  Maybe hack-around in a beautified version of Cannon.js, too... see how the gravity values are used.  (But I'm not sure if doing that would give you any good answers, either.)

Sorry that I didn't have a decent answer.  If you DO find an answer (from somewhere else), could you make sure you tell us, here.  Thanks.  I am curious, too.

Link to comment
Share on other sites

Well no, this is a serious question. If my entire scene is built using inches as a unit then my gravity vector ought to be  (0,-386,0) , but when I use that vector, gravity looks rocket powered. This is not just a question about conventions. The engine cannot possibly be arbitrarily changing units from vector to vector. All of my other vectors are in inches! 

How could the engine possibly know I used inches everywhere that it knows to convert gravity from meters to inches appropriately? There needs to be a logical explanation. If I remodeled everything in meters (to match units) the gravitational force would be tiny! I doubt everybody models in inches.

Link to comment
Share on other sites

use this code in the playground:

see the sizes used at the top .3, .025 and 1.25 are units in metres. The gravity in this demo (entered as meters) MAKES NO SENSE!

// scene consists of a .3m x .3m table and a .025m diameter ball (camera 1.25m away)

var createScene = function () {


    var tablesize = .3;
    var ballsize  = .025;
    var camdist = 1.25;
    var balldist = .5;

    // This creates a basic Babylon Scene object (non-mesh)
    var scene = new BABYLON.Scene(engine);

    scene.enablePhysics();
    scene.getPhysicsEngine().setGravity(new BABYLON.Vector3(0,-9.81,0));

    var camera = new BABYLON.ArcRotateCamera("Camera", 3 * Math.PI / 2, Math.PI / 3, camdist, BABYLON.Vector3.Zero(), scene);

    camera.attachControl(canvas, true);

    // This creates a light, aiming 0,1,0 - to the sky (non-mesh)
    var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);

    // Default intensity is 1. Let's dim the light a small amount
    light.intensity = 0.7;

    // Our built-in 'sphere' shape. Params: name, subdivs, size, scene
    var sphere = BABYLON.Mesh.CreateSphere("sphere1", 3, ballsize, scene);
    sphere.position.y = balldist;

    // Our built-in 'ground' shape. Params: name, width, depth, subdivs, scene
    var ground = BABYLON.Mesh.CreateGround("ground1", tablesize, tablesize, 2, scene);


    sphere.physicsImpostor = new BABYLON.PhysicsImpostor(sphere, BABYLON.PhysicsImpostor.SphereImpostor, { mass: 1, restitution: 0.5 }, scene);
    ground.physicsImpostor = new BABYLON.PhysicsImpostor(ground, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, restitution: 0.5 }, scene);

    return scene;
};

 

Change the size of the models to inches:

    var tablesize = 12;
    var ballsize  = 1;
    var camdist = 50;
    var balldist = 20;

 

Now, even though we have left the gravity in meters the gravity looks more reasonable. In my opinion this is incorrect.

 

According to DigiHz, "you can not mix inches and meters and expect everythng to work" and yet Babylon expects us to do exactly this!!!

 

Link to comment
Share on other sites

21 minutes ago, octopus said:

That's terrible advice. The engine is supposed to be consistent. Its not about setting things arbitrarily. Sheesh!

This is a game engine.  Relax.

It's more important for me to have things look good rather than be "right" and look like shit.

Link to comment
Share on other sites

@octopus The engine is not broken at all, you just confused it :).

1 unit is 1 unit, it is not 1 inch, it is not 1 centimeter, it is 1 unit.

In your first PG,

Your gravity is actually calculated relatively correctly,

However, it looks so wrong because your plane and ball are so small compared to it.

in the real world you could compare it to a small piece of gravel that is droped from a height and then hits a brick on a sidewalk. that piece of gravel will also appear to travel very fast.

http://www.babylonjs-playground.com/#X9VJM#0

Link to comment
Share on other sites

14 minutes ago, aWeirdo said:

@octopus The engine is not broken at all, you just confused it :).

1 unit is 1 unit, it is not 1 inch, it is not 1 centimeter, it is 1 unit.

In your first PG,

Your gravity is actually calculated relatively correctly,

However, it looks so wrong because your plane and ball are so small compared to it.

in the real world you could compare it to a small piece of gravel that is droped from a height and then hits a brick on a sidewalk. that piece of gravel will also travel very fast.

http://www.babylonjs-playground.com/#X9VJM#0

Dude, you totally missed the point of this thread. Its the code where the units DO NOT MATCH that works correctly! When the units all agree the gravity is incorrect! 

Link to comment
Share on other sites

@octopus 

I understood perfectly well, but it doesn't change the fact that 1 unit is 1 unit, it is not measured in meters or inches. it's a made up measurement.

Gravity is set to -9.81 by default, simply because that's the correct real-world measurement in meters/s2, But it doesn't matter, in babylonJs it is now -9.81 Units, not meters.
 

So your small scene seems odd as i explained with gravel in my previous post, and your bigger scene seems more "normal" because gravity doesn't appear to have the same impact since everything is bigger, even though the gravity is calculated exactly the same way.

 

Take a look at this scene: http://www.babylonjs-playground.com/#46YD5#1

Everything is enlarged,

It also looks wrong, but it is indeed also calculated correctly.

It is simply a question of perspective.
 

Link to comment
Share on other sites

In other words if I model a scene in meters the gravity needs to be changed to roughly 0.25.  Does nobody see an issue with that? it is 0.25 because there are 39.3701 inches per meter and 9.81 (G in meters) needs to be converted now. In my opinion you should not be converting gravity from meters to something else if you have modeled your scene in meters. 

Go to another measurement system and model a city scape using miles. What should gravity be now? I can tell you it will need to be set to 0.000154777 but not because that's what G is in miles/sec^2, because its not. In fact G in miles/sec^2 is 0.00609357. But again, you need to divide by the number of inches per meter. Surely somebody will chime into this thread eventually and see that this conversion is not intuitive. I'm really impressed with the amount of work that has gone into Babylon. Its not just a game engine, it can be used to model physics as well. This is just one small nitpicky thing that I noticed, and when I initially started this thread I was hoping that there was a sensible answer that I simply overlooked.

It might say I'm a "newbie" on the left there, but I am no spring chicken to this. I've developed in Unity and Unreal Engine and used other 3D engines over the years such as Irrlicht as well as coding raw OpenGL, WebGL, DirectX and my own simplistic physics engines. The values used when we program needs to be predictable and intuitive. Not arbitrary.

 

Link to comment
Share on other sites

I sort of agree.  I have not had the need to use this, so I will not be doing any changing. 

Looking at Blender game Engine, gravity is set to 9.80.  If you change the scene units to 'Imperial' it changes to 32.15.  Perhaps, a 'units' property with setter could be added.  It might auto change value, alleviating the user of doing it.  Still it would be a goofy number, if they look afterward.  Undoing that would require more.

You would have to enter the gravity in meters first (unless there was a setter for gravity too).  I know it is not 9.8 for the moon.

Link to comment
Share on other sites

I like this conversation :)

I wrote about is here as well - https://msdn.microsoft.com/en-us/magazine/mt614269

You can set your units. But you might also ask - what is mass? Kg? Pounds? 

Those are simply units. The connection between them is being calculated in the physics engine. You will simply need to change the default behavior, change the gravity to fit, change the mass to fit as well, and you could use any units you would like. But! be consistent.

Having said that, why would anyone want to use any system other than the metric system was never clear to me :) It is so simple and intuitive...

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...