// Copyright NVIDIA Corporation 2007 -- Denis Kovacs #pragma once #ifndef NV_MESH_CLIPPEDTRIANGLE_H #define NV_MESH_CLIPPEDTRIANGLE_H #include namespace nv { class ClippedTriangle { public: ClippedTriangle(Vector2::Arg a, Vector2::Arg b, Vector2::Arg c) { m_numVertices = 3; m_activeVertexBuffer = 0; m_verticesA[0]=a; m_verticesA[1]=b; m_verticesA[2]=c; m_vertexBuffers[0] = m_verticesA; m_vertexBuffers[1] = m_verticesB; } uint vertexCount() { return m_numVertices; } const Vector2 * vertices() { return m_vertexBuffers[m_activeVertexBuffer]; } inline void clipHorizontalPlane(float offset, float clipdirection) { Vector2 * v = m_vertexBuffers[m_activeVertexBuffer]; m_activeVertexBuffer ^= 1; Vector2 * v2 = m_vertexBuffers[m_activeVertexBuffer]; v[m_numVertices] = v[0]; float dy2, dy1 = offset - v[0].y; int dy2in, dy1in = clipdirection*dy1 >= 0; uint p=0; for (uint k=0; k= 0; if (dy1in) v2[p++] = v[k]; if ( dy1in + dy2in == 1 ) // not both in/out { float dx = v[k+1].x - v[k].x; float dy = v[k+1].y - v[k].y; v2[p++] = Vector2(v[k].x + dy1*(dx/dy), offset); } dy1 = dy2; dy1in = dy2in; } m_numVertices = p; //for (uint k=0; k= 0; uint p=0; for (uint k=0; k= 0; if (dx1in) v2[p++] = v[k]; if ( dx1in + dx2in == 1 ) // not both in/out { float dx = v[k+1].x - v[k].x; float dy = v[k+1].y - v[k].y; v2[p++] = Vector2(offset, v[k].y + dx1*(dy/dx)); } dx1 = dx2; dx1in = dx2in; } m_numVertices = p; //for (uint k=0; k