The MASM Forum

General => The Workshop => Topic started by: Farabi on April 09, 2014, 07:31:38 PM

Title: Overlaped Triangle
Post by: Farabi on April 09, 2014, 07:31:38 PM
(http://farabidatacenter.url.ph/MainSystem/MainData/Intersection.png)

I cant stop thinking about this. Anyone had information on how to calculate an overlaped triangle? I already know how to calculcate an intersected triangle but not an overlaped one. Thanks for any info. This is the 3rd day I dont have enough sleep thinking about this. Im so curious.
Title: Re: Overlaped Triangle
Post by: Siekmanski on April 09, 2014, 08:51:37 PM
Calculate the average z value of the three points per triangle.
Don't use the z-buffer.
Sort the triangles by the average z values and draw them from back to front.
Title: Re: Overlaped Triangle
Post by: Farabi on April 09, 2014, 09:15:13 PM
Quote from: Siekmanski on April 09, 2014, 08:51:37 PM
Calculate the average z value of the three points per triangle.
Don't use the z-buffer.
Sort the triangles by the average z values and draw them from back to front.

Hi siekmansie.
No it was not a renderer problem its a collission detect problem. Im trying to create a physic engine. But thanks for your attention.
Title: Re: Overlaped Triangle
Post by: Farabi on April 11, 2014, 11:42:10 PM
Anyone knew who is the first person who invent this formula?

private bool PointInTriangle(Vector3[] TriangleVectors, Vector3 P)
    {
        Vector3 A = TriangleVectors[0], B = TriangleVectors[1], C = TriangleVectors[2];
        if (SameSide(P, A, B, C) && SameSide(P, B, A, C) && SameSide(P, C, A, B))
        {
            Vector3 vc1 = Vector3.Cross(Vector3.Subtract(A, B), Vector3.Subtract(A, C));
            if (Math.Abs(Vector3.Dot(Vector3.Subtract(A, P), vc1)) <= .01f)
                return true;
        }

        return false;
    }

    private bool SameSide(Vector3 p1, Vector3 p2, Vector3 A, Vector3 B)
    {
        Vector3 cp1 = Vector3.Cross(Vector3.Subtract(B, A), Vector3.Subtract(p1, A));
        Vector3 cp2 = Vector3.Cross(Vector3.Subtract(B, A), Vector3.Subtract(p2, A));
        if (Vector3.Dot(cp1, cp2) >= 0) return true;
        return false;

    }


I think 3D technology is only the past 40 years, but it amazingly fast. The discovery of the 3D math is superb. I think it took 3 century before we can enhance pytagoras formula, but then 3D formula suddenly appear. Anyone maybe know how this is invented? How did they discover it and they did the research? I wanted to understand their paradigm.