inlib  1.2.0
Public Member Functions
inlib::a3::clip< T > Class Template Reference

List of all members.

Public Member Functions

 clip ()
virtual ~clip ()
void reset ()
void add (const vec< T > &a_point)
void execute (const plane< T > &plane)
const std::vector< vec< T > > & result () const

Detailed Description

template<class T>
class inlib::a3::clip< T >

Definition at line 427 of file a3.


Constructor & Destructor Documentation

template<class T >
inlib::a3::clip< T >::clip ( ) [inline]

Definition at line 429 of file a3.

:m_cur(0){}
template<class T >
virtual inlib::a3::clip< T >::~clip ( ) [inline, virtual]

Definition at line 430 of file a3.

{}

Member Function Documentation

template<class T >
void inlib::a3::clip< T >::add ( const vec< T > &  a_point) [inline]

Definition at line 440 of file a3.

                                  {
    m_data[m_cur].push_back(a_point);
  }
template<class T >
void inlib::a3::clip< T >::execute ( const plane< T > &  plane) [inline]

Definition at line 444 of file a3.

                                      {
    //Clip polygon against plane. This might change the number of
    //vertices in the polygon.

    unsigned int n = m_data[m_cur].size();
    if (n == 0) return;

    // create a loop :
    vec<T> dummy = m_data[m_cur][0];
    m_data[m_cur].push_back(dummy);

    const vec<T>& planeN = plane.normal();

    for(unsigned int i = 0; i < n; i++) {
      vec<T> v0 = m_data[m_cur][i];
      vec<T> v1 = m_data[m_cur][i+1];
  
      T d0 = plane.distance(v0);
      T d1 = plane.distance(v1);
  
      if (d0 >= 0.0f && d1 < 0.0f) { // exit plane
        vec<T> dir = v1-v0;
        // we know that v0 != v1 since we got here
        dir.normalize();
        T dot = dir.dot(planeN);
        vec<T> newvertex = v0 - dir * (d0/dot);
        out_point(newvertex);
      } else if (d0 < 0.0f && d1 >= 0.0f) { // enter plane
        vec<T> dir = v1-v0;
        // we know that v0 != v1 since we got here
        dir.normalize();
        T dot = dir.dot(planeN);
        vec<T> newvertex = v0 - dir * (d0/dot);
        out_point(newvertex);
        out_point(v1);
      } else if (d0 >= 0.0f && d1 >= 0.0f) { // in plane
        out_point(v1);
      }
    }
    m_data[m_cur].clear();
    m_cur ^= 1;
  }
template<class T >
void inlib::a3::clip< T >::reset ( ) [inline]

Definition at line 435 of file a3.

               {
    m_data[0].clear();
    m_data[1].clear();
    m_cur = 0;
  }
template<class T >
const std::vector< vec<T> >& inlib::a3::clip< T >::result ( ) const [inline]

Definition at line 487 of file a3.

                                            {
    return m_data[m_cur];
  }

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines