Some code snippets that might help…
Code that creates a mapping from s and t texture coordinates related to xyz positions…
gzVoid CMapTweaker::setMappingValues(const gzVec2 &st0 , const gzVec3 &xyz0 ,
const gzVec2 &st1 , const gzVec3 &xyz1 ,
const gzVec2 &st2 , const gzVec3 &xyz2 ,
const gzVec2 &st3 , const gzVec3 &xyz3 )
{
m_ST=gzMatrix4( gzVec4(1,st0.v1,st0.v2,st0.v1*st0.v2),
gzVec4(1,st1.v1,st1.v2,st1.v1*st1.v2),
gzVec4(1,st2.v1,st2.v2,st2.v1*st2.v2),
gzVec4(1,st3.v1,st3.v2,st3.v1*st3.v2));
m_ST.getInvertedMatrix(m_ST_inv);
m_XYZ=gzMatrix4(gzVec4(xyz0.v1,xyz0.v2,xyz0.v3,1),
gzVec4(xyz1.v1,xyz1.v2,xyz1.v3,1),
gzVec4(xyz2.v1,xyz2.v2,xyz2.v3,1),
gzVec4(xyz3.v1,xyz3.v2,xyz3.v3,1));
m_A=m_XYZ*m_ST_inv;
m_bInit = true;
}
and perhaps the most interesting part… Code that calculates texture coordinates from a generic xyz position or calculates xyz postion out of a texture coordinate
</font><blockquote><font size=“1” face=“Verdana, Arial”>code:</font><hr /><pre style=“font-size:x-small; font-family: monospace;”>
gzVec3 CMapTweaker::getXYZ(const gzVec2 &st)
{
ATLASSERT(m_bInit);
return gzVec3( m_A.v11 + m_A.v12st.v1 + m_A.v13st.v2 + m_A.v14st.v1st.v2,
m_A.v21 + m_A.v22st.v1 + m_A.v23st.v2 + m_A.v24st.v1st.v2,
m_A.v31 + m_A.v32st.v1 + m_A.v33st.v2 + m_A.v34st.v1st.v2 );
}
gzVec2 CMapTweaker::getST(const gzVec3 &xyz)
{
ATLASSERT(m_bInit);
gzFloat a=m_A.v14*m_A.v23-m_A.v13*m_A.v24;
gzFloat b=-m_A.v11*m_A.v24+m_A.v12*m_A.v23-m_A.v13*m_A.v22+m_A.v14*m_A.v21-m_A.v14*xyz.v2+m_A.v24*xyz.v1;
gzFloat c=-m_A.v11*m_A.v22+m_A.v12*m_A.v21-m_A.v12*xyz.v2+xyz.v1*m_A.v22;
gzDouble s,t;
if(a==0)
t=-c/b;
else
{
t=0.5*(-b+sqrt(b*b-4*a*c))/a;
if((t<-10)