Car relative vector to world relative vector - Printable Version +- iDevGames Forums ( http://www.idevgames.com/forums)+-- Forum: Development Zone ( /forum-3.html)+--- Forum: Game Design ( /forum-5.html)+--- Thread: Car relative vector to world relative vector ( /thread-7549.html)Pages: 1 2 |

Car relative vector to world relative vector - Cookie - Sep 30, 2002 05:22 AM
hi everyone I'm trying to make a simple 3D racing game, and I need to convert a car-relative velocity vector into a world co-ordinate velocity vector. For my car-relative velocity vector, the Z axis is in straight out the windsheild, the x-axis cuts across the car, and the y axis points up out of the car. I need to convert this velocity vector into a world coordinate velocity vector. Thanks Car relative vector to world relative vector - OneSadCookie - Sep 30, 2002 05:33 AM
I remember this! It's a basis transformation! Um... Yeah. Car relative vector to world relative vector - OneSadCookie - Sep 30, 2002 05:48 AM
Oh boy, linear algebra! Quote:Anton, "Elementary Linear Algebra", 7th ed. Car relative vector to world relative vector - OneSadCookie - Sep 30, 2002 05:53 AM
So (if I've got this right, and it's 12.45 AM so take it with a grain of salt), what you need to do is make a matrix with the vectors for the x direction of the car in world space, the y direction of the car in world space, and the z direction of the car in world space, and multiply that matrix by the car-relative velocity vector. Car relative vector to world relative vector - OneSadCookie - Sep 30, 2002 05:54 AM
I have no idea whether that's right though. I should really leave the math questions to the people who actually remember these things... Car relative vector to world relative vector - kainsin - Sep 30, 2002 07:20 AM
Sounds just right to me. Car relative vector to world relative vector - Cookie - Sep 30, 2002 07:39 AM
thanks onesadcookie, that sounds easy enough, although I'd rather not use matrices. although after playing around I came up with this for 2D transformation: velwc.x=-sin(yawamount)*velocity.z+cos(yawamount)*velocity.x velwc.z=-cos(yawamount)*velocity.z+sin(yawamount)*velocity.x Is there a similar way for 3D transformation? I attempted to work it out, but now my brain hurts. I'd prefer to stay away from matrices as I really have no idea what i am doing. Car relative vector to world relative vector - ededed - Sep 30, 2002 08:07 AM
Just a hint that may not help in your situation but It is worth noting. DotProduct(x, y) = (Sin(theta), Cos(theta)) theta = the bearing of (x, y) to the origin DotProduct(x, y){ d = sqrt(x*x + y*y) x /= d y /= d } Out of intrest why might you need to convert a relative velocity to a world velocity, why not just use a world velocity for a car? Car relative vector to world relative vector - Cookie - Sep 30, 2002 08:52 AM
I'm implementing some car physics, and some of these equations deal with the relative velocity of the car, and the wheel angle and such. These forces are acting on the car in relation to the car, not world coordinates, hence the need to convert. Anyway, I'll see if I can get some of this matrix stuff workin. Even though I did matrices last semester in school, im still a bit rusty.. but it sounds easy enough. Thanks everyone! Car relative vector to world relative vector - ededed - Oct 1, 2002 10:49 AM
Just a second, you seem to be making this very complicated, using matrices and things. You must rotate the car to draw it properly... So cant you just to the opposite rotatation on the vector of the car. Car relative vector to world relative vector - OneSadCookie - Oct 1, 2002 02:56 PM
It's a 3x3 matrix multiplication. That's nine multiplies and six adds -- it's going to be easier and faster than some yucky trigonometric solution. Car relative vector to world relative vector - codemattic - Oct 1, 2002 03:30 PM
You have a car that is rotated and translated. How are you currently storing that rotation now? A quaternion? A 3x3 rotation matrix? Quote:Originally posted by ededed I would argue he is making his life *harder* by avoiding using matricies and things. Car relative vector to world relative vector - David - Oct 1, 2002 03:48 PM
Quote:Originally posted by Cookie My dorotation method: XYZ DoRotation(XYZ thePoint, float xang, float yang, float zang){ XYZ newpoint; if(xang){ xang*=6.283185; xang/=360; } if(yang){ yang*=6.283185; yang/=360; } if(zang){ zang*=6.283185; zang/=360; } if(yang){ newpoint.z=thePoint.z*cos(yang)-thePoint.x*sin(yang); newpoint.x=thePoint.z*sin(yang)+thePoint.x*cos(yang); thePoint.z=newpoint.z; thePoint.x=newpoint.x; } if(zang){ newpoint.x=thePoint.x*cos(zang)-thePoint.y*sin(zang); newpoint.y=thePoint.y*cos(zang)+thePoint.x*sin(zang); thePoint.x=newpoint.x; thePoint.y=newpoint.y; } if(xang){ newpoint.y=thePoint.y*cos(xang)-thePoint.z*sin(xang); newpoint.z=thePoint.y*sin(xang)+thePoint.z*cos(xang); thePoint.z=newpoint.z; thePoint.y=newpoint.y; } return thePoint; } where xyz is a class of 3 floats, x,y and z xang is rotation around x axis, etc. I hope this helps. Car relative vector to world relative vector - Cookie - Oct 4, 2002 11:16 PM
Actually, I see what you mean now OSC and codemattic, so I'll go with matrices. Currently i am storing the orientation of my car in a quarternion. How would I store it in a 3x3 matrix? Thanks. Car relative vector to world relative vector - OneSadCookie - Oct 5, 2002 03:55 AM
Oh, if you're storing the orientation as a quaternion, there's probably an even simpler solution than we've proposed... Unfortunately, I know nothing about quaternions, so I can't be of assistance. If you can turn it into the three vectors that my matrix method needed, you could still go that route... |