AlbertoBonn Posted February 17, 2014 Share Posted February 17, 2014 Hi, why changed the position of the cam or plane in following situration:the init script initialize the Babylon scene init.jswindow.onload=function(){this.canvas = document.getElementById("webgl");if (!BABYLON.Engine.isSupported()){window.alert('Your browser do not support WebGL');}else{var engine = new BABYLON.Engine(canvas,true);scene = createScene(engine);scene.activeCamera.attachControl(canvas); engine.runRenderLoop(function(){ scene.render(); }); this.addEventListener("resize", function () {engine.resize();});} };index.htm<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>BABYLON - physics</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> <link rel="stylesheet" href="lib/css/babylon.css"> <script src="lib/js/babylon.js"></script> <script src="lib/js/cannon.js"></script> <script src="lib/js/hand.js"></script> <script type="text/javascript" src="lib/js/init.js"></script> <script type="text/javascript"> var createScene= function (engine){ var scene = new BABYLON.Scene(engine); var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 3, -40), scene); camera.checkCollisions = true; camera.applyGravity = true; var light = new BABYLON.DirectionalLight("dir02", new BABYLON.Vector3(0.2, -1, 0), scene); light.position = new BABYLON.Vector3(0, 80, 0); // Material var materialAmiga = new BABYLON.StandardMaterial("amiga", scene); materialAmiga.diffuseTexture = new BABYLON.Texture("lib/media/amiga.jpg", scene); materialAmiga.emissiveColor = new BABYLON.Color3(0.5, 0.5, 0.5); materialAmiga.diffuseTexture.uScale = 5; materialAmiga.diffuseTexture.vScale = 5; var materialAmiga2 = new BABYLON.StandardMaterial("amiga", scene); materialAmiga2.diffuseTexture = new BABYLON.Texture("lib/media/ground.jpg", scene); materialAmiga2.emissiveColor = new BABYLON.Color3(0.5, 0.5, 0.5); var box = BABYLON.Mesh.CreateBox("Box", 10, scene); box.position.x = -6; box.material = materialAmiga2; var sphere = BABYLON.Mesh.CreateSphere("Sphere", 10.0, 10.0, scene); sphere.position.x = 6; sphere.material = materialAmiga; var ground = BABYLON.Mesh.CreatePlane("Plane", 50.0, scene); ground.material = materialAmiga2; ground.position.y = -10; ground.rotation.x = Math.PI/2; // Physics scene.enablePhysics(); scene.setGravity(new BABYLON.Vector3(0, -10, 0)); sphere.setPhysicsState({ impostor: BABYLON.PhysicsEngine.SphereImpostor, mass: 1 }); ///// HERE COMES THE ADDITIONAL LINE ///// return scene; }; </script></head><body> <canvas id="webgl"></canvas></body></html>ok everything goes fine, now u see a sphere falling thru the grounding planebut when I add this lineground.setPhysicsState({ impostor: BABYLON.PhysicsEngine.BoxImpostor, mass: 0, friction: 0.5, restitution: 0.7 })the camera or plane changed the position. The ball bouce but on a vertical orientated plane/ground#!?Greetz Alberto Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 17, 2014 Share Posted February 17, 2014 can you just slightly move the sphere in order to avoid intersection with the plane before setting physics up? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 17, 2014 Share Posted February 17, 2014 Oh I got it Physics only support quaternion for rotation so you can do plane.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(0, Math.PI/2, 0); or you can use the new mesh.rotate function : plane.rotate(BABYLON.Axis.X, Math.PI/2, BABYLON.Space.LOCAL); Quote Link to comment Share on other sites More sharing options...
AlbertoBonn Posted February 20, 2014 Author Share Posted February 20, 2014 try it Quote Link to comment Share on other sites More sharing options...
AlbertoBonn Posted February 20, 2014 Author Share Posted February 20, 2014 I tried out but the first solution have the same effect and the other one dont work for mecan you send me the part of code? Im newbie in babylon Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 21, 2014 Share Posted February 21, 2014 Just replace that line:ground.rotation.x = Math.PI/2; by this one:plane.rotate(BABYLON.Axis.X, Math.PI/2, BABYLON.Space.LOCAL); Quote Link to comment Share on other sites More sharing options...
AlbertoBonn Posted February 22, 2014 Author Share Posted February 22, 2014 Thanx Deltakosh,but I think u mean ground.rotate not plane.rotate. maybe easier to understand for beginners. Here now the important part code:the problem:rotation of a mesh works not with enabled physics (right now) var ground = BABYLON.Mesh.CreatePlane("Plane", 50.0, scene); ground.material = materialAmiga2; ground.position.y = -10; ground.rotation.x = Math.PI/2;solution:rotationQuaternion works with physics: var ground = BABYLON.Mesh.CreatePlane("Plane", 50.0, scene); ground.material = materialAmiga2; ground.position.y = -10; ground.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(0, Math.PI/2, 0); 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.