[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Pixel Location in 3D Space?
Mike C. Fletcher wrote:
   * textures are mapped linearly across a triangle
         o All polygons can be reduced to triangles during tessellation
Thanks for your reply.
I just thought of a way to convert polygons to triangles, but didn't 
know what it was called. I understand how this is done.
         o The corner of each triangle has a texture coordinate, again,
           often generated during tessellation
Yes - I can extract these from the UV-mapped object.
         o For any point on the surface of the triangle, the pixel
           displayed is a linear blending of the texture coordinates of
           the 3 points of the triangle, you'll find an equation in the
           OpenGL spec for how that math works
Ah, there's the point I don't get. Do you have a link to the spot in the 
spec where this is discussed?
         o So, for each pixel
               + for each tessellated triangle
                     # for imagewidth in texture coordinate triangle width:
                           * for imageheight in texture coordinate
                             triangle height:
                                 o test if
                                   imagewidth+pixel,imageheight+pixel
                                   is within coordinate triangle
                                       + if it is:
                                             # take a linear blend of
                                               the 3D points of the
                                               triangle with the
                                               weights for the texture
                                               coordinates
That 'linear blend of the 3d points of the triangle with the weights for 
the texture coordinates' is the bit that's balking me. I can see how 
this loop would work, I just don't know the algorithm for assigning an 
XYZ point to the pixel.
Thanks for any additional hints you can lend me!
--Kamilche