MattePatte Posted April 3, 2014 Share Posted April 3, 2014 Hi!I have problems changing the rotation and position of meshes when i have added physics to them.I have taken a look at the tutorial (https://github.com/BabylonJS/Babylon.js/wiki/How-to-handle-rotations-and-translations) but still haven't found a solution. I have manage to change the rotation and position before i have added physics to the mesh but i would rather change the rotation and position without removing and adding the mesh every time i want to change it's position and rotation. I think the problem is that i don't manage to get these two function to work.mesh.rotate(BABYLON.Axis.X, 1.0, BABYLON.Space.LOCAL);mesh.translate(BABYLON.Axis.X, 1.0, BABYLON.Space.WORLD); Saying that property.X is undefined. Any suggestions and comments are more then welcome! Quote Link to comment Share on other sites More sharing options...
gwenael Posted April 3, 2014 Share Posted April 3, 2014 Which version of BabylonJS do you use? Do you the minified version of it or do you include all the javascript files? Quote Link to comment Share on other sites More sharing options...
MattePatte Posted April 3, 2014 Author Share Posted April 3, 2014 Excellent question. Just took a file named babylon.js in when downloaded the repository from github. I can see now there is a JavaScript file called babylon.1.9.0.js and that it is the one that has the functionalists for rotate and translate.So i think you have solved the problem for me thank you! gwenael 1 Quote Link to comment Share on other sites More sharing options...
gwenael Posted April 3, 2014 Share Posted April 3, 2014 You're welcome. 1.10.0 is out if you want the latest code. MattePatte 1 Quote Link to comment Share on other sites More sharing options...
MattePatte Posted April 3, 2014 Author Share Posted April 3, 2014 I am very bad rotating meshes. As i mentioned earlier the objective is to rotate the mesh without removing it.This is the code.shape = new BABYLON.Mesh.CreateBox("box",3,scene,true);shape.scaling.x = 5;shape.scaling.y = 0.2;shape.scaling.z = 5;shape.setPhysicsState({ impostor: BABYLON.PhysicsEngine.BoxImpostor, mass: 0, friction: 0.5,restitution: 0.7 });shape.rotate(BABYLON.Axis.X, Math.PI/4, BABYLON.Space.LOCAL);shape.translate(BABYLON.Axis.X, 4, BABYLON.Space.WORLD);The mesh don't rotate or moves in this case. But if i rotate and translates before adding the physics to the mesh it works. Do i have to remove the mesh and then add it to rotate it or is there a solution for rotating it without removing it? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 3, 2014 Share Posted April 3, 2014 Hi MattePatte, welcome to the forum! Good to have you with us. I am Wingnut, newbie, big mouth, pretend know-it-all, and nut case. Howdy! I think you are experiencing what I call "quaternion hell". Take a look at this MSDN Post. There is a sentence there: "The initial position and rotation (using mesh.rotationQuaternion property) of the mesh are used to define the position and rotation of the impostors." Yep, cannon.js imposters (magic physics mesh hidden inside your mesh)... use quaternions, not 'eulers'. One of the easiest ways to get good information about this... is to click this link to a google search about it . Take a look at the 'mesh class' at our cool API for babylon.js . There are two ways to rotate a mesh. 1. rotate, and 2. rotationQuaternion (yaw, pitch and roll). When a mesh has its physics state set, rotationQuaternion becomes the preferred way to rotate. To be REALLY brief... look at this local post . Excerpt: some_mesh.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(0, 0, 0); or... some_mesh.rotate(BABYLON.Axis.X, 0, BABYLON.Space.LOCAL); some_mesh.rotate(BABYLON.Axis.Y, 0, BABYLON.Space.LOCAL); some_mesh.rotate(BABYLON.Axis.Z, 0, BABYLON.Space.LOCAL); See that? mesh.rotate still works, but it must be done in a special way, shown above. You are not being dumb at all. This 'cannon.js uses quaternions' thing has bitten quite a few of us, and our documentation on the subject is not wonderful. We are working on it. I hope you can help us do that, too, someday. Babylon.js is a team project and everyone is invited, but a chap named deltakosh is team chief. I am not experienced in quaternions AT ALL, and last I heard, quaternion.toEulerAngles() was still being 're-worked'. From what I have heard on the web, all 'toEuler' attempts on quaternions... give mixed results... because of the nature of quaternions and eulers. I hope this helps. Maybe smarter people than I will add replies. There are some really smart (and really friendly) people nearby. Tell us about your discoveries and projects, post links to big or little demos and tests, we love it! Welcome again. Xanmia and MattePatte 2 Quote Link to comment Share on other sites More sharing options...
MattePatte Posted April 3, 2014 Author Share Posted April 3, 2014 Thanks Wingnut! I will start learning about quaternion. Wingnut 1 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.