octopus Posted August 15, 2016 Share Posted August 15, 2016 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. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted August 16, 2016 Share Posted August 16, 2016 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. adam 1 Quote Link to comment Share on other sites More sharing options...
octopus Posted August 16, 2016 Author Share Posted August 16, 2016 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 16, 2016 Share Posted August 16, 2016 are you sure that -9.81 m/s2 is translated into -386 inches per second per second? Quote Link to comment Share on other sites More sharing options...
DigiHz Data Posted August 16, 2016 Share Posted August 16, 2016 I use the meter system here in Sweden. I not start to use gravity functionallity yet, but...... Why don't you just make a javascript function that converts from inches to centimeters and another function that converts from centimeters to inches? Quote Link to comment Share on other sites More sharing options...
octopus Posted August 16, 2016 Author Share Posted August 16, 2016 What I am saying is that a pool table modeled at 50 x 100 units with balls that have a diameter of 2.25 units all seem to operate with a gravity setting of 9.81 units and not 386 units. Something is not right! Quote Link to comment Share on other sites More sharing options...
Wingnut Posted August 16, 2016 Share Posted August 16, 2016 heh. Are you being a bit obsessive, holding yourself to strict "only inches" criteria... unnecessarily... perhaps? Why does it matter? Is the project somehow "impure" because of this evil invasive units of measure... stinkin'-up the place? GameMonetize and adam 2 Quote Link to comment Share on other sites More sharing options...
octopus Posted August 16, 2016 Author Share Posted August 16, 2016 There is absolutely nothing in the engine that knows what units I have chosen to use. All the engine knows is that if something moves one unit then it matches the units else where. See where I'm going with this? Quote Link to comment Share on other sites More sharing options...
DigiHz Data Posted August 16, 2016 Share Posted August 16, 2016 Well, you can only use 1 type of units that you set yourself, you can not mix inches and meters and expect everythng to work. 1 unit is 1 unit (a unit does not have inches or meters). GameMonetize and ian 2 Quote Link to comment Share on other sites More sharing options...
DigiHz Data Posted August 16, 2016 Share Posted August 16, 2016 Example: var mesh = BABYLON.Mesh.CreateBox("box", 50, scene); The green value of 50 does not say if it is in meters or inches, it say 50 units. Quote Link to comment Share on other sites More sharing options...
octopus Posted August 16, 2016 Author Share Posted August 16, 2016 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!!! Quote Link to comment Share on other sites More sharing options...
DigiHz Data Posted August 16, 2016 Share Posted August 16, 2016 Your calculation is correct. You have to convert your values as i said earlier. Quote Why don't you just make a javascript function that converts from inches to centimeters and another function that converts from centimeters to inches? Quote Link to comment Share on other sites More sharing options...
adam Posted August 16, 2016 Share Posted August 16, 2016 I would just choose a number for gravity that looks good to you. These physics engines are not perfect. Quote Link to comment Share on other sites More sharing options...
octopus Posted August 16, 2016 Author Share Posted August 16, 2016 That's terrible advice. The engine is supposed to be consistent. Its not about setting things arbitrarily. Sheesh! Why doesn't somebody fix the engine? Imo, it is broken. it may very well be the fault of cannon, though. I am not sure. Quote Link to comment Share on other sites More sharing options...
adam Posted August 16, 2016 Share Posted August 16, 2016 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. Quote Link to comment Share on other sites More sharing options...
DigiHz Data Posted August 16, 2016 Share Posted August 16, 2016 The engine is not broken. But the engine uses UNITS, not inches or meters. If i ask you.....How tall are you? And you reply 5,6, i not know if you are 5,6 feet tall or 5,6 meters tall Quote Link to comment Share on other sites More sharing options...
adam Posted August 16, 2016 Share Posted August 16, 2016 There is some good advice here from the developer of cannon.js. http://stackoverflow.com/questions/16424500/what-would-be-realistic-values-for-gravity-mass-and-contact-material-in-canno Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted August 16, 2016 Share Posted August 16, 2016 @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 adam and GameMonetize 2 Quote Link to comment Share on other sites More sharing options...
octopus Posted August 16, 2016 Author Share Posted August 16, 2016 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! Quote Link to comment Share on other sites More sharing options...
adam Posted August 16, 2016 Share Posted August 16, 2016 15 minutes ago, octopus said: Dude, you totally missed the point of this thread. "Dude", you need to chill or people are going to start blocking you. DigiHz Data 1 Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted August 16, 2016 Share Posted August 16, 2016 @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. Quote Link to comment Share on other sites More sharing options...
octopus Posted August 16, 2016 Author Share Posted August 16, 2016 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. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted August 16, 2016 Share Posted August 16, 2016 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. Quote Link to comment Share on other sites More sharing options...
adam Posted August 16, 2016 Share Posted August 16, 2016 3 hours ago, octopus said: The gravity in this demo (entered as meters) MAKES NO SENSE! It makes perfect sense to me. It reminds me of this dollar bill drop reaction time test. You're camera is so close that the object zooms by. aWeirdo 1 Quote Link to comment Share on other sites More sharing options...
RaananW Posted August 17, 2016 Share Posted August 17, 2016 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... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.