Skip to content

Conversation

@lafflan
Copy link
Contributor

@lafflan lafflan commented Oct 25, 2018

when drag an object who's local position and rotation not equal world position and rotation will cause a wrong effect

@lafflan
Copy link
Contributor Author

lafflan commented Oct 30, 2018

@Mugen87 Mugen87 changed the title fix drag object in local coordinate DragControls: Fix drag object in local coordinate Oct 30, 2018
@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 30, 2018

@WestLangley
Copy link
Collaborator

when drag an object who's local position and rotation not equal world position and rotation will cause a wrong effect

I expect the problem is simply caused by the rotated parent object. Can you confirm?


Also, I suggest you avoid getWorldPosition() as it is not efficient. World matrices should have been updated already by the renderer in this case.

@lafflan lafflan closed this Oct 31, 2018
@lafflan lafflan reopened this Oct 31, 2018
@lafflan
Copy link
Contributor Author

lafflan commented Oct 31, 2018

I expect the problem is simply caused by the rotated parent object. Can you confirm?

maybe...but i'm not very clear.I found this problem incidentally when I was using it.

Also, I suggest you avoid getWorldPosition() as it is not efficient. World matrices should have been updated already by the renderer in this case.

but It seems that there is no other way to get the world position.

@WestLangley
Copy link
Collaborator

but It seems that there is no other way to get the world position.

Check the source code for .getWorldPosition().

vector.setFromMatrixPosition( object.matrixWorld );

@mrdoob mrdoob added this to the r99 milestone Oct 31, 2018
@arodic
Copy link
Contributor

arodic commented Oct 31, 2018

I expect the problem is simply caused by the rotated parent object. Can you confirm?

Exactly. Therefore, parent's transform should be taken into account when performing world space transformations.

I would expect similar issue to arise with scaled parent (a common case when importing objects from different world units)

@WestLangley
Copy link
Collaborator

In your use case,

_selected.parent.worldToLocal()

inverts the parent's world matrix repeatedly. This method should not be called in tight loops.

Can you compute the necessary inverse and reuse it?

@mrdoob
Copy link
Owner

mrdoob commented Nov 9, 2018

@WestLangley Just double-checking... Are you suggesting changes to this PR?

@WestLangley
Copy link
Collaborator

Are you suggesting changes to this PR?

I am suggesting the OP avoid calling worldToLocal() in tight loops. I doubt the parent's inverse will be changing while dragging.

@lafflan
Copy link
Contributor Author

lafflan commented Nov 12, 2018

@WestLangley thanks, could you please help to check

@WestLangley
Copy link
Collaborator

@sweerwen Yes, that is what I had in mind. I have not tested your code, however.

These convenience methods are just that: convenient. However, they are not necessarily efficient.

Thanks for making the change.

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 12, 2018

Looks good 👍

@mrdoob mrdoob merged commit dc62597 into mrdoob:dev Nov 13, 2018
@mrdoob
Copy link
Owner

mrdoob commented Nov 13, 2018

Thanks!

@lafflan lafflan deleted the patch-1 branch November 13, 2018 00:58
@Mugen87 Mugen87 mentioned this pull request Jul 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants