Пример #1
0
        public DxMeshEntity Intersect(
            Vector3 rayPos,
            Vector3 rayDir)
        {
            double mindist = double.MaxValue;

            AdnPoint point = null;

            DxMeshEntity closestEntity = null;

            AdnRay ray = new AdnRay(
                new AdnPoint(
                    rayPos.X - _center.X,
                    rayPos.Y - _center.Y,
                    rayPos.Z - _center.Z),
                new AdnVector(
                    rayDir.X,
                    rayDir.Y,
                    rayDir.Z));

            foreach (var entity in _meshEntities.Values)
            {
                if (entity.Intersects(ray, ref point))
                {
                    double dist = ray.Origin.SquaredDistanceTo(point);

                    if (dist < mindist)
                    {
                        mindist = dist;
                        closestEntity = entity;
                    }
                }
            }

            return closestEntity;
        }
Пример #2
0
        public bool Intersects(
            AdnRay ray,
            ref AdnPoint point)
        {
            point = null;

            // Perform intersection test on bounding box
            // first for performances
            if (!_boundingBox.Intersects(ray))
                return false;

            double mindist = double.PositiveInfinity;

            for (int idx = 0; idx < _vertexBuffer.ElementCount; idx += 3)
            {
                AdnPoint p = null;

                if (ray.Intersect(
                    _vertices[idx],
                    _vertices[idx + 1],
                    _vertices[idx + 2],
                    out p))
                {
                    double dist = ray.Origin.SquaredDistanceTo(p);

                    if (dist < mindist)
                    {
                        mindist = dist;
                        point = p;
                    }
                }
            }

            return (point != null);
        }
Пример #3
0
        public bool Intersects(AdnRay ray)
        {
            if (ray.Intersect(_vertices[0], _vertices[1], _vertices[2]))
                return true;

            if (ray.Intersect(_vertices[2], _vertices[3], _vertices[0]))
                return true;

            if (ray.Intersect(_vertices[1], _vertices[5], _vertices[4]))
                return true;

            if (ray.Intersect(_vertices[4], _vertices[2], _vertices[1]))
                return true;

            if (ray.Intersect(_vertices[3], _vertices[2], _vertices[4]))
                return true;

            if (ray.Intersect(_vertices[4], _vertices[7], _vertices[3]))
                return true;

            if (ray.Intersect(_vertices[0], _vertices[7], _vertices[7]))
                return true;

            if (ray.Intersect(_vertices[7], _vertices[0], _vertices[6]))
                return true;

            if (ray.Intersect(_vertices[0], _vertices[1], _vertices[6]))
                return true;

            if (ray.Intersect(_vertices[1], _vertices[5], _vertices[6]))
                return true;

            if (ray.Intersect(_vertices[4], _vertices[7], _vertices[6]))
                return true;

            if (ray.Intersect(_vertices[6], _vertices[5], _vertices[4]))
                return true;

            return false;
        }