# Transforming Vector3 By Matrix??

This topic is 5176 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
Vector3 has static Transform() method which transforms a Vector3 with matrix. Notice that it returns Vector4. Usage:
Vector4 transformedVector = Vector3.Transform(vector, matrix);

##### Share on other sites
Vector3.TransformCoordinate takes a matrix and transforms the vector by it in place. Vector3.TransformNormal for normals.

##### Share on other sites
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?

##### Share on other sites
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

##### Share on other sites
Quote:
 Original post by dyerseveAssuming 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'.

##### Share on other sites
Quote:
 Original post by dyerseveNow 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.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 9
• 24
• 52
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!