コード例 #1
0
ファイル: KDop.cs プロジェクト: chargen/AGI-X0
        // from http://stackoverflow.com/questions/2168055/k-dop-collision-between-different-k-and-volumes
        public static bool checkIntersect(KDop a, KDop b)
        {
            Debug.Assert(a.k == b.k);

            for (int i = 0; i < a.k / 2; i++)
            {
                if ((a.min[i] > b.max[i]) || (a.max[i] < b.min[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #2
0
ファイル: KDop.cs プロジェクト: chargen/AGI-X0
        // based on http://stackoverflow.com/questions/2168055/k-dop-collision-between-different-k-and-volumes
        public static bool checkIntersectAabb(KDop other, KDop aabb)
        {
            Debug.Assert(other.baseVectorsStartWithAabb);
            Debug.Assert(aabb.baseVectorsStartWithAabb); // must be AABB

            for (int i = 0; i < 3; i++)                  // we just have to check the first 3 base vectors
            {
                if ((other.min[i] > aabb.max[i]) || (other.max[i] < aabb.min[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #3
0
ファイル: KDop.cs プロジェクト: chargen/AGI-X0
        public static KDop makeAabbKDopByCenterAndRadius(SpatialVectorDouble center, double radius)
        {
            Debug.Assert(radius > 0.0);

            KDop result = new KDop(KDop.BASEVECTORSOFKDOP6, 6, true);

            result.min[0] = center.x - radius;
            result.min[1] = center.y - radius;
            result.min[2] = center.z - radius;
            result.max[0] = center.x + radius;
            result.max[1] = center.y + radius;
            result.max[2] = center.z + radius;

            return(result);
        }
コード例 #4
0
ファイル: KDop.cs プロジェクト: chargen/AGI-X0
        public static KDop calculateKdopFromVerticesAndbaseVectors(IList <SpatialVectorDouble> vertices, SpatialVectorDouble[] baseVectors, bool baseVectorsStartWithAabb)
        {
            uint k = (uint)baseVectors.Length * 2;

            KDop result = new KDop(baseVectors, k, baseVectorsStartWithAabb);

            foreach (SpatialVectorDouble iterationVertex in vertices)
            {
                for (int baseVectorI = 0; baseVectorI < baseVectors.Length; baseVectorI++)
                {
                    double dotWithIterationVector = SpatialVectorDouble.dot(iterationVertex, baseVectors[baseVectorI]);
                    result.min[baseVectorI] = System.Math.Min(result.min[baseVectorI], dotWithIterationVector);
                    result.max[baseVectorI] = System.Math.Max(result.max[baseVectorI], dotWithIterationVector);
                }
            }

            return(result);
        }