I got it.
It's much more complex than just transforming points. It all has to do with which way a mapper will most likely consider "up" and want the texture to point.
Have you ever had a routine you wrote, and have no idea how you got it wo work, except just by going on hunches and looking for patterns, until suddenly it works perfectly? This was almost up there with CSG.
Take a look at this crazy-ass code:
It's much more complex than just transforming points. It all has to do with which way a mapper will most likely consider "up" and want the texture to point.
Have you ever had a routine you wrote, and have no idea how you got it wo work, except just by going on hunches and looking for patterns, until suddenly it works perfectly? This was almost up there with CSG.
Take a look at this crazy-ass code:
Function TextureCoords(x#,y#,z#,nx#,ny#,nz#) If nz<0.0 nx=-nx ny=-ny nz=-nz EndIf If Abs(nx#)<0.0000001 And Abs(nz#)<0.0000001 texturev=z/64.0 textureu=x/64.0*Sgn(ny) Return EndIf If Abs(nx#)<0.0000001 And Abs(ny#)<0.0000001 texturev=y/64.0 textureu=x/64.0*-Sgn(nz) Return EndIf If Abs(nz#)<0.0000001 And Abs(ny#)<0.0000001 texturev=y/64.0 textureu=z/64.0*Sgn(nx) Return EndIf If Abs(nx)>Abs(nz) If Abs(ny)>Abs(nx) roll#=-90.0*Sgn(nx) EndIf If Abs(nx)<Abs(nz) If Abs(ny)>Abs(nz) If ny>0.0 If nz>0.0 roll#=180.0 EndIf If ny<0.0 If nz<0.0 roll#=180.0 EndIf EndIf EndIf If Abs(nx)>Abs(nz) And Abs(ny)>Abs(nz) nz=0 If Abs(nx)>Abs(ny) And Abs(nz)>Abs(ny) ny=0 If Abs(ny)>Abs(nx) And Abs(nz)>Abs(nx) nx=0 dx#=nx# dy#=ny# dz#=nz# dist#=Sqr#((dx#^2)+(dz#^2)) pitch#=ATan2((dy#),dist#) yaw#=ATan2(dx#,-dz#) matrix=createtransmatrix(x,y,z) matrix2=createrotmatrix3(pitch,yaw,roll) matrix3=mulmatrices(matrix,matrix2) textureu#=getmatrixelement(matrix3,4,1)/64.0 texturev#=getmatrixelement(matrix3,4,2)/64.0 FreeBank matrix FreeBank matrix2 FreeBank matrix3 Return