Jump to content

Absolute Position and Pivot Point


Art Vandelay
 Share

Recommended Posts

Hi,

Im pretty confused :blink:

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!

Link to comment
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.

Link to comment
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 :D

 

Link to comment
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.

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...