To switch from a global coordinate system to a local coordinate system of an object, we need to multiply the global coordinates by the inverted matrix of an object:
1 2 3 4 5 |
import copy object_matrix_inverted = copy.copy(bpy.context.object.matrix_world) object_matrix_inverted.invert() cursor_location_local = object_matrix_inverted @ bpy.context.scene.cursor.location |
To switch from the local coordinate system of the object to the global coordinate system, we need to multiply the local coordinates by the matrix of an object:
1 2 3 4 5 |
import copy object_matrix = copy.copy(bpy.context.object.matrix_world) vertex_0 = bpy.context.object.data.vertices[0].co vertex_0_global = object_matrix @ vertex_0 |
I used this to convert a BGE 2.79 script to an UPBGE 3.0 script and it worked, but I dont
know why. Please can you give a little explanation?
This is just matrix math. To switch from the local coordinate system to the global and back, we need to multiply the object transform matrix to the inverted world (local) matrix.