Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

3 plane intersection and cross product question

$
0
0
Im doing GTK Radiant map importer, the file structure consists of some kind of surfaces that define a shape of object. So far i extract all surfaces, now i need to check if they collide with each other so i can define points out of it, however even when i have these surfaces calculted along with normals and distances i get some errors like: no 3 plane intersection at all, this might be something with crossproduct, calculation of normal (normalized or not?), or even with the 3plane intersection algo itself so here is the code maybe someone will find a problem (maybe i use wrong order since they use different handsystem i may doing something wrong - thus i calculate surfaces in my coord system (i believe its lefthanded [anyway the other one that quake3 uses]) so that shouldnt matter for crossproduct function itself but im so confused that i cant find an error; this is a function of a surface calculation just for your eyes, shouldnt matter void calc_plane(t3dpoint<T> p0, t3dpoint<T> p1, t3dpoint<T> p2, bool normalized) { n = Normal(p0,p1,p2, !normalized); //if (!normalized) n = Normalize(Norm); else n = Norm; x = (T)p0.x; y = (T)p0.y; z = (T)p0.z; A = (T)n.x; B = (T)n.y; C = (T)n.z; D = -(A*x + B*y + C*z); } int ClassifyPoint(t3dpoint<T> point) { T costam = dotproduct(point,n)+T(D); if (costam > 0) return isFront; if (costam < 0) return isBack; if (betweenorequal(T(-SPECIAL_FEATURE),T(SPECIAL_FEATURE),costam) == true) return isOnPlane; } //-------------------------- now the code that matters template <class type> t3dpoint<type> vectorcross(t3dpoint<type> v1,t3dpoint<type> v2) { t3dpoint<type> crossproduct; crossproduct.x = (v1.y*v2.z)-(v1.z*v2.y); crossproduct.y = (v1.z*v2.x)-(v1.x*v2.z); crossproduct.z = (v1.x*v2.y)-(v1.y*v2.x); return crossproduct; } original function bool GetIntersection ( n1, n2, n3, d1, d2, d3, &p ) { double denom = n1.Dot ( n2.Cross ( n3 ) ); if ( denom == 0 ) { return false; } p = -d1 * ( n2.Cross ( n3 ) ) – d2 * ( n3.Cross ( n1 ) ) – d3 * ( n1.Cross ( n2 ) ) / denom; return true; } now mine template <class T> bool Get3PlaneIntersection(t3dpoint<T> n1, t3dpoint<T> n2, t3dpoint<T> n3, T d1, T d2, T d3, t3dpoint<T> &p ) { double denom = Dot(n1, vectorcross(n2, n3) ); if (betweenorequal(-epsilona,epsilon, denom)) return false; //check if denominator is equal or very close to 0 t3dpoint<T> tmp = vectorcross(n2, n3) * -d1; t3dpoint<T> tmp2 = vectorcross(n3, n1) * -d2; t3dpoint<T> tmp3 = vectorcross(n1, n2) * -d3; p = (tmp+tmp2+tmp3) / denom; return true; } --------------------- maybe someone sees difference between my function and that original one

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>