Skip to main content
gamedev.net
🔒 Locked

Planar mapping Help

Started by maxx126 1 reply 800+ views
Original Post
maxx126
maxx126
Hi, I''ve searched the forum but i couldn''t find an answer to my question so i''m posting here. I wonder how can i calculate the correct uv for the vertices of a polygon if i use an arbitrary direction when i do planar mapping?. For example not one of the standards like 1,0,0 (YZ plane) but 0.5, 0.5, 0. Another example would be the way 3dsmax uvwmap modifier calculates new uv coordinates when you move the plane gizmo for planar mapping. Thank You
RheniumIodide
RheniumIodide
I am working on the EXACT same thing right now, and I think I know how to do it.

How much linear algebra do you know? This explanation is fairly linear-intensive, but it sounds like you are familiar with mappings, etc.

Here goes:

Your plane, as Anonymous pointed out, is the set of all linear combinations of two basis vectors, which, I am guessing, correspond to the x and y coordinates on the screen. Let''s call those two vectors A and B.

These two vectors should be orthogonal to each other (perpendicular), unless you want a weird skewed picture. You will also have a third vector, N, which is your plane''s normal vector (points "out" perpendicular to the plane.)

These three vectors are now all orthogonal to each other, and they form a new basis for R3 (basically, 3D space). So what you want to do, I think (at least, this is what I want do to) is represent each point in R3 as a combination of multiples of A, B, and N. And then, since you are basically throwing away the "how far away is the object" aspect, you throw away the N component. This should leave you with two variables that correspond to where on the screen the point will map to.

Let''s call the original point in R3 S, and the point it maps to P. where P = [Px, Py, Pz] and S = [Sx, Sy, Sz]. So we have:

S = (some linear combination of A,B, and N)
S = u*A + v*B + w*N
S = [A, B, N][u, v, w]

[c1, c2, c3] is your new point, and I guess you''ll throw away c3, because that just tells you "how far away" the vertex is from the observer (though this information is probably useful in a more complicated mapping).

Note that [A, B, N] is actually a 3x3 matrix. There are three entries in each of those basis vectors. Let''s call this matrix T. Now:

S = TP
P = (T^-1)S

so now you have to find T inverse. You''re guaranteed that T is invertible, because all three of those basis vectors are linearly independent. When you invert T, you will have another 3x3 matrix which, when multiplied by S, will give you your three new coordinates.

I haven''t actually implemented this in my project yet (I''m about to try it out right now), and I''ve done a fair bit of footwork and made it pretty easy for myself to work with matrices and vectors. I''m pretty sure the math is solid, but I can''t gaurantee you''ll get the result you want.

-Reid





Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.