Jump to content
  • Advertisement
Sign in to follow this  
ScopeDynamo

Transforming Vector3 By Matrix??

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Vector3 has static Transform() method which transforms a Vector3 with matrix. Notice that it returns Vector4. Usage:

Vector4 transformedVector = Vector3.Transform(vector, matrix);

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
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'.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!