Exemple #1
0
        public static MapJudgmentResult Judge(PositionXYZ position)
        {
            int pointCount = Map.Indices.Length;
            Line l1 = new Line(), l2 = new Line();
            Vector3 centor;
            Vector3 point = new Vector3((float)position.X, (float)position.Y, (float)position.Z);

            MapJudgmentResult result = new MapJudgmentResult() { mapOK = false, floorHeight = 0.0};

            for(int i = 0; i < pointCount; i += 3)
            {
                int i1 = Map.Indices[i], i2 = Map.Indices[i + 1], i3 = Map.Indices[i + 2];
                bool cross = false;

                if (Map.Vertices[i1].position.Y > point.Y - 0.5) continue;

                double cX = (Map.Vertices[i1].position.X + Map.Vertices[i2].position.X + Map.Vertices[i3].position.X) / 3.0;
                double cZ = (Map.Vertices[i1].position.Z + Map.Vertices[i2].position.Z + Map.Vertices[i3].position.Z) / 3.0;

                centor = new Vector3((float)cX, 0.0f, (float)cZ);

                l1.a = Map.Vertices[i1].position;
                l1.b = Map.Vertices[i2].position;
                l2.a = point;
                l2.b = centor;
                if (HitTestLine(l1, l2))
                    cross = true;

                l1.a = Map.Vertices[i1].position;
                l1.b = Map.Vertices[i3].position;
                l2.a = point;
                l2.b = centor;
                if (HitTestLine(l1, l2))
                    cross = true;

                l1.a = Map.Vertices[i2].position;
                l1.b = Map.Vertices[i3].position;
                l2.a = point;
                l2.b = centor;
                if (HitTestLine(l1, l2))
                    cross = true;

                if (!cross)
                {
                    result.mapOK = true;

                    if (Map.Vertices[i1].position.Y > result.floorHeight)
                        result.floorHeight = Map.Vertices[i1].position.Y;
                }
            }

            return result;
        }
Exemple #2
0
 public static SlimDX.Vector3 ConvertToSlimDXVector3(PositionXYZ position)
 {
     return new SlimDX.Vector3((float)position.X, (float)position.Y, (float)position.Z);
 }