Car relative vector to world relative vector
hi everyone
I'm trying to make a simple 3D racing game, and I need to convert a carrelative velocity vector into a world coordinate velocity vector.
For my carrelative velocity vector, the Z axis is in straight out the windsheild, the xaxis 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
I'm trying to make a simple 3D racing game, and I need to convert a carrelative velocity vector into a world coordinate velocity vector.
For my carrelative velocity vector, the Z axis is in straight out the windsheild, the xaxis 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
I remember this! It's a basis transformation!
Um...
Yeah.
Um...
Yeah.
Oh boy, linear algebra!
Quote:Anton, "Elementary Linear Algebra", 7th ed.
Solution of the Change of Basis Problem. If we change the basis for a vector space V from some old basis B = {u1, u2, ..., un} to some new basis B' = {u'1, u'2, ..., u'n}, then the old coordinate matrix [v]B of a vector v is related to the new coordinate matrix [v]B' of the same vector v by the equation
[v]B = P[v]B'
where the columns of P are the coordinate matrices of the new basis vectors relative to the old basis; that is, the column vectors of P are
[u'1]B, [u'2]B, ..., [u'n]B
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 carrelative velocity vector.
I have no idea whether that's right though. I should really leave the math questions to the people who actually remember these things...
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.
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.
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?
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?
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!
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!
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.
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.
You have a car that is rotated and translated. How are you currently storing that rotation now? A quaternion? A 3x3 rotation matrix?
I would argue he is making his life *harder* by avoiding using matricies and things.
Quote:Originally posted by ededed
Just a second, you seem to be making this very complicated, using matrices and things.
I would argue he is making his life *harder* by avoiding using matricies and things.
Quote:Originally posted by Cookie
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.
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.
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.
Currently i am storing the orientation of my car in a quarternion. How would I store it in a 3x3 matrix?
Thanks.
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...
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...
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
What to do with vector graphics?  stevejohnson  4  6,609 
May 6, 2005 01:27 PM Last Post: stevejohnson 

topdown cameras. What to do with the up vector  reubert  10  4,964 
Apr 18, 2005 07:31 PM Last Post: Leisure Suit Lurie 