Jump to content
  • Advertisement
Sign in to follow this  
Toji

Tex-Coords - Matrix

This topic is 4902 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

Assuming you have a quad with default texture coords of (0,0) (0,1) (1,1) (1,0) clockwise, is there a way to take the actual texture coordinates and calculate the transform matrix that would be required to get from the default to the actual coords. For example: say the coordinates are (0,0) (0,2) (2,2) (2,0), then obviously the matrix simply scales by 2. It get's more complicated when you begin rotating and such, of course, which is why I'm curious if there's a general purpouse algorithim.

Share this post


Link to post
Share on other sites
Advertisement
I don't know if it is of much help, but my first thoughts are you are having a system of equations. Given four input vectors and four target vectors, compute a transformation T:

v1' = v1 T
v2' = v2 T
v3' = v3 T
v4' = v4 T

A system to be solved. But I think in general there is no solution for T. Just some thoughts.

Greetz,

Illco

Share this post


Link to post
Share on other sites
There should be a unique solution for 3 points. Although texture coordinates are 4-component and the texture matrix is a 4x4 matrix I'm assuming all the z-components are zero which effectively reduces you to a 3x3 matrix and 3-component coordinates. To get said unique solution you have to use matrix maths - I'm sure there's plenty of web pages about the inversion algorithm out there. The required maths looks something like this:

Since:

( 2 0 0 ) ( 0 0 1 ) ( 0 0 2 )
( 0 2 0 ) * ( 0 1 1 ) = ( 0 2 2 )
( 0 0 1 ) ( 1 1 1 ) ( 1 1 1 )

(Using the first 3 coordinates from your example)

You have to multiply both sides from the right by the inverse of your source coordinates, giving:

( 2 0 0 ) ( 0 0 2 ) ( 0 0 1 )^-1
( 0 2 0 ) = ( 0 2 2 ) * ( 0 1 1 )
( 0 0 1 ) ( 1 1 1 ) ( 1 1 1 )

Where the ^-1 means inverse. Luckily since your source coordinates are constant you can precalculate the inverse matrix, which gives:

( 0 -1 1 )
( -1 1 0 )
( 1 0 0 )

NB the last row in the matrices used gives the w-component (projective component) of the texture coordinates. This means that the target area doesn't necessarily have to be a rectange - it can be a trapezoid. If you just want to be able to rotate coordinates about the origin you can solve for 2 points but that removes the whole ability to distort the shape and do translations, which is really what homogenous coordinates are all about.

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!