Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As a previous reply suggests, keeping an up, forward and right vector is a good way to define a (Euclidean) coordinate space. Its even better if you add an origin as well, since you can represent a wider range of spaces.</p> <p>Lets say we have two spaces A and B, in A, up, forward and right are (0,1,0), (0,0,1) and (1,0,0) respectively, and the origin is at zero this gives the usual left-handed xyz coordinates for A. Say for B we have u=(ux,uy,uz), f=(fx,fy,fz) and r=(rx,ry,rz) with origin o = (ox,oy,oz). Then for a point at p = (x,y,z) in B we have in A (x*rx + y*ux + z*fx + ox, x*ry + y*uy + z*fy + oy, x*rz + y*uz + z*fz + oz).</p> <p>This can be arrived at by inspection. Observe that, since the right, up and forward vectors for B have components in each axis of A, a component of some coordinates in B must contribute to all three components of the coordinates in A. i.e. since (0,1,0) in B is equal to (ux,uy,uz), then (x,y,z) = y*u + (some other stuff). If we do this for each coordinate we have that (x,y,z) = x*r + y*u + z*f + (some other stuff). If we make the observation that the at the origin these terms vanish except for (some other stuff) then we realise that (some other stuff) must in fact be o, which gives the coordinates in A as x*r + y*u + z*f + o, which is (x*rx + y*ux + z*fx + ox, x*ry + y*uy + z*fy + oy, x*rz + y*uz + z*fz + oz) once the vector operations are expanded.</p> <p>This operation can be reversed as well, we just set the coordinates in A and solve equations to find them in B. e.g. (1,1,1) in A is equal to x*r + y*u + z*f + o in B. This gives three equations in three unknowns and can be solved by the method of simultaneous equations. I won't bother explaining that here... but here is a link if you get stuck: <a href="http://en.wikipedia.org/wiki/Simultaneous_equations" rel="nofollow noreferrer">link</a></p> <p>How does all of this relate to your original example of a bullet and a car? Well, if you rotate a set of up/right/forward vectors with the car, and update the origin as the car is translated you can move from world space to the car's local space and make some tests easier. e.g instead of transforming vertices for a collision model, you can transform the bullet into 'car local' space and use the local coordinates. This is handy if you are going to transform the car's vertices for rendering on a GPU, but don't want to suffer the overhead of reading that information back to use for physics calculations on the CPU.</p> <p>In other uses it can save you transforming x points by transforming three points and performing these operations instead, this allows you to combine x transformations on a large number of points without a significant performance hit over a single transformation across the same number of points.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload