Global to Local pos
-
Hi
How to convert global position to local.
I want to convert global position of Object to local position of his parent -
Here you will find any information about matrices and thus everything about positioning, scaling, rotation, etc.
-
I'm not an expert in math i tried but don"t work
My english is null and google translate isn't always correct
Can you give me an example? -
No problem.
Now to your question: You can simply call GetMl() on your child object. This returns you the local matrix of the object. Now to access the position, ask the matrix for the offset:
myObject.GetMl().off
It's the very first example code in the documentation I linked in my previous post.
@passion3d said in Global to Local pos:
google translate isn't always correct
You should try Deepl
-
My question may not be clear enough.
I have an object1 that has a child Object2
I want to move Object2 to a global position, so I have to convert the global position from destination to local position with respect to its parent. -
You don't have to!
There's also a function available: SetMg()
I warmly suggest you to read the Matrix Fundamentals since it has been written to demystify the matrix math. It also has various code examples for all kinds of transformations, including your scenario.
edit: Now that I think about your question: Do you want to move the parent with the child?
-
no, i want move the child but not the parent
-
Sorry, got you slightly wrong then.
Try this:
m = op.GetMg() # get the object's matrix m.off = c4d.Vector(50) # modify the position op.SetMg(m) #set the modified matrix c4d.EventAdd() # update C4D
This code simply moves the child, completely decoupled from its parent in absolute world coordinates.
-
Thank you @mp5gosu
This is exactly what I was looking for.
In fact, C4D does the calculations itself. I thought I had to do the matrix multiplication, and I didn't understand how to do it.
Finally it's very simple