Basics of Linear Transformations

Get answers to all your basic programming questions. No Ogre questions, please!
Bleakwise
Kobold
Posts: 27
Joined: Wed Jun 26, 2013 10:36 am
x 3

Basics of Linear Transformations

Post by Bleakwise »

http://www.ogre3d.org/docs/api/html/cla ... ml#details
OGRE uses column vectors when applying matrix multiplications, This means a vector is represented as a single column, 4-row matrix. This has the effect that the transformations implemented by the matrices happens right-to-left e.g. if vector V is to be transformed by M1 then M2 then M3, the calculation would be M3 * M2 * M1 * V. The order that matrices are concatenated is vital since matrix multiplication is not commutative, i.e. you can get a different result if you concatenate in the wrong order.
The use of column vectors and right-to-left ordering is the standard in most mathematical texts, and is the same as used in OpenGL. It is, however, the opposite of Direct3D, which has inexplicably chosen to differ from the accepted standard and uses row vectors and left-to-right matrix multiplication.
OGRE deals with the differences between D3D and OpenGL etc. internally when operating through different render systems. OGRE users only need to conform to standard maths conventions, i.e. right-to-left matrix multiplication, (OGRE transposes matrices it passes to D3D to compensate).
The generic form M * V which shows the layout of the matrix entries is shown below:
[ m[0][0] m[0][1] m[0][2] m[0][3] ] {x}
| m[1][0] m[1][1] m[1][2] m[1][3] | * {y}
| m[2][0] m[2][1] m[2][2] m[2][3] | {z}
[ m[3][0] m[3][1] m[3][2] m[3][3] ] {1}

An explanation of the very most basics would be great, that is, given say, the matrix above, how that is "rendered". So far the Khan's link below is the best explanation I've had.

Watching this video gives some insight to the "basics" but...
https://www.khanacademy.org/math/linear ... eflections

Does this translate over to Oger3d's matrix classes or are there some rotational differences.It appears Khan is using the same notation as Ogre3d is, ie: a column vector and right to left notation. In the video it's described as T(x) = Ax (the transformation of x is Matrix * Vector).

I would love to see this thread turn into something of a matrix3/matrix4 "cookbook".
Last edited by Bleakwise on Thu Jun 27, 2013 6:36 pm, edited 3 times in total.
Books: The C++ Programming Language Special Edition, Programming Windows 5th Edition, Compilers: Principles, Techniques, and Tools 1st Edition.
Todo: The C Programming Language 2nd Edition, More Effective & Effective C++ 2nd/3rd Editions, The Java Programming Language 4th Edition, The C++ Programming Language 4th Edition (C++11), Hadoop: The Definitive Guide.
Bleakwise
Kobold
Posts: 27
Joined: Wed Jun 26, 2013 10:36 am
x 3

Re: Basics of Linear Transformations

Post by Bleakwise »

I've been a poster on CryDev for a while. I had an epiphony today related to Linear Transformations and the 4x4 matrix. I'm just going to copy/paste the post here in place of my ramblings, as it turned out much more clear concise and to the point.
I've been buggering this forum about Matrix Algebra for a while now, and I figured it's only fair I drop in with the "key" I didn't have that wouldn't let me advance in the subject.

For starters, there is a great new video series up at Khan's Academy detailing the creation of translation matrixes; instead of "solving translations" he's going at it the reverse way and creating translations that rotate and stretch/skew various sets of vectors (polygons) in order to achieve a desired result.
https://www.khanacademy.org/math/linear ... eflections

I had an epiphany a while ago, one that kicked in the door of Mr.Linear Transformations house and he told me everything I wanted to know under the condition that I didn't tell anyone else. Well too bad, you got to hear this. An XY plane describes rotations around the Z axis. The XZ plane describes rotations around the Y axis, and of course this leaves the YZ plane to describe rotations around the X axis. Just imagine the axis sticking straight up out of the origin and the "unit circle" from trigonometry defining any possible rotation around it. It's not hard to conceive.

