Matrix4 Methods explanation and rotation vs. direction

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
PWAUVAN
Posts: 8
Joined: Thu Mar 01, 2007 7:19 pm
Location: Milwaukee

Matrix4 Methods explanation and rotation vs. direction

Post by PWAUVAN »

For those of use whose experience with matrices is that of the solving systems of equations and numerical methods sorts rather than the 3D transformations sorts, I was wondering if someone with more experience in this could explain in more detail than the API docs what some of the Matrix4 and Vector3D methods do. The ones I in particular are curious about are below:

Matrix4::buildCameraLookAtMatrixLH/RH:
The API says that it builds a left handed and right handed look-at matrix,
What is a look-at matrix?
What are some uses for one?
Whats the difference with the hands?
Syntactically, how would one use it?
what is an "up vector"?

Matrix4::buildNDCToDCMatrix:
I suppose this would make more sense if I knew what normalized device coordinates vs device coordinates were.

buildProjectionMatrixOrthoRH/LH:
What is an orthogonal projection matrix?
What are some uses for one?
Syntactically, how would one use it?

buildProjectionMatrixFov and buildProjectionMatrixPerspective
What are the differences between orthoganal, FOV, and Perspective projection matrices?

getTranslation

getTransposed

interpolate
i have an idea of what this one might do, but who would use it?

where would an inverse rotate/translate vector be used?

transformvect/plane/box

translatevect/plane/box

I am just as confused on some of the vector3D methods:

getHorizontalAngle

getInterpolated

normalize

rotateXY/XZ/YZ
I am confused by the center parameter in this function

OK, I realize I have just caused someone to go through alot of work with the explanation of these methods, but I am sure it will help many people immensly. Below is a specific "issue" I am having

I am attempting to use the rotation of a node to return a vector which corresponds the the direction that the node is facing. This is done so I have a basis to use for teh targeting and animation of projectiles in my game.
Example of what I mean,
vector3d getDirection(vector3d rotation);

used like direction = getDirection(node.getRotation());

so that a node with rotation of (0, 180, 0) would return (0, -1, 0)
and a node with rotation of (0, 225, 0) would return (-.707, 0, -.707) and so on.

