Transforming Vector3 By Matrix??

Started by
5 comments, last by Muhammad Haggag 18 years, 8 months ago
Hi, Is it possible to transform a Vector3 class by a directx matrix class? I'm ussing Managed DirectX, July update, if that makes a difference. I need for my sub entities. So they can be repositioned when a entity higher up on the scene graph is rotated. Or is there a better altnative to handling sub/child entities/pivots updating? If not, do I have to write my own vector>matrix transform? I could do this, but I'd prefer it if someone posted a snippet so I could be sure my method matched what dx does internally, so there's no untracable bugs later on in development. Thanks.
Advertisement
Vector3 has static Transform() method which transforms a Vector3 with matrix. Notice that it returns Vector4. Usage:
Vector4 transformedVector = Vector3.Transform(vector, matrix);
Vector3.TransformCoordinate takes a matrix and transforms the vector by it in place. Vector3.TransformNormal for normals.

Assuming you have a 4x4 matrix, Matrix * Vector(x,y,z,0) transforms a normal and Matrix * Vector(x,y,z,1) transforms a point right?

What if you had a plane. (ax+by+cz+d=0, where (a,b,c) is the normal and d is the distance from the origin. Is that right?) Could you just do Matrix*Vector(a,b,c,d) to transform the plane?
Now that I think about it a plane can be defined with one point. If the point is A then the plane could be defined as the plane perpendicular to the vector A and passing through the point A. Then you can transform the plane by just transforming the point. This leads to the following formula for transforming planes:


Matrix4 matrix;
Plane plane;

Vector4 temp=matrix*Vector4(-plane.a*plane.d,-plane.b*plane.d,-plane.c*plane.d,1);
Vector3 normal=Vector3(-temp.x,-temp.y,-temp.z).normalize();
Plane transformedPlane=Plane(normal.x,normal.y,normal.z,-temp.length());

I'm going to go test this idea
Quote:Original post by dyerseve
Assuming you have a 4x4 matrix, Matrix * Vector(x,y,z,0) transforms a normal and Matrix * Vector(x,y,z,1) transforms a point right?

In computer graphics, when transforming normals is mentioned, it usuallymeans using the transpose of the inverse of the transformation matrix. Vector3.TransformNormal assumes that the matrix passed is already the transpose of the inverse (as indicated by the corresponding unmanaged documentation).

Quote:What if you had a plane. (ax+by+cz+d=0, where (a,b,c) is the normal and d is the distance from the origin. Is that right?) Could you just do Matrix*Vector(a,b,c,d) to transform the plane?

Yes, <a, b, c> is the normal and d is the signed distance from the origin. To rotate the plane, you can rotate its normal, substitute the coordinates of the point into the plane equation, and get 'd'.

Quote:Original post by dyerseve
Now that I think about it a plane can be defined with one point. If the point is A then the plane could be defined as the plane perpendicular to the vector A and passing through the point A.

A plane is defined by 3 non-collinear points, or a point and a normal. What you're using here is the point-normal method.

This topic is closed to new replies.

Advertisement