# Absolute Position and Pivot Point

## Recommended Posts

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?

Thanks!

##### Share on other sites

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.

##### Share on other sites

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:

##### Share on other sites

Do you want to tackle it?

sure

Thanks mate!

##### Share on other sites

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?

##### Share on other sites

I went with getAbsolutePosition:

##### Share on other sites

had me confused too sometime back

##### Share on other sites

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

##### Share on other sites
1 hour ago, Deltakosh said:

@JohnK would you mind adding some word about the setPivotMatrix function new parameter?

Will do

##### Share on other sites

ACtually it could be more than that:

##### Share on other sites
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

1. leave the function setPivotMatrix alone and ensure the documentation clearly states that that the matrix needs to use the inverse translation;
2. change the function setPivotMatrix to work with the actual translation, if so the function setPivotPoint (and possibly getPivotPoint and getAbsolutePivotPoint) would need changing;
3. 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.

##### Share on other sites

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)

## 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.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.