Thank you for all the help
PWAUVAN (Programmer With An Unnecessarily Verbose Acronym Name
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Re: Matrix4 Methods explanation and rotation vs. direction

Post by bitplane »

PWAUVAN wrote: Matrix4::buildCameraLookAtMatrixLH/RH:
The API says that it builds a left handed and right handed look-at matrix,
What is a look-at matrix?
What are some uses for one?
Whats the difference with the hands?
Syntactically, how would one use it?
what is an "up vector"?
I guess a 'look at matrix' is a matrix which rotates something to look at a target. the difference between left and right handed cartasean coordinate systems can be explained like this-
point your thumb upwards (this is the Y axis), your index finger forwards (this is Z), now point your middle finger towards your other hand (this is X). Irrlicht uses a left-handed coordinate system, where X goes from right to left when Y is facing up.
an "up vector" is a normalized vector (a vector of length 1.0, not a rotation), which faces upwards.
PWAUVAN wrote: Matrix4::buildNDCToDCMatrix:
I suppose this would make more sense if I knew what normalized device coordinates vs device coordinates were.
no idea, i've never had to worry about this! if I ever need to convert between normalized device coordinates and device coordinates, I know where to look though ;)
PWAUVAN wrote: buildProjectionMatrixOrthoRH/LH:
What is an orthogonal projection matrix?
What are some uses for one?
Syntactically, how would one use it?
You would use it to create an orthogonal projection matrix for your camera's view transformation. if you're using irrlicht's cameras, you don't need to worry about this. If you're making your own camera and want it to have no perspective (things dont get smaller in the distance), you can use this.
PWAUVAN wrote: buildProjectionMatrixFov and buildProjectionMatrixPerspective
What are the differences between orthoganal, FOV, and Perspective projection matrices?
not sure, I guess its just the values you use to create the view matrix.
PWAUVAN wrote: getTranslation
translation means movement. 4x4 matrics have translation, rotation and scale.
PWAUVAN wrote: getTransposed
transposing a matrix is the act of turning it on its side- swapping the columns and rows.
PWAUVAN wrote: interpolate
i have an idea of what this one might do, but who would use it?
anyone who wants to interpolate between two matrices, you don't have to use it just because its there!
PWAUVAN wrote: where would an inverse rotate/translate vector be used?
usually you'd use the whole inverse matrix, to reverse a matrix multiplication.
PWAUVAN wrote: transformvect/plane/box
translatevect/plane/box
translate (move) or transform (scale, move, rotate) a plane, box or vector.
PWAUVAN wrote: getHorizontalAngle
gets the rotation of a vector around 0,1,0
PWAUVAN wrote: getInterpolated
interpolates between one vector and another. for example, interpolating 0.5 between 1,1,1 and 2,2,2 would give 1.5, 1.5, 1.5.
PWAUVAN wrote: normalize
makes the vector a "unit vector" which has a length of 1.0
PWAUVAN wrote: rotateXY/XZ/YZ
I am confused by the center parameter in this function
center is the axis you wish to rotate around.
PWAUVAN wrote: OK, I realize I have just caused someone to go through alot of work with the explanation of these methods, but I am sure it will help many people immensly. Below is a specific "issue" I am having
yeah i'm bored already, but i shall press on regardless...
PWAUVAN wrote: I am attempting to use the rotation of a node to return a vector which corresponds the the direction that the node is facing. This is done so I have a basis to use for teh targeting and animation of projectiles in my game.
Example of what I mean,
vector3d getDirection(vector3d rotation);

used like direction = getDirection(node.getRotation());

so that a node with rotation of (0, 180, 0) would return (0, -1, 0)
and a node with rotation of (0, 225, 0) would return (-.707, 0, -.707) and so on.
first you must decide which way up or forwards is. try this-

Code: Select all

vector3df upVector(0,1,0);
node->getAbsoluteTransformation().rotateVect(upVector);
return upVector;
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
PWAUVAN
Posts: 8
Joined: Thu Mar 01, 2007 7:19 pm
Location: Milwaukee

My solution to the issue

Post by PWAUVAN »

Thank you for the help bitplane, as well as the extremely long and informative reply. Your absolute transformation code worked well, I am able to use it to not only determine what the node is "looking at" without having to attach a camera to it, but Ive found that the directiong vector can be used to shoot a projectile by first calling normalize on the upVector after it has been rotated and then applaying a velocity scalar to it to create a velocity vector.

To get the a velocity vector using a continuation of bitplane's code

Code: Select all

vector3df upVector(0,1,0); 
node->getAbsoluteTransformation().rotateVect(upVector); 
upVector->Normalize();
return upVector;
Now to fire a projectile using the velocity vector returned: (assuming no gravity)

Code: Select all

Vector3D VelocityVec = CreateVelocityVec(); //The function we just wrote
Matrix4 m = new Matrix4();
m->setRotationDegrees(projectilenode->getRotationDegrees());
m->TransformVect(velocityVec);
Vector3D Pos = projectilenode->getPosition();
Pos->setX(Pos->getX + VelocityVec->getX();
Pos->setX(Pos->getY + VelocityVec->getY();
Pos->setX(Pos->getZ + VelocityVec->getZ();
projectilenode-_setPosition(Pos);

Now call this function for every projectile during the device run loop and have each projectile get eliminated either after it collides with something or it has gone a certain distance.

I have found that another, rather hack way to get the direction vector of a node is just to create a child node of extremely tiny size about 100 units or so infront of your node. since this node is a child node it will always be in the direction of the "face" of the node. So to get the direction the node is facing just do

Code: Select all

directionVec = (Node->getAbsolutePosition() - ChildNode->getAbsolutePosition())->Normalize();
return directionVec;
I suppose you could get real creative with this method, maybe use a line3d instead of another node. THis line could double for collision detection or defining the limits of "sight" for nodes controlled by AI. Also, if you are (such as I am) creating a node with multiple "guns" (think an x-wing or TIE Interceptor) where the guns projectiles ought to converge at some point, the child node or other end of the line as a point to converge the projectiles without having to define a specific in game target to converge at. Drawing the child node closer or shortening the line length can have the gunfire converge closer to the player node and vice versa. [/quote]
PWAUVAN (Programmer With An Unnecessarily Verbose Acronym Name
Post Reply