Matrix operation to do this?

Started by
1 comment, last by Lord Crc 14 years, 5 months ago
I'm at a loss for the proper terminology to use here, so please bear with me. I want to update the world position of a vertex based on a velocity given in world space, but applied to a camera space basis. What I mean is, say my world space velocity is (0,100,0), I want to be able to transform my vertex along the "up" vector of my camera (given in world space) by 100. Or, if I pass in (100, 50, 0) in world space, I want to translate along my camera's "up" vector by 50 and along its "right" vector by 100, but the result should be in world space. This is the code I've come up with, and it seems to work, but I'm wondering if there is an existing operation to do this, or what this technique is called.
       
            //camera normalized Z
            this.cameraView.Normalize();

            //normalized X
            Vector3 camNormalizedRight = Vector3.Cross(this.cameraView, this.cameraUp);
            camNormalizedRight.Normalize();

            //normalized Y
            Vector3 camNormalizedUp = Vector3.Cross(camNormalizedRight, this.cameraView);
            camNormalizedUp.Normalize();

            Vector3 upPart    = cParticle.Velocity.Y * camNormalizedUp;
            Vector3 rightPart = cParticle.Velocity.X * camNormalizedRight;
            Vector3 zPart     = cParticle.Velocity.Z * this.cameraView;

            Vector3 particleVel = upPart + rightPart + zPart;


Advertisement
It looks like it's a simple matrix-vector multiplication that you're after. Using column-vector notation, it might look something like this:
matrix3x3 m = from_basis_vectors(cam.right, cam.up, cam.forward);vector3 transformed_velocity = m * velocity;
I'm not sure about your terminology though (in this case, the velocity would be more properly described as being given in the local space of the camera, and transformed to world space).
Quote:Original post by Penance
This is the code I've come up with, and it seems to work, but I'm wondering if there is an existing operation to do this, or what this technique is called.


The "technique" is called a "change of basis". The right/up/view vectors you created form an orthonormal basis for R^3. I'm assuming your "world space" is using the standard basis for R^3.

See for instance http://www.math.hmc.edu/calculus/tutorials/changebasis/changebasis.pdf for more details.

What you've coded is usually expressed as a matrix-vector product, like in the paper above.

This topic is closed to new replies.

Advertisement