Matrix Calculus in Python


is it possible to do some matrix calculus in python to rotate objects in BGE?

obj.getOrientation() returns 3x3 orientation matrix of object, that can be modified and obj.setOrientation(mat) sets new orientation matrix to object.

thanks, i want to generate a random orientation. is that possible too?

I have created a little module, that contains matrix operations for use in GameBlender. It’s contained in the lastest Texture plug-in demo (download demo, open .blend file and get text file and load it to your .blend file).
Then a simple script will generate 3 random angles and create rotation matrix from them:

import mat
rndMat = [[1.0, 0.0, 0.0],[0.0, 1.0, 0.0],[0.0, 0.0, 1.0]]
for i in range(3):
  rndMat = mat.matMult(rndMat, mat.matRot(i, GameLogic.getRandomFloat() * 360.0))
obj = GameLogic.getCurrentController().getOwner()

I recently used the “euclid” python module to do matrix/vector math in the GE, it’s a bit of a handfull if you’re not used to it, but it’s a viable alternative to the mathutils module.

But actually we should snag us a coder and make him make mathutils available in the GE… cause it should be :wink:

very nice. thanks very much ashsid.
@macouno i will have a look at it