POV-Ray : Newsgroups : povray.advanced-users : 3D texture mapping by triangulation method. My own approach to texture mapp= : 3D texture mapping by triangulation method. My own approach to texture mapp= Server Time
28 Jul 2024 14:23:01 EDT (-0400)
  3D texture mapping by triangulation method. My own approach to texture mapp=  
From: sonyafterdark
Date: 16 Jun 2005 04:55:01
Message: <web.42b13d8ab20c16507ce55a170@news.povray.org>
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.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.