bool Interp1Point3pZ(PointInfo &v, TLITVERTEX &vec1, TLITVERTEX &vec2, TLITVERTEX &vec3) { bool res = true; LineEuqationType line; Create1LineEq(line, vec2, vec3, vec1); v3 tempvec1(vec1.x, vec1.y, 0); double aDot = (v.x*line.x + v.y*line.y); double bDot = (vec1.x*line.x + vec1.y*line.y); double scale1 = ( - line.d - aDot) / ( bDot - aDot ); v3 tempv; v3 va(v.x, v.y, v.z); tempv = va + ((float)scale1 * (tempvec1 - va)); double s1 = (v.x-vec1.x)/(tempv.x-vec1.x); if( !_finite(s1) || abs(s1) > 100 ) { s1 = (v.y-vec1.y)/(tempv.y-vec1.y); if( !_finite(s1) ) return false; } double s2 = (tempv.x-vec2.x)/(vec3.x-vec2.x); if( !_finite(s2) || abs(s2) > 100 ) { s2 = (tempv.y-vec2.y)/(vec3.y-vec2.y); if( !_finite(s2) ) return false; } if( !_finite(s1) || !_finite(s2) ) { return false; } v.z = interp3p(vec1.z,vec2.z,vec3.z,s1,s2); return true; }
bool Interp1Point3p(PointInfo &v, TLITVERTEX &vec1, TLITVERTEX &vec2, TLITVERTEX &vec3, TLITVERTEX &out) { bool res = true; LineEuqationType line; Create1LineEq(line, vec2, vec3, vec1); v3 tempvec1(vec1.x, vec1.y, 0); double aDot = (v.x*line.x + v.y*line.y); double bDot = (vec1.x*line.x + vec1.y*line.y); double scale1 = ( - line.d - aDot) / ( bDot - aDot ); v3 tempv; v3 va(v.x, v.y, v.z); tempv = va + ((float)scale1 * (tempvec1 - va)); double s1 = (v.x-vec1.x)/(tempv.x-vec1.x); if( !_finite(s1) || abs(s1) > 100 ) { s1 = (v.y-vec1.y)/(tempv.y-vec1.y); if( !_finite(s1) ) return false; } double s2 = (tempv.x-vec2.x)/(vec3.x-vec2.x); if( !_finite(s2) || abs(s2) > 100 ) { s2 = (tempv.y-vec2.y)/(vec3.y-vec2.y); if( !_finite(s2) ) return false; } if( !_finite(s1) || !_finite(s2) ) { memcpy(&out, &vec3, sizeof(TLITVERTEX) ); RDP_NOIMPL_WARN("s1 or s2 is still infinite, it is a coplaner triangle"); return false; } out.x = v.x; out.y = v.y; out.z = v.z; //out.z = interp3p(vec1.z,vec2.z,vec3.z,s1,s2); out.rhw = interp3p(vec1.rhw,vec2.rhw,vec3.rhw,s1,s2); if( !_finite(out.z) || !_finite(out.rhw) || out.rhw < 0 ) { #ifdef _DEBUG if( out.rhw < 0 ) DebuggerAppendMsg("Warning: rhw<0"); else RDP_NOIMPL_WARN("Z or RHW value is #INF, check me as below"); DebuggerAppendMsg("vec1=[%f %f %f %f];\n",vec1.x, vec1.y, vec1.z, vec1.rhw); DebuggerAppendMsg("vec2=[%f %f %f %f];\n",vec2.x, vec2.y, vec2.z, vec2.rhw); DebuggerAppendMsg("vec3=[%f %f %f %f];\n",vec3.x, vec3.y, vec3.z, vec3.rhw); DebuggerAppendMsg("v=[%f %f];\n",v.x, v.y); DebuggerAppendMsg("v-out=[z=%f rhw=%f];\n",out.z, out.rhw); DebuggerAppendMsg("tempv=[%f %f %f];\n",tempv.x, tempv.y, tempv.z); DebuggerAppendMsg("s1=%f, s2=%f;\n",s1,s2); #endif return false; } if( out.z > 1 ) { RDP_NOIMPL_WARN("Warning: z>1"); return false; } out.dcSpecular = vec2.dcSpecular; //fix me here if( gRDP.tnl.Fog ) { float f1 = (vec1.dcSpecular >> 24)*vec1.rhw; float f2 = (vec2.dcSpecular >> 24)*vec2.rhw; float f3 = (vec3.dcSpecular >> 24)*vec3.rhw; float f = interp3p(f1,f2,f3,s1,s2)/out.rhw; if( f < 0 ) f = 0; if( f > 255 ) f = 255; uint32 fb = (uint8)f; out.dcSpecular &= 0x00FFFFFF; out.dcSpecular |= (fb<<24); }
void CreateLineEquations(TLITVERTEX &vec1, TLITVERTEX &vec2, TLITVERTEX &vec3) { Create1LineEq(alllines[0],vec1,vec2,vec3); Create1LineEq(alllines[1],vec1,vec3,vec2); Create1LineEq(alllines[2],vec2,vec3,vec1); }
void CreateLineEquations(TLITVERTEX &v1, TLITVERTEX &v2, TLITVERTEX &v3) { Create1LineEq(alllines[0],v1,v2,v3); Create1LineEq(alllines[1],v1,v3,v2); Create1LineEq(alllines[2],v2,v3,v1); }