3D rotation using KX_GameObject.orientation problem

Ok, so i’m not the good with 3D math so bare with me.

I want to rotate a point around an objects center using the objects rotation,

I have this code:


orientation = obj.orientation
ori_mat = Matrix(orientation[0], orientation[1], orientation[2])

#vecOffset is the offset from the position of the object and is the point that i want to rotate

pos2 =  ori_mat * (Vector(obj.position) + Vector(vecOffset)) 

For some reason, when the object rotates, the point seems to rotate around location [0, 0, 0] (world origin), and not the objects position. The point is in the right position when the object has no rotation. Mabey there is something i have to set in the orientation matrix? I don’t really have a clue, i’m just now starting to study vector math. Any help with this problem would be great, thx :slight_smile:

long needed bump

Try this:


pos2 = Vector(obj.worldPosition) + (ori_mat * Vector(vecOffset))

Thx a lot social, it worked like its supposed to for once. Iv’e been studying vector math in my free time, but I still haven’t scratched the surface of matrices yet. I know who to ask now when I have a 3D math problem, thx again.