Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Rightclick on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: Idahosa Edokpayi <idahosae@sw...>  20020331 11:18:20

Here is the new code for my triangle class incorporating most of the recommendations Jackie Chan and Angel Popov made. What I would still like to know is: What happens to triangles that are "on"? They do not intersect, they are not above, and not below yet they are in the BSP and not rejected. This somehow seems like it would be bad thing just waiting to bite an unsuspecting coder in the butt. Also, I want to know, what are the ramifications if I actually do write triangle intersection code using separating axis theorem or whatever I am convinced is the fastest way to do it and I substitute that for my current triangle intersection code? The code I have now detects PLANE intersection. By using strict triangle intersection would I be jacking up the semantics of my BSP system? #ifndef TRIANGLE_H #define TRIANGLE_H #include "mathcore.h" template <class vector, class matrix, class plane > class triangle { private: vector m_vVertices[3]; plane m_Plane; // speed up BSP comparisons static scalar m_Epsilon; public: triangle(){} triangle( const vector& v1, const vector& v2, const vector& v3 ) { m_vVertices[0] = v1; m_vVertices[1] = v2; m_vVertices[2] = v3; PlaneFromPoints( m_Plane, m_vVertices[0], m_vVertices[1], m_vVertices[2] ); } triangle( const vector* pvVertices ) { m_vVertices[0] = pvVertices[0]; m_vVertices[1] = pvVertices[1]; m_vVertices[2] = pvVertices[2]; PlaneFromPoints( m_Plane, m_vVertices[0], m_vVertices[1], m_vVertices[2] ); } ~triangle(){} // modifier void setVertex( const vector& v, const unsigned int index ) { m_vVertices[index%3] = v; PlaneFromPoints( m_Plane, m_vVertices[0], m_vVertices[1], m_vVertices[2] ); } // operators // assignment triangle& operator=( const triangle& tri ) { m_vVertices[0] = tri .m_vVertices[0]; m_vVertices[1] = tri .m_vVertices[1]; m_vVertices[2] = tri .m_vVertices[2]; PlaneFromPoints( m_Plane, m_vVertices[0], m_vVertices[1], m_vVertices[2] ); } // array operator const vector& operator[]( const unsigned int index ) const { return m_vVertices[index%3]; } // comparison for BSP partitioning bool operator < ( const triangle& tri ) const { if( SignedDistanceToPoint( m_Plane, tri[0] ) < triangle::m_Epsilon && SignedDistanceToPoint( m_Plane, tri[1] ) < triangle::m_Epsilon && SignedDistanceToPoint( m_Plane, tri[2] ) < triangle::m_Epsilon ) return true; return false; } bool operator > ( const triangle& tri ) const { if( SignedDistanceToPoint( m_Plane, tri[0] ) > triangle::m_Epsilon && SignedDistanceToPoint( m_Plane, tri[1] ) > triangle::m_Epsilon && SignedDistanceToPoint( m_Plane, tri[2] ) > triangle::m_Epsilon ) return true; return false; } // plane intersection bool operator == ( const triangle& tri ) const { return ( !(*this < tri) && !(*this > tri) ); } enum cmp { ABOVE, BELOW, ON, INTERSECTING }; // test point comparison cmp Compare( const vector& v ) { // above or below scalar sTest = SignedDistanceToPoint( m_Plane, v ); if( sTest > triangle::m_Epsilon ) return ABOVE; else if( sTest < triangle::m_Epsilon ) return BELOW; return ON; } cmp Compare( const triangle& tri ) { // use separating axis fool! return ABOVE; } }; #endif Idahosa Edokpayi 