Tutorial: Orientation Matrix [Rotation about *any* point added]

I have written a short tutorial (rotation.zip 264K ) describing the Orientation matrix (the matrix you get when calling getOrientation() on a game object), and how to use it for some rotation problems (eg. flipping an object upright, or pointing one object in another’s direction).

Be warned though, the tutorial is fairly mathematical, and the reader is assumed to be familiar with basic concepts of vectors and matrices.

I’d appreciate comments and suggestions.

Comments and suggestions?!
Sure, If I only understood a word?! :slight_smile:
But the final ( 5.5, 5.6) it’s just beautiful
Like an abstract poem or a modern drawing
Most of us, blender users, and that’s why we use it, are programming
Can you make some examples in action?
It would be great
Thank you anyway

Hey, thanks a lot. That will make a great reference. I hate hunting that kind of thing up when I have to do something like that.

I have added some Python code that implement the algorithms, and made some corrections.

@OTO: Indeed, manipulating geometric objects is not for the feint of heart. I will try to add some blend files later this week. In the mean time the code I have added might be useful, even if it is somewhat less poetical than the math statements :wink:

@fireside: Exactly what “inspired” this tutorial - hours of fruitless search and then hours of grinding tests!

OK, here are three blend files (rotation.zip 264K) showing:

  • how to flip an object upright (but keeping its “front” in the same direction),
  • how to point one object’s “front” to another, and
  • how to point one object’s “front” to another and also keeping it upright.I discovered some better ways to solve these problems, and will update the written tutorial when I have time.

Hello again
Ah, now it’s much more “funny”
Thank you for the effort
Maybe you can give me some tips
I’m using Erwin’s vehicle demo to make a demo for the contest
But the car turns upside down often
I can I avoid this, automatically ( inside the vehicle’s script) or maybe
with a key action?

My heart is sinking. I was hoping to use a script to rotate my camera… Oh, math! What do I look like here? An engineer? My father-in-law could read it better than I read English (I’m an ignorant American–I don’t know any other languages), but to me and my high school diploma it’s like walking through the arctic tundra naked: painful at first, until you go numb and turn blue. Then nothing really matters anymore.

Thank you for your tutorial, though. As I have already gone numb, the pain is no longer a deterant. I am dedicated to figuring this out. (I’ll just have to read it several more times, that’s all…)

edit: Interesting… It posted twice for some reason…

It’s just college level matrix math. I learned about some of this in highschool as well.

I like that it’s in PDF format, and I also like how you presented the code and the basic function setup.

Useful stuff.


You can use the script in “flip.blend” (in the zip above) to flip over your car (with a key action) [That is exactly how we flip over our car].

Avoiding it, however, won’t be easy using orientation, and I think it will take away from the natural dynamics. The best is to build a car which is more stable (size, weight, acceleration), or build a world that is less dangerous (slopes, ramps, height of bariers and general placement of obstacles). We spent a lot of time playing with settings, and built our world specifically for the car – there is no quick fix.

Ah, Social, not everyone went to college. Yes, I remember learning these things in high school, but high school is fading quickly, and math seems to be going the fastest. I’ve used my education so rarely for years that (now that I have a use for it) it seems to resent me.

Regardless, I did figure it out. Many thanks, herman.tulleken. Your tutorial showed me what I needed to know, and with a little help from forum search I was able to apply it. Additional thanks to fireside for sample code of what I needed, and also to wiseman303 for clarifying for me that the x, y, and z stuff is not in the rows of the matrix, but in the columns.

Point taken.

I can definitely relate to the “fade” effect you are reffering to. Most of that stuff looked pretty useless until I actually needed it.

If only teachers used the BGE to teach math. Imagine the possibilities.

If only teachers used the BGE to teach math. Imagine the possibilities.

Yeah. It’s a joke in there, really. They spend so much time with proofs, and they pass over practical applications. Most of them are computer illiterate. I’m all for theory up to a point, but it’s useless and uninteresting without practical applications. The teaching of math is stuck in the 1940’s. They make this big deal that you buy a scientific calculator that costs about 1/3 the price of a decent computer and is borderline useless, then they don’t let you use it on half the tests they give. I had a trig teacher that wasted so much time forcing everyone to memorize these tables and giving tests on it. Who remembers that crap when they get out? You look it up.


  • The PDF and blends are now neatly zipped together.
  • Formulas have been updated (with rows and columns as they should be - thanks for pointing that out).
  • A section and blend added that explains how to revolve one object around any point. This should be the final version - hope it is useful.

Hello again
Thank you very much for the tips!!
I’ll try them.

I downloaded the new zip file, but ZippHO and WinRAR both say its corrupt. I was able to extract the blend files, but not the new pdf. (Strangely, I was looking forward to reading it…)

I think its fixed now…

My hat is off (and as you can see, it’s a big one) for you herman.tulleken, thank you very much for putting this matrix stuff into a doc like this.

You sure are a brave man :D.

You even did it all in a nicely layed out PDF file, it looks pro ;).

Note: on the rotate.blend file, the text data “text” is incomplete it just says “press space to see the”.

Thanks, Herman. The new zip archive works perfectly. Your “rotate an object around any point” script will certainly prove useful! I am imagining all of the cool things I can do with it… I must say, you’ve certainly offered a huge help to many of us who were previously very confused. Keep up the good work!

Thank you, very nice.