Calculation point in 3D polygon, from 2D texture coordinates

Started by
0 comments, last by openglaussie 16 years, 1 month ago
Basically what I'm looking for is a way to calculate the real position of a pixel in 3d world. I know the texture coordinates of that polygon(triangle), and it's 3d representation, i would like to loop through whole texture and retrieve positions for all points in it. so: for i = 0 to width for j = 0 to height if (i,j) in triangle_texture_coordinates point[i,j] = calculate( (i,j), triangle_texture_coordinates, triangle_positions )
Advertisement
there is no fast way to accomplish that , texture uv coords are normalized , thus you can cycle trhough 0..1 and get the correct index.
You can follow this algorithm

first you need a bilinear transofrmation beetween the points rendered in the surface and points in 3d , this is achieved retriving the point coordinate in space for each vertex.
Once you have that, compute the normal for this surface
write polygon rasterizing function.
when you have rasterized each polygon scan line pass the extremes for
this scan line in a function which computes the plane
equation like this
a * ( x-px0 ) +b * ( y-py0 ) +c* ( z-pz0 )=0;

a,b,c is the normal vector
px0,py0,pz0 is a point lying on the plane, usually is the first vertex
you obtain from polygon coordinates.
now in side the main loop you have the x,y,z values spanning all the polygon
and with the function above you can easily compute the z coordinate
By the way i think that this method is computationally expensive
what are you trying exactly to do ?

This topic is closed to new replies.

Advertisement