[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Pixel Location in 3D Space?



HandyGM wrote:
...

         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?

Hmm, looking for it, no, I can't, but it's something like this if I'm recalling correctly from way back when:


px - ax = S( Bx-Ax ) + T( Cx-Bx )
py - ay = S( By-Ay ) + T( Cy-By )

where the only unknowns are S and T, (since you know the U,V coordinates for each corner of the triangle and the pixel you're querying is in U,V coordinates). Substitute one (S or T) into the other equation, plug in the real values, and your first variable pops out, substitute into the other equation and you have the second variable.

You are taking a point on a (2D) plane as defined by two vectors (edges of the triangles) and determining how to get from one of the vertices to the target point as a function to the defining vectors.

+ 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

o So, for each pixel

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.

P = A + S( AB ) + T( BC )

That is, your two weighting factors for the edges of the triangle pulled from the texture-space are applied to the 3D edges of the triangle.

Of course, all of that is from a very rusty old brain, I may have missed something with the switch to 3D (IIRC there is a particular approach to this that winds up with warped textures), but I *think* that gives you a linear interpolation across the surface of the triangle.

Good luck,
Mike

--
________________________________________________
 Mike C. Fletcher
 Designer, VR Plumber, Coder
 http://www.vrplumber.com
 http://blog.vrplumber.com