Rotation question
by Benj · in Torque Game Engine · 01/20/2007 (9:53 am) · 15 replies
After much skimming of the forums i kinda sorta understand the rotations torque uses, i found this function in a reply to www.garagegames.com/mg/forums/result.thread.php?qt=16170
called normal2rotation, that makes a quat rotation that points the objects local Z at a normal, problem is, the rotation around the local Z seems almost random, what id like to know is if anyone knows a way to control the local Z rotation of the object, so it can sit realistically on a surface, but control its Z rotation.
basically, instead of giving it a axis to rotate around and a angle, i want to give it a axis to point the Z axis at, and rotation around that.
called normal2rotation, that makes a quat rotation that points the objects local Z at a normal, problem is, the rotation around the local Z seems almost random, what id like to know is if anyone knows a way to control the local Z rotation of the object, so it can sit realistically on a surface, but control its Z rotation.
basically, instead of giving it a axis to rotate around and a angle, i want to give it a axis to point the Z axis at, and rotation around that.
#2
i can matrix multiply and effect the local Z axis, but its relative, i cant just set its Z rotation, only change it that way.
01/20/2007 (12:11 pm)
I just mean around the objects local Z rotation, like you can do in the mission editor.i can matrix multiply and effect the local Z axis, but its relative, i cant just set its Z rotation, only change it that way.
#3
the "up" vector is in world-space and is used to orient the local X & Y axes around local Z.
i'm away from the codebase now,
but when i get back to it i'll give a look around.
01/20/2007 (5:45 pm)
Right.the "up" vector is in world-space and is used to orient the local X & Y axes around local Z.
i'm away from the codebase now,
but when i get back to it i'll give a look around.
#4
i was just gonna say that there's a *really* easy way to orient an object how you want,
if you have access to real rotation matrices. versus quaternions.
if you know what direction you want the object's local Z to point,
and you have an Up vector, say you want local Y to point as much as
possible towards Up while maintaining Z.
Just Cross Z into Up to get X, then cross X back into Z to get Y.
Now you have 3 perpendicular vectors X Y and Z.
These are what's called an "orthogonal basis".
Once you've got an orthogonal basis,
it's trivial to create the corresponding rotation matrix;
you just line the basis vectors up next to each other like so:
voila !
also note that if you have a rotation matrix,
this makes it trivial to extract what direction local Y is facing:
it's just (Yx Yy Yz).
- note that it needs to be a pure rotation,
without any scaling etc in it.
unfortunately i don't think Torque exposes real 3x3 rotation matrices to script,
nor 4x4 transform matrices. - but you're an SDK owner, so it's always easy to do yourself !
01/20/2007 (5:58 pm)
Damn! lost a nice big post.i was just gonna say that there's a *really* easy way to orient an object how you want,
if you have access to real rotation matrices. versus quaternions.
if you know what direction you want the object's local Z to point,
and you have an Up vector, say you want local Y to point as much as
possible towards Up while maintaining Z.
Just Cross Z into Up to get X, then cross X back into Z to get Y.
Now you have 3 perpendicular vectors X Y and Z.
These are what's called an "orthogonal basis".
Once you've got an orthogonal basis,
it's trivial to create the corresponding rotation matrix;
you just line the basis vectors up next to each other like so:
| Xx Yx Zx | | | | Xy Yy Zy | | | | Xz Yz Zz | where (Zx Zy Zz) = your desired Z direction, and X and Y similarly.
voila !
also note that if you have a rotation matrix,
this makes it trivial to extract what direction local Y is facing:
it's just (Yx Yy Yz).
- note that it needs to be a pure rotation,
without any scaling etc in it.
unfortunately i don't think Torque exposes real 3x3 rotation matrices to script,
nor 4x4 transform matrices. - but you're an SDK owner, so it's always easy to do yourself !
#5
01/20/2007 (7:12 pm)
I allready have the objects Z pointing in the right direction with the function i found, what i need now is to rotate it around its Z, which i can do by multiplying a empty z rotation quat, but i cant set its Z rotation, only alter it, like i can only + or - it, i cant do = to it.
#6
01/20/2007 (10:48 pm)
Yah, i know. that's what my previous three posts have been about.
#7
01/21/2007 (9:25 am)
Well, im not so good with all of the matrix rotations and stuff, but as far as i can tell ive been rotating it on the Z without a up vector already, i just need a way of getting the current Z rotation out of the quat, then i can cancel it out/change it to what i want, or just figure out a way of changing the normal2rotation function todo it automatically.
#8
01/29/2007 (8:15 am)
Hmmm, iam starting to understand how the normal2rotation function works, as i understand cross dot and arc cosine now(i got a $2 calculator that can do all the advanced functions like that minus cross and dot), is there a way do do what you were talking about without the raw matrix? i know why my Z rotations were seemingly random now(after i figured out how it was doing it, and demonstrated it to myself by tilting my DS around with my hands and fingers as the cross product lol).
#9
01/31/2007 (9:24 pm)
Ok so i made a console method to do the rotation matrix, after fiddling it works like a charm. it was pointing in the opposite direction though, so i had to inverse the x vector before crossing it again to make the Y, now it works perfect.
#10
sorry i didn't get back to you,
but uh, along the lines of "that which does not kill me",
maybe sometimes "those questions which do not get answered for me make me smarter" ?
i dunno. anyhow, congrats.
feel like posting it ?
01/31/2007 (10:51 pm)
Hey great!sorry i didn't get back to you,
but uh, along the lines of "that which does not kill me",
maybe sometimes "those questions which do not get answered for me make me smarter" ?
i dunno. anyhow, congrats.
feel like posting it ?
#11
02/01/2007 (1:16 pm)
In here?
#12
well it sounds like a pretty useful function which i'm sure other folks would appreciate having.
maybe post in the SDK-owner's forum ?
02/01/2007 (2:02 pm)
Oh right - i guess not.well it sounds like a pretty useful function which i'm sure other folks would appreciate having.
maybe post in the SDK-owner's forum ?
#13
i might post it in the private forum so anyone can see if theres something wrong with it.
02/01/2007 (2:38 pm)
Iam not sure if its fully working yet, in some cases it seems to not be aligning the Z axis....i might post it in the private forum so anyone can see if theres something wrong with it.
#14
heres a example
02/02/2007 (9:05 am)
Although, after dumping the matrices of the objects involved, it almost seems like the ray cast is faulty, i was testing it by doing a thing similar to what tribes2 construction does, with a block dts, and even if the rotation was off, it should still be touching the one before it, and when it messes up, it is both tilted wrong, and isn't touching it. what its doing is, for a block touching the ground, the Z is aligned to the ray cast normal, and the Y is aligned to the players forward vector, and the ray cast normal is stored in the object, and if its being placed on another block, its Z is aligned to the ray cast normal, and the Y is aligned to the normal the block its touching used to align its Z axis. heres a example
#15
www.garagegames.com/mg/forums/result.thread.php?qt=57532
02/04/2007 (9:20 pm)
Heres my post in the private forum describing my problem.www.garagegames.com/mg/forums/result.thread.php?qt=57532
Associate Orion Elenzil
Real Life Plus
so the object's Z-axis points along "direction" and the Y-axis points as close as possible to "up".
- maybe look about for an extra param like that ?
(of course, if "direction" and "up" get very close to each other, the rotation again becomes sort of undefined)