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); }
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); } float r = interp3p(vec1.r*vec1.rhw,vec2.r*vec2.rhw,vec3.r*vec3.rhw,s1,s2)/out.rhw; if( r<0 ) r=0; if( r>255 ) r=255; out.r = (uint8)r; float g = interp3p(vec1.g*vec1.rhw,vec2.g*vec2.rhw,vec3.g*vec3.rhw,s1,s2)/out.rhw; if( g<0 ) g=0; if( g>255 ) g=255; out.g = (uint8)g; float b = interp3p(vec1.b*vec1.rhw,vec2.b*vec2.rhw,vec3.b*vec3.rhw,s1,s2)/out.rhw; if( b<0 ) b=0; if( b>255 ) b=255; out.b = (uint8)b; float a = interp3p(vec1.a*vec1.rhw,vec2.a*vec2.rhw,vec3.a*vec3.rhw,s1,s2)/out.rhw; if( a<0 ) a=0; if( a>255 ) a=255; out.a = (uint8)a;
out.dcSpecular = v2.dcSpecular; //fix me here if( gRDP.tnl.Fog ) { float f1 = (v1.dcSpecular>>24)*v1.rhw; float f2 = (v2.dcSpecular>>24)*v2.rhw; float f3 = (v3.dcSpecular>>24)*v3.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); } float r = interp3p(v1.r*v1.rhw,v2.r*v2.rhw,v3.r*v3.rhw,s1,s2)/out.rhw; if( r<0 ) r=0; if( r>255 ) r=255; out.r = (uint8)r; float g = interp3p(v1.g*v1.rhw,v2.g*v2.rhw,v3.g*v3.rhw,s1,s2)/out.rhw; if( g<0 ) g=0; if( g>255 ) g=255; out.g = (uint8)g; float b = interp3p(v1.b*v1.rhw,v2.b*v2.rhw,v3.b*v3.rhw,s1,s2)/out.rhw; if( b<0 ) b=0; if( b>255 ) b=255; out.b = (uint8)b; float a = interp3p(v1.a*v1.rhw,v2.a*v2.rhw,v3.a*v3.rhw,s1,s2)/out.rhw; if( a<0 ) a=0; if( a>255 ) a=255; out.a = (uint8)a;