JohnK Posted February 9, 2017 Share Posted February 9, 2017 Having had a look at the playgrounds using Jerome's new addRotation I started wondering about line 39 in http://www.babylonjs-playground.com/#1PON40#4 torus.rotation.copyFromFloats(0.0, 0.0, Math.PI / 2); the torus had already been set as vertical so why was it necessary to re-do it. On commenting out this line and running the PG again the wheel wobbles (quite a lot very soon). So I decided it had to do with stopping error accumulation. My next thought was why copyFromFloats and not just use. torus.rotation = new BABYLON.Vector3(0, 0, Math.PI/2); This does work as in http://www.babylonjs-playground.com/#1PON40#9 From advice about something else that Jerome gave me I decided that it had something to do with avoiding constructing new variables and garbage collection. My next thought was would this be avoided if I set a variable to be the vector3 (0, 0, Math.PI/2) and used this each time. So I created var vRot = new BABYLON.Vector3(0, 0, Math.PI/2); and then in the render loop used torus.rotation = vRot; result more extreme wobbling as in http://www.babylonjs-playground.com/#1PON40#10. If you do a console.log(vRot) in the loop its value changes. The simple question is why? What fundamental misunderstanding have I made this time? (Probably something to do with my use of Javascript rather than BJS) Quote Link to comment Share on other sites More sharing options...
adam Posted February 9, 2017 Share Posted February 9, 2017 Javascript is "pass by reference" when setting objects. JohnK 1 Quote Link to comment Share on other sites More sharing options...
JohnK Posted February 9, 2017 Author Share Posted February 9, 2017 Of course any changes in torus.rotation are also made to vRot. Thank you @adam knew it was something simple I should already know. Quote Link to comment Share on other sites More sharing options...
jerome Posted February 9, 2017 Share Posted February 9, 2017 Well, the goal of addRotation() is to compute the final value of mesh.rotation step by step. I don't know this final value (and I don't care), I just want my mesh rotated this way, then this way, etc. So, I need to begin each frame from a starting state rotation.z = PI /2, then to add my steps to reach the final wanted orientation. I can't keep the last stored values, because the next use of addRotation() will accumulate a new rotation on this last state what will lead to something unpredictable (by me). Just keep in mind that the WorldMatrix needs only a final value in the property rotation (or rotationQuaternion) whatever the way this value is set : manually or by using addRotation() or rotate() I've added a summary in the rotation doc here : https://github.com/BabylonJS/Documentation/blob/master/content/overviews/Standard/How_Rotations_and_Translations_Work.md JohnK 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.