Art Vandelay Posted January 25, 2018 Share Posted January 25, 2018 Hi, Im pretty confused In the attached playground I create a sphere at (0,0,0). Then I change the pivot point to (0,-5,0) (the bottom of the sphere). At this point the absolute position of the sphere is still (0,0,0). However, when do setAbsolutePosition(0,0,0) I would expect no change. But the absolute position changes to (0,5,0). Why is this happening? https://playground.babylonjs.com/#RTE4BS#6 Thanks! Quote Link to comment Share on other sites More sharing options...
JohnK Posted January 25, 2018 Share Posted January 25, 2018 Tricky things pivots, this might be worth a read http://doc.babylonjs.com/how_to/pivots Setting the pivot point to (0, -5, 0) is achieved (under the bonnet by all the following) by translating the sphere by (0, 5, 0) so the pivot point is now at the bottom of the sphere and becomes the local origin of the sphere ie is locally (0, 0, 0) for the sphere. However at this stage the sphere would be sitting on the ground. To move it to its starting point a translation in world space of (0, -5, 0) is needed. Of course the local origin of the sphere (or pivot) moves with the sphere and is still the local origin of the sphere and the sphere's position remains (0, 0, 0) locally. In world space the coordinates of the local origin of the sphere are (0, -5, 0) and so absolute position is given as (0, -5, 0) as in label 2. At the final stage you are resetting the absolute coordinates from (0, -5, 0) to (0, 0, 0) which is a translation of (0, 5, 0) giving its absolute position as (0, 0, 0) but of course this translation has to be also applied to the local origin of the sphere moving it from (0, 0, 0) to (0, 5, 0) giving the results as in label 3. webdva 1 Quote Link to comment Share on other sites More sharing options...
adam Posted January 25, 2018 Share Posted January 25, 2018 That looks like a bug. Either getAbsolutePosition should be taking the pivot matrix into consideration or setAbsolutePosition should be ignoring the pivot matrix. Here I used the inverted pivotMatrix to update the absolute position: https://playground.babylonjs.com/#RTE4BS#7 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 25, 2018 Share Posted January 25, 2018 Agree @adam Do you want to tackle it? Quote Link to comment Share on other sites More sharing options...
adam Posted January 25, 2018 Share Posted January 25, 2018 sure Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 25, 2018 Share Posted January 25, 2018 Thanks mate! Quote Link to comment Share on other sites More sharing options...
Art Vandelay Posted January 26, 2018 Author Share Posted January 26, 2018 Thanks Adam, glad I brought it up then Would be happy to know when the issue is fixed. Also, out of curiosity, which option do you think makes more sense, changing getAbsolutePosition or setAbsolutePosition? Quote Link to comment Share on other sites More sharing options...
adam Posted January 26, 2018 Share Posted January 26, 2018 I went with getAbsolutePosition: https://github.com/BabylonJS/Babylon.js/pull/3631 brianzinn, JohnK, tomer and 1 other 4 Quote Link to comment Share on other sites More sharing options...
satguru Posted January 26, 2018 Share Posted January 26, 2018 glad this is getting fixed. had me confused too sometime back Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 29, 2018 Share Posted January 29, 2018 So I had to change the fix bit to not break existing code. But this should be transparent for you (the setPivotPoint behavior should be fixed directly) @JohnK would you mind adding some word about the setPivotMatrix function new parameter? You can now specifiy a boolean as 2nd parameter (false by default). If set to true, the pivotMatrix will ONLY move the pivot and not act as a transformMatrix also. This should be the default behavior but I can force it because of back compat Thanks webdva 1 Quote Link to comment Share on other sites More sharing options...
JohnK Posted January 29, 2018 Share Posted January 29, 2018 1 hour ago, Deltakosh said: @JohnK would you mind adding some word about the setPivotMatrix function new parameter? Will do Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 29, 2018 Share Posted January 29, 2018 ACtually it could be more than that: Quote Link to comment Share on other sites More sharing options...
JohnK Posted January 30, 2018 Share Posted January 30, 2018 13 hours ago, Deltakosh said: ACtually it could be more than that: It could perhaps be even more? In starting to re-write the documentation and the PG examples examples that go with it I came across a situation where a further decision needs to be considered. I will follow the issue with the reason for it. Issue Under the breaking change where only the pivot is changed I would expect the following to apply :- A box having width 8, height 4 and depth 2 and origin at (0, 0, 0) is to have a pivot set at its right front lower corner (4, -2, -1) The pivot need to be translated (4, -2, -1) so set the matrix M for this translation. however Box.setPivotMatrix(M) places the pivot at (-4, 2, 1) You can see this in the PG https://www.babylonjs-playground.com/#AGXDE#20 So to place the pivot at (4, -2, -1) requires M to be set using the negative translation (-4, 2, 1) as seen in the PG https://www.babylonjs-playground.com/#AGXDE#21 Decision Possibilities leave the function setPivotMatrix alone and ensure the documentation clearly states that that the matrix needs to use the inverse translation; change the function setPivotMatrix to work with the actual translation, if so the function setPivotPoint (and possibly getPivotPoint and getAbsolutePivotPoint) would need changing; something I haven't thought of. Reasons The original function moved the mesh and so, as in the given example, to place the pivot at the right front lower corner required the translation of the box to be in the opposite direction - see PG using stable version https://www.babylonjs-playground.com/indexstable#AGXDE#22 before translating the box back to its original position. The function setPivotMatrix still follows this procedure. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 30, 2018 Share Posted January 30, 2018 I would say 1 as I do not want to change things too much (I already did too much for the sake of the backward compatibility) 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.