Imagine an optional line with the four points A2, B2, C2 and D2.
1. Take these points and multiply them by their perspective and modelview matrix M.
As a result you'll get A, B, C and D in screen coordinates.
2. Calculate the line normal
3. Calculate the discriminant r by
where Vector4f.dot() calculates the dot product of these two vectors and Vector4f.sub() the difference vector.
4. draw the line between A2 and B2 only if r > 0
1. Take these points and multiply them by their perspective and modelview matrix M.
As a result you'll get A, B, C and D in screen coordinates.
Code:
Matrix4f.transform(M, A2, A);
Matrix4f.transform(M, B2, B);
Matrix4f.transform(M, C2, C);
Matrix4f.transform(M, D2, D);
2. Calculate the line normal
Code:
N.x = A.y - B.y;
N.y = B.x - A.x;
3. Calculate the discriminant r by
Code:
[b]r[/b] = Vector4f.dot(N, Vector4f.sub(C, A)) * Vector4f.dot(N, Vector4f.sub(D, A));
where Vector4f.dot() calculates the dot product of these two vectors and Vector4f.sub() the difference vector.
4. draw the line between A2 and B2 only if r > 0