コード例 #1
0
ファイル: Displacement.cs プロジェクト: maesse/CubeHags
        void SweptAABB_BuildTriList(Vector3 start, Vector3 end, Vector3 extends, int nodeid, AABB_t AABBox, TriList_t triList)
        {
            // get the current node
            Node_t node = m_pNodes[nodeid];

            //
            // fill in AABBox plane distances
            //
            AABBox.Dists[0] = -(node.m_BBox[0].X - ClipMap.EPSILON);
            AABBox.Dists[1] = (node.m_BBox[1].X + ClipMap.EPSILON);
            AABBox.Dists[2] = -(node.m_BBox[0].Y - ClipMap.EPSILON);
            AABBox.Dists[3] = (node.m_BBox[1].Y + ClipMap.EPSILON);
            AABBox.Dists[4] = -(node.m_BBox[0].Z - ClipMap.EPSILON);
            AABBox.Dists[5] = (node.m_BBox[1].Z + ClipMap.EPSILON);

            // test the swept box against the given node
            if (SweptAABB_NodeTest(start, end, extends, AABBox))
            {
                //
                // if leaf add tris to list
                //
                if ((node.m_fFlags & 0x01) > 0)
                {
                    if (triList.Count < DISPCOLL_TRILIST_SIZE)
                    {
                        triList.ppTriList[triList.Count] = m_pTris[node.m_iTris[0]];
                        triList.ppTriList[triList.Count + 1] = m_pTris[node.m_iTris[1]];
                        triList.Count += 2;
                    }

                    return;
                }
                // continue testing with children nodes
                else
                {
                    SweptAABB_BuildTriList(start, end, extends, Nodes_GetChild(nodeid, 0), AABBox, triList);
                    SweptAABB_BuildTriList(start, end, extends, Nodes_GetChild(nodeid, 1), AABBox, triList);
                    SweptAABB_BuildTriList(start, end, extends, Nodes_GetChild(nodeid, 2), AABBox, triList);
                    SweptAABB_BuildTriList(start, end, extends, Nodes_GetChild(nodeid, 3), AABBox, triList);
                }
            }
        }
コード例 #2
0
ファイル: Displacement.cs プロジェクト: maesse/CubeHags
        void SweptAABB_IntersectTriList(Vector3 start, Vector3 end, Vector3 extends, float startf, float endf, ref trace_t trace, TriList_t trilist)
        {
            Vector3 impactNormal = new Vector3();
            float impactDist = 0f;
            Tri_t tri;

            //
            // intersect against all the flagged triangles in trilist
            //
            for (int iTri = 0; iTri < trilist.Count; iTri++)
            {
                // get the current displacement
                tri = trilist.ppTriList[iTri];

                // intersection test
                IntersectAABoxSweptTriangle(start, end, extends,
                                     m_pVerts[tri.m_uiVerts[0]],
                                     m_pVerts[tri.m_uiVerts[2]],
                                     m_pVerts[tri.m_uiVerts[1]],
                                     tri.m_vecNormal, tri.m_flDist,
                                     tri.m_nFlags, tri.m_iSurfProp,
                    /*fraction,*/ref trace, true);

            }
        }
コード例 #3
0
ファイル: Displacement.cs プロジェクト: maesse/CubeHags
        public bool AABBSweep(Vector3 start, Vector3 end, Vector3 extends,
                              float startf, float endf, ref trace_t trace)
        {
            //
            // create and initialize the triangle list
            //
            TriList_t trilist = new TriList_t();

            //
            // create and initialize the primary AABB
            //
            AABB_t AABBox = new AABB_t();

            //
            // sweep box against the axial-aligned bboxed quad-tree and generate an initial
            // list of collision tris
            //
            SweptAABB_BuildTriList(start, end, extends, 0, AABBox, trilist);

            // save the starting fraction
            float preIntersectionFrac = trace.fraction;

            //
            // sweep axis-aligned bounding box against the triangles in the list
            //
            if (trilist.Count > 0)
            {
                SweptAABB_IntersectTriList(start, end, extends, startf, endf, ref trace, trilist);
            }

            // collision
            if (preIntersectionFrac > trace.fraction)
                return true;

            // no collision
            return false;
        }