|
|
>>> Help, Math wizards, you're my only hope.
>
>> Try the attached.
>
> Yeah baby! There's nothing like a copy/paste solution that I almost
> understand, but does exactly what I want. ;)
> I can't wait to try it out on non-solid, non-spherical shapes.
>
> Thanks!
:-)
What you're trying to do is transform some kind of "screen" coordinates
into world coordinates. What I did was to calculate the directions of
the "new" x,y,z axes and then use those to transform the original
coordinate to the actual world coordinate:
> #local newZ = vnormalize( Lookat-Camera );
The new Z axis direction should be from Camera to Lookat, this is what
you want. vnormalize makes sure it's a unit length vector.
> #local newY = y;
The new Y axis direction is just y to start (it will be fixed later).
> #local newX = vnormalize(vcross(newY,newZ));
The new X axis direction is perpendicular to the Z and Y defined in the
above two lines (ie to the right). X and Z are now correct, but Y needs
to be adjusted to take account of Z probably not being horizontal (Y
needs to be "tipped back" a bit).
> #local newY = vnormalize(vcross(newZ,newX));
The new Y is now calculated as perpendicular to the Z and X just
calculated. This is correct now, with all 3 perpendicular to each other.
> #local bar = bar.x * newX + bar.y * newY + bar.z * newZ;
This line essentially takes the original xyz coordinates and transforms
them using the new XYZ axes. There are neater ways to do this, but I
thought this made it a little more clear what is going on.
Note the new coordinates are relative to the camera, so you still need
the translate camera line.
Post a reply to this message
|
|