Setting position and orientation directly via Matrix

Hello everybody,

I’m trying to set and rotate a camera to a specific position / orientation in world space, during the game engine is running. I receive position and orientation data continually via network as a 3x3 rotation matrix and a 3 component tranformation vector.
As I saw in the Blender Python API, it’s possible to get the current camera position and orientation in exactly this format via “myCamera.worldPosition” and “myCamera.worldOrientation”. The problem is, that I couldn’t find functions like “setWorldPosition” and “setWorldOrientation”.

Of course I can use “applyMovement” and “applyRotation” but therefor I have to calculate the difference between the last position an my new position and much harder I have to translate the rotation matrix into an x,y and z rotation value (it’s a part of pi but I dont know how this is called).
But this is getting inaccurate over the time and the effort to translate the rotation isn’t that small.

Does anybody have an idea how to solve this problem, or is there any advanced developer who can tell me how to extend the game engine python API?

By the way, I’m using Blender 2.57 :wink:

I’m new in this Forum and hope I did everything right with this post…

worldPosition and worldOrientation are both properties. This means you can use them for both getting and setting data.

Getting:
position = obj.worldPosition

Setting:
obj.worldPosition = position

however, you may find issues setting the orientation. and position. in order to circumvent this, try this code instead.

#getting


pos = [object.worldPosition[0],object.worldPosition[1],object.worldPosition[2]]
ori = [[object.worldOrientation[0][0],object.worldOrientation[0][1],object.worldOrientation[0][2]],[object.worldOrientation[1][0],object.worldOrientation[1][1],object.worldOrientation[1][2]],[object.worldOrientation[2][0],object.worldOrientation[2][1],object.worldOrientation[2][2]]]			

#setting


object.worldPosition = pos
object.worldOrientation = ori

Thank you very much!
It took me a while to test it because of other problems but now it works. So you really helped me and I’m so happy that there is a simple solution.