简体   繁体   中英

how to convert world space transform to object space transform?

i'm trying to implement :

transform.InverseTransformPoint(Vector3) and transform.InverseTransformDirection(Vector3) using glm library in opengl. i have view ,projection ,model matrices for each object.

actually i don't know what i must to do with this matrices for got to that methods functionality.

Usually, a point in local space can be transformed to NDC space by doing the following math:

Pworld = M * Plocal;
Pview = V * Pworld;
Pndc = P * Pview;

where M = model, V = view and P = projection.

So, if you have a point in world coordinate system and want to get it in local coordinate system, you just have to invert the first equation:

Plocal = inv(M) * Pworld;

This should be equivalent to transform.InverseTransformPoint(Vector3) (just add a fourth coordinate vector H = 1)

To implement transform.InverseTransformDirection(Vector3) , which is not affected by scale, you must use this equation:

Plocal = transpose(inverse(M)) * Pworld

where M is the upper-left 3x3 matrix from your original Model. To understand why you sould use this math, I invite you to look at this page: normal transformation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM