View Full Version : How can i texture a polygon with more then 4 edges ??
05-14-2001, 03:19 AM
I want to make a textured polygon with, for example 7 edges or more. I only use 2d polygons. The polygons are irregular. How can i calculate the texture coordinates ???
Can anyone help me please ???
Use dot products. Make a rectangle that encloses your poly. Pick first and next vertex of this rectangle, call it edge B then do the same for first and last vertex and make edge C. Pick first vertex of rectangle enclosing a poly and first vertex of the poly and make edge A. Then do dot between A and B and A and C. I.e. dot product is (a dot b) / lengthA*lengthB. Then x over hypotenuse is cos of theta. But cosine of theta equals dot product so multiply hypotenuse i.e. length A by dot product to project the A's edge on edge B. Then do Projected edge length / length B to get percentage. Then use parametric equation subing percentage for the parameter like so: Rect vertex.u + percent * (rect vertex.u - rect vertex.u). That will give you u texture parameter i.e. x value. Do the same for edge C and A to get v or y value. Make sure that the first vertex of the rectangle enclosing your poly is top left corner of the texture i.e. texture space coords begin in upper left for directX. In opengl, ahhh I think bottom left but I don't use opengl so look it up for sure. I call this an absolute calculation because we're making texture coords based on a rectangle's upper left corner so we know that when we move to the right(edge B) we're moving u-value and when we move down(edge C) we're getting v-value.
Does anyone know how to rotate a texture on a poly and create correct texture coords after a poly is split? I did relative calculations of coords without the rectangle enclosing the poly by using poly's vertices but these suckers move with respect to texture space origin everytime I cut up a poly (I'm doing bsp style csg). It seems there isn't a way to pin it down unless I reorder the new vertices but keep texture coords the same after creating intersection vertices. Then when the texture is rotated I would have to somehow associate the vertex closest to the texture origin and make that the starting vertex so when I pass this poly down the bsp tree and it gets split up again I can use relative dot products to get new texture coords then have to check again the order of the vertices making sure the first vertex is closest to the texture origin. I guess I lost some of you but what the heck http://www.opengl.org/discussion_boards/ubb/smile.gif
Incidentally, I did this using the separate rect for each face with its own texture coords and then when I get a split I calculate dot between this rect edges and new intersection point. It works will see what happens when I rotate the texture and then do the splits.
[This message has been edited by JD (edited 05-14-2001).]
05-15-2001, 03:20 AM
JD.. Can automatic TExture generation fuction of OGL be a solution to that?
I don't know. Imagine you had a poly that evolved from splitting up its parent poly. The vertex order for this child poly will/might be different from its parent poly because as you split parent edge the intersection point is added to the front and back poly-vertex list thus becoming the first in the list. Then the edge formed from this to next intersection point is no longer parallel to the original or parent poly edge formed from first parent vertex to next parent vertex.
Thus the u and v could exchange positions and wrong texture coords would be created. How would automatic texture coordinate generation predict which vertex of the child should be the texture space origin? I haven't used auto texture generation so I might be wrong. What would happen if you rotated the texture around poly's center and then decided to split the parent obtaining a child poly and then issue auto texture generation? Would opengl/directx know that you've rotated the texture and that the child's u,v values march in different directions from the parent? I'll just have to look into auto text. gen. to know for sure. There is soo little info about this feature and am not sure if directx does it on cpu or if the video card's driver does it.
Thanks for your idea though... http://www.opengl.org/discussion_boards/ubb/smile.gif
[This message has been edited by JD (edited 05-15-2001).]
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.