Jump to content
  • Advertisement
Sign in to follow this  
Vishy

My approach to texture mapping. Triangulation. Need help...

This topic is 4872 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Please help!!! I've a system of 3 pairs of distances. Each pair consists of a spatial distance and a distance inside a plane. A 3d distance and a 2d distance. As you might have guessed, this system holds 3 texture mapping equations. I need it solved for Xm and Ym. sqrt(sqr(Xr-X1)+sqr(Yr-Y1)+sqr(Zr-Z1))=sqrt(sqr(Xm-Xt1)+sqr(Ym-Yt1)) and sqrt(sqr(Xr-X2)+sqr(Yr-Y2)+sqr(Zr-Z2))=sqrt(sqr(Xm-Xt2)+sqr(Ym-Yt2)) and sqrt(sqr(Xr-X3)+sqr(Yr-Y3)+sqr(Zr-Z3))=sqrt(sqr(Xm-Xt3)+sqr(Ym-Yt3)) which is the same with sqr(Xr-X1)+sqr(Yr-Y1)+sqr(Zr-Z1)=sqr(Xm-Xt1)+sqr(Ym-Yt1) and sqr(Xr-X2)+sqr(Yr-Y2)+sqr(Zr-Z2)=sqr(Xm-Xt2)+sqr(Ym-Yt2) and sqr(Xr-X3)+sqr(Yr-Y3)+sqr(Zr-Z3)=sqr(Xm-Xt3)+sqr(Ym-Yt3) Xr,Yr,Zr vary from case to case but whichever Pr(Xr,Yr,Zr), it is contained in the plane defined by P1(X1,Y1,Z1), P2(X2,Y2,Z2) and P3 (X3,Y3,Z3). It is also inside the triangle these form. It is the intersection between the projector ray for a given screen pixel and some (the given) polygon. X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3 also vary from case to case. These are the coordinates (in space) of the 3 triangle tips of the polygon to be texture mapped. Evidently these can be rotated and/or translated but P1, P2, P3 do not move in relation to each other. That would make the whole thing pointless, wouldn't it? Xt1,Yt1,Xt2,Yt2,Xt3,Yt3 are unique to each polygon to be texture mapped. They are calculated when the 3D scene is loaded and never change. Not unless I morph polygons which I don't do(right now). They are the texture coordinates assigned to each polygon tip. So the distances between P1(X1,Y1,Z1), P2(X2,Y2,Z2) and P3(X3,Y3,Z3) don't change and are unique to each polygon. Otherwise it would mean i morph the polygon. Xm, Ym=?(u, v texture coordinates) Please help!!! I tried changing the Xts and Yts as follows: Xt1=0; Yt1=0; Xt2=distance between P1(X1,Y1,Z1) and P2(X2,Y2<Z2); Yt2=0; Xt3=[sqr(d(P3,P1))+sqr(d(P2,P1))-sqr(d(P3,P2))]/[2*d(P2,P1)]; Yt3=SQRT(sqr(d(P2,P1))-sqr(Xt3)) to obtain a "FIXED" polygon surface 2D coordinate system. Note that d(P1,P2) means the distance between P1 and P2. P1 is the origin (0,0). The line defined by P1 & P2 is the abcissa. It is then obious that P2's ordinate coordinate is 0 whereas its abcissa coordinate is the actual distance from itself to the origin (P1). Also obvious is that the distance from P3 to the line defined by P1 & P2 is P3's ordinate coordinate and the distance from P3's projection on the edge defined by P1 & P2 to P1 itself (the origin of the system) is its abcissa coordinate. All this leads me to logically conclude that Xm=[(Xr-X1)*(X2-X1)+(Yr-Y1)*(Y2-Y1)+(Zr-Z1)*(Z2-Z1)]/SQRT(SQR(X2-X1)+SQR(Y2-Y1)+SQR(Z2-Z1)); Ym=not yet solved; Ray tracing: Knowing that CurrentScreenXcoord=(Xr/Zr*ViewAngle)+HalfXResolution we know that Xr=(CurrentScreenPixelXcoord-HalfXResolution)*Zr/ViewAngle. This applies to Yr as well: Yr=(CurrentScreenPixelYcoord-HalfYResolution)*Zr/ViewAngle. According to the 3 point definition of a plane we also know: Zr=[X1*(Y2*Z3-Y3*Z2)+X2*(Y3*Z1-Y1*Z3)+X3*(Y1*Z2-Y2*Z1)]/[X1*(Y2-Y3)+X2*(Y3-Y1)+X3*(Y1-Y2)+((CurrentScreenPixelXcoord-Ha lfXResolution)*(Y1*(Z2-Z3)+Y2*(Z3-Z1)+Y3*(Z1-Z2))+(CurrentScreenPixelYcoord-HalfYResolution)*(X1*(Z3-Z2)+X2*(Z1-Z3)+X3* (Z2-Z1))/ViewAngle] I hope i've transcribed everything correct from my notebook. My problem is that the calculations get horrendously complicated altough they seem humanly solvable at this stage, at least. I fill 2 rows just writing the thing. But if I try solving the system for Xm, Ym without establishing a polygon coordinate system, so I have the freedom to choose whatever one I want later, then things get even worse. If there's anything you can do to help (like solving the system with algebrator or something), please, do help. Thanx forwardedly (not just for having the patience to read through)!!! Already posted to FreePascal.org, Chip.ro and lots of math forums to no avail.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!