Convert pitch/yaw/roll to Vector
Blitz3D Forums/Blitz3D Programming/Convert pitch/yaw/roll to Vector
| ||
hi! i need to convert a rotation defined by pitch, yaw and roll to a vector defined by XYZ. eg: (freelook) i'm looking to the right and push forward, so i move right instead of forward. thanks :) |
| ||
nobody knows? i suppose it's something simple with sin/cos..? |
| ||
maybe you mean something like this? http://de.wikipedia.org/wiki/Eulersche_Winkel |
| ||
Try this. It's not exactly a maths way, but... Create a pivot at 0,0,0 Create another pivot at 0,0,0 and parent it to the one before. Position the pivot at 0,0,1 (which i assume is the correct vector for pitch and yaw, if not, adjust accordingly). Then... rotate the pivot at 0,0,0 to the pitch and yaw values. Then read the global position of the second pivot. The X,Y and Z values will be your vectors. No doubt someone will come along with a maths way, but that will work for you until then. |
| ||
Make that the "up key" (or whatever you are using to move forward) moves the object in its local Z axis. It will always move forward no matter where it's facing. If that's not what your asking, then please reformulate your question because it's a bit vague. |
| ||
Svenart: that's an overkill for my brain. i simply need the formula. ----> Euler Rotation (pitch,yaw,roll) To Vector (x,y,z) <---- Kryzon: thats exactly what i mean. btw: no pivot and TForm opperations please. only maths. |
| ||
Tform is maths essentially, and it's dam quick. |
| ||
Is there nothing in Mark's .b3d source code that could help? |
| ||
Ok, i've had a right good look through the code archives for vector stuff. This would seem to be suited to your problem: http://www.blitzbasic.com/codearcs/codearcs.php?code=1091 EDIT: Oh i see you've already commented on that code... The tform commands would give the answer here btw, and there are pretty quick. Especially if it's for something like calculating the direction to move the camera etc etc. (Any reason why you can't use moveentity?) |
| ||
I second Ross C's last question, and also...you can't transform orientation elements into a vector. They only tell where the vector is facing, not how "long" it is. But still, if you want to know the global directions of a vector based on your character's facing: TFormVector 0,0,SizeOfVector, Character, 0 Then you could use something like... MoveEntity Character,TFormedX(),TFormedY(),TFormedZ() But then again, you can just cut all that sh*t out and just use MoveEntity straight away. |
| ||
i simply can't use TForm opperations because i'm programming with managed direct3D in C#. but i think that it's no problem when i post here anyway, because i think i will get the answer here more likely than in any other forum. Ross C: i can't seem to find anything useful in this vector lib. |
| ||
Hi I don't understood what are you trying to get. You could calculate a vector with the orientation to where the object is facing based on it's pitch an roll with some sin cos math but you loose the roll component. One thing you posibly do is to calculate the x,y,z component of the vector with pitch and yaw, normalize the vector (so it has a Length of 1) and then scale the vector by the roll component. This is the only way I imaginge that you could store all the information in a vector. But, my friend, if you do that, you probably end working wiht a 3d lib like the one posted avobe!, sorry. Juan |
| ||
but you loose the roll component. if you think about it, the roll factor doesn't matter because it does not change the direction or lenght of the vector. please tell me how to use those sin/cos things to get this thing working. |
| ||
exactly for that is that I don't understood what you needed the post should be: convert pitch/yaw to vector! I try to find some doc's / code I think have. see you Juan |
| ||
Hi Test that function: Function PitchYawToVector(pitch#,yaw#,dest.Vector) dest\x = Cos(pitch) * Sin(yaw) dest\y = Sin(pitch) dest\z = Cos(pitch) * Cos(yaw) NormalizarVector(dest) End Function with this Type Vector Field x#, y#, z# End Type v.Vector = New vector Graphics3D 800,600,0,2 SetBuffer = BackBuffer() cam = CreateCamera() PositionEntity cam,0,0,-5 light = CreateLight() cube1 = CreateCube() ScaleEntity cube1,.1,.1,1 EntityColor cube1,255,0,0 Cube1Pitch# = 0 Cube1Yaw# = 0 Repeat If KeyDown(200) Then Cube1Pitch = Cube1Pitch + 1 If KeyDown(208) Then Cube1Pitch = Cube1Pitch - 1 If KeyDown(203) Then Cube1Yaw = Cube1Yaw + 1 If KeyDown(205) Then Cube1Yaw = Cube1Yaw - 1 RotateEntity cube1, Cube1Pitch, Cube1Yaw, 0, True PitchYawToVector(Cube1Pitch, Cube1Yaw, v) RenderWorld Text 10,10,Cube1Pitch Text 10,30,Cube1Yaw Text 100,10,v\x Text 100,30,v\y Text 100,50,v\z Text 100,70,Magnitud(v) TFormVector 0,0,1, Cube1, 0 Text 200,10,TFormedX() Text 200,30,TFormedY() Text 200,50,TFormedZ() v\x = TFormedX() v\y = TFormedY() v\z = TFormedZ() Text 200,70,Magnitud(v) Flip Until KeyHit(1) End Function PitchYawToVector(pitch#,yaw#,dest.Vector) dest\x = Cos(pitch) * Sin(yaw) dest\y = Sin(pitch) dest\z = Cos(pitch) * Cos(yaw) NormalizarVector(dest) End Function Function CuadradoVector#(v.Vector) Return v\X*v\X + v\y*v\y + v\Z*v\Z End Function Function Magnitud#(V.Vector) Return Float(Sqr(CuadradoVector(V))) End Function Function NormalizarVector(v.Vector) ; v = v(normalizado) Local Temp# Local mag# mag = Magnitud(v) If mag>0 Then Temp# = Float(1/mag) v\X = v\X * Temp v\y = v\y * Temp v\Z = v\Z * Temp Else v\x = 0 v\y = 0 v\z = 0 End If End Function hope that is what you need (btw nice gui!, thank's) Edit: there are a sign error in x and y, please modify the function to: Function PitchYawToVector(pitch#,yaw#,dest.Vector) dest\x = -Cos(pitch) * Sin(yaw) dest\y = -Sin(pitch) dest\z = Cos(pitch) * Cos(yaw) NormalizarVector(dest) End Function Juan |
| ||
thanks so far. that works. when i use this code, the camera moves to the direction where it looks. but since in my 3d code, you can move an entity by all three axis, so i need this for all three axis. when i call something like >> Entity.Move(1, 2, 3) i got an idea: maybe what i really need is to rotate the vector (1|2|3) around the pitch/yaw and the result is the final vector. you know what i mean? |
| ||
to be honest, no idea! I saw that you are programming in C, so you didn't have the nice 3d functions blitz has. The 3d libs normally work with matrix, point, vector quaternions and the like. Translate, rotate and all this stuff is made by matrix multiplication etc. If you look inside, the elements of the matrix are calculated based on sin, cos math like the function above. Are you programing 3D in C, with out a 3D lib? Is it posible for you to write the equivalent in blitz of your intention. Probably I could translate to simple sin/cos math, (but not guaranteed). best regards Juan |
| ||
As Charrua says, TFormVector, Point and Normal are just Blitz3D names for multiplying a vector by a series of matrices. In this case, since scale and position are not an issue, you can just use one matrix. Make a rotation matrix from your Euler Angles And Multiply your starting vector by that rotation matrix to get your end vector. |
| ||
yes, when i do it in C#, i have a Matrix and a Vector class with lots of methods. but i can't multiply vectors by matrices... EDIT: your idea was good, gabriel Vector3 vec = new Vector3(x, y, z); vec.TransformNormal(MatrixRotation); MatrixPosition *= Matrix.Translation(vec.X, vec.Y, vec.Z); thanks to all in this thread. i learned more usefull stuff regarding vector stuff. :) |