Once this "hit me" it occurred to me that this must be exactly what pitch roll and yaw are used to describe. For so long I was stuck on the "proper way" to describe "z components"; if anyone else is suffering from this mode of thinking just stop, it's just wrong, it leads nowhere. Anyway, once I figured out the proper way of viewing the system/solution a simple Google search on the string "matrix roll pitch yaw" procured a great document on industrial robot programming that echos standard math used by our friends over at Khans (and also CE3).
http://planning.cs.uiuc.edu/node102.html
Explains what my epiphany was in technical detail.

For a more complete understanding going back a few pages on that site isn't a bad idea
http://planning.cs.uiuc.edu/node100.html
Besides the mathematics that link provided an interesting revelation, if Game Development doesn't work out I could always use the math I learned here to program a ROBOT ARMY OF DOOM! =D
Books: The C++ Programming Language Special Edition, Programming Windows 5th Edition, Compilers: Principles, Techniques, and Tools 1st Edition.
Todo: The C Programming Language 2nd Edition, More Effective & Effective C++ 2nd/3rd Editions, The Java Programming Language 4th Edition, The C++ Programming Language 4th Edition (C++11), Hadoop: The Definitive Guide.
Bleakwise
Kobold
Posts: 27
Joined: Wed Jun 26, 2013 10:36 am
x 3

Re: Basics of Linear Transformations

Post by Bleakwise »

I was talking with a friend of mine on Skype on an issue that has remained and still remains mostly clouded, Quaternions.

Can anyone recommend a good math book on the subject? Something that starts with principles of imaginary numbers that works it's way into the subject of Quaternions would be ideal. From what I gather, our use of Quaternions involves just a few simple steps. I've included the videos I used to gather the below information.

1) Creating a quaternion (represeting a rotatoin) defiend as a R3 vector and a scalar angle.
[cos( a/2 ), x * sin( a/2), y * sin( a/2), z * sin( a/2) ]

2) Multiplying the "Rotation Quaternion" by a "Pure Quaternion" created from a vector in R3, producing another Quaternion. This quaternion holds the components of the rotated version of the vector that we used to create the "Pure Quaternoin"

3) To extract the rotated vector, you multiply the quaternion by it's "Conjugate", which is basically the original Quaternion with it's components negated.
[ -1 * cos( a/2 ), -1 * x * sin( a/2), -1 * y * sin( a/2), -1 * z * sin( a/2) ]

The interesting thing about Quaternions being that you avoid Gimbal Lock, and Interpolation is reduced to a straightforward algorithm.

If you're interested I suggest watching these videos in the order posted.
http://www.youtube.com/watch?annotation ... f7mpLG48Wk
http://www.youtube.com/watch?v=LB6U849kwXc

Special thanks to William Hamilton, it's amazing what some people find staring in the Abyss.
Books: The C++ Programming Language Special Edition, Programming Windows 5th Edition, Compilers: Principles, Techniques, and Tools 1st Edition.
Todo: The C Programming Language 2nd Edition, More Effective & Effective C++ 2nd/3rd Editions, The Java Programming Language 4th Edition, The C++ Programming Language 4th Edition (C++11), Hadoop: The Definitive Guide.
User avatar
Daixiwen
Greenskin
Posts: 105
Joined: Fri Feb 08, 2013 11:30 am
Location: Oslo
x 16

Re: Basics of Linear Transformations

Post by Daixiwen »

This is almost correct, except for the conjugate. The real part of the quaternion isn't negated, so the conjugate would be:
[ 1 * cos( a/2 ), -1 * x * sin( a/2), -1 * y * sin( a/2), -1 * z * sin( a/2) ]
If you negate all the components then you just get a negated quaternion.

I don't have any book to recommend, someone else probably will have one for you. I learned 3D a long while ago with an old book that only used matrices, and now most of my knowledge about quaternions have been gathered on the net. But you don't fully need to understand how quaternion works to use them, fortunately most libraries have ready made functions for that.
Hardware, n.: part of the computer you can kick
User avatar
cybereality
Hobgoblin
Posts: 563
Joined: Wed Jul 12, 2006 5:40 pm
x 12

Re: Basics of Linear Transformations

Post by cybereality »

"3D Math Primer for Graphics and Game Development" is a great resource:
http://www.amazon.com/Math-Primer-Graph ... 568817231/

I have also heard good things about "Mathematics for 3D Game Programming and Computer Graphics" (next on my to-read list):
http://www.amazon.com/Mathematics-Progr ... 1435458869