ChrisR Posted September 22, 2015 Author Share Posted September 22, 2015 But moving the pivot moves the mesh. So it still rotating in local space relative to the same pivot location. So if i move the pivot, the mesh moves the same amount. This has been my problem the whole time Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 22, 2015 Share Posted September 22, 2015 yes but the pivot happens before the rotation which means that you can set a translation in the pivot, do your rotation and then reset your position No way to achieve this without the pivot. As you may know matrices multiplication are not associative: AxB != BxA the complete matrices chain in bjs is: PivotMatrix x Scaling x Rotation x Translation Quote Link to comment Share on other sites More sharing options...
JohnK Posted October 7, 2016 Share Posted October 7, 2016 Recently I needed to rotate a mesh around a pivot and started out using a parent. In the project the camera was always fixed on the mesh and the pivot needed to move from frame to frame and I had problems keeping the mesh in its correct position. A search for "rotating" and "pivot" brought me back to this topic which I had forgotten. So I decided if I found a solution I would post it here. @ChrisR sorry to have taken so long (over a year) and hope what follows is a solution to what you wanted, even if you have solved it another way I hope others might find it useful. What I wanted was for a mesh to rotate around an line that did not pass through its local origin. Two things are needed to fix a line, a point that the line passes through and a vector representing the direction of the line. You can think of these as a pivot point and an axis. Given a pivot point (pivotAt) and an axis (axis) and an angle (theta) for the rotation the following will rotate a mesh around the line. var m = BABYLON.Matrix.Identity().setTranslation(mesh.position.subtract(pivotAt)); var invm = m.clone().invert(); var r = BABYLON.Matrix.RotationAxis(axis,theta); var ar = m.multiply(r).multiply(invm); mesh.setPivotMatrix(ar); http://www.babylonjs-playground.com/#29BGXO#3 iiceman 1 Quote Link to comment Share on other sites More sharing options...
DigiHz Data Posted November 5, 2016 Share Posted November 5, 2016 @ChrisR Have you found a solution for this problem yet? I understand exactly what you mean, and i am trying to achieve the same thing. See topic http://www.html5gamedevs.com/topic/26132-getpivotmatrix-xyz-local-values/?page=1 Quote Link to comment Share on other sites More sharing options...
DigiHz Data Posted November 13, 2016 Share Posted November 13, 2016 A solution might be ths PG. http://www.babylonjs-playground.com/#M0UJB Hans 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.