How to use matrices for rotation

What exactly does a 3X3 Rotation matrix in Panda mean?
It is not the literal rotation transformation right?
But rather the 3 vectors which define the axes of the object?

How would I take these axes and rotate them by say 90 degrees on the y axis or 90 deg on x axis.

Do I simply apply the transform to each column of the matrix or what?

No panda provides very many higher level operation on the matrix
www.panda3d.org/apiref.php?page=Mat3

I know this is an old post treeform. But i do not think you answered this person’s question. You just referred him to a reference which he probably does not understand anyway. He needs instructions on what a rotation matrix IS and HOW it is used in panda3d

I think treeform’s answer may be interpreted as “you don’t need to understand what a 3x3 matrix means, because Panda provides the high-level tools that make that unnecessary.”

Granted, sometimes you want to understand what the matrix means anyway. But I think this poster wasn’t in that category; he/she was just asking how to get the job done, which treeform’s response answered satisfactorily.

Are you in the latter category? :slight_smile:

David

I must say I would also very much like to know this.

For a person that is familiar with C++ this link may be enough, but for many of the rest of us, a simple Python example of maybe 6 lines of code would be so much more valuable.

I imagine this sort of question will be asked over and over again (I would be asking it in about 4 weeks time) and it would save a newer person a lot of unnecessary sorting time through posts that may provide just that little bit too little information.

We all value the help others provide on this forum, but a small code snippet in an explanation could be so much more informative.

Please don’t take this as a criticism, it is just meant to reflect the desperate hope of an uneducated member that is trying to get productive as quickly as possible.

OK, but we still need to clarify exactly what it is you want to know, because the original question is unclear. Do you want to know how to rotate an object by 90 degrees, or do you want to know how to rotate a matrix by 90 degrees? They are completely different questions.

For the latter question, it is true that the three rows of the 3x3 matrix represent the X, Y, and Z axes of the coordinate space. The lengths of these axes correspond to the scale, and the direction of the axes correspond to the rotation. If they are not all perpendicular to each other, you have a shear going on. So, if you wanted to build a rotation matrix the hard way, you could construct one by figuring out which way you wanted your axes to point, and build up the appropriate 3x3 matrix. You normally wouldn’t do this, though–it is generally faster and easier to rotate a 3x3 matrix by multiplying by another 3x3 matrix that performs the rotation. In general, any kind of transformation can be represented in a matrix, and the act of performing that transformation is the same thing as the act of multiplying the matrices.

But even still, most people never even touch matrices when working with Panda. You don’t need to, since Panda provides a bewildering suite of higher-level functions that do all of this work for you. So, if you wanted to rotate an object by 90 degrees on the y axis from its current position, the easiest way is to do something like this:

object.setHpr(object,0, 0, 90)

If you look at the transform matrix before and after the rotation, you can see the the vectors have changed position, but you normally don’t need to think about that.

print object.getMat()
object.setHpr(object,0, 0, 90)
print object.getMat()

There are many other operations you can do, as well, none of them involving matrix math, including relative operations and lerps. Most of them are covered, at least briefly, in the manual.

David

David i can add some info to this page
panda3d.org/manual/index.php/Math_Engine
about the math api with common application examples. I’m learning how to work with the math api right now and it would nice if this info was accessible in the same place.

WOW…Thank you gentlemen.

Now this thread has become very useful even to me.

When I get to the stage further down the line in my project, I was wondering how would be the most efficient way of applying a gun convergence to a WW2 aircraft.

Now, not only do I know how I will handle the manipulation of the model of the aircraft in 3D space, but also the nature of the mathematical calculations to provide the offset from the aircraft vectors, to the bullet vectors, to achieve the necessary convergence. :open_mouth:

Maybe you don’t need to know, but every programmer worth his salt should know what they are and how they work, even if not actually building them himself. I remember when I studied my computer science I was asked to build my own software rasterizer and thought to myself “When am I ever going to need to do this? This is why we have game engines that do it for us”. But looking back, I’m glad I did because it gives you valuable insight into why things work the way they do. I can guarantee that if you do, at some point you will have that difficult how-to question and you won’t be looking on a forum, you will be the one answering it.

If you’re new to programming, don’t kick yourself if you don’t get it 100%. We all went through that at some point.