Ejemplo n.º 1
0
        /// <summary>
        /// Performs a simple picking test against all triangles of this object.
        /// </summary>
        /// <param name="pickingRay">The picking ray.</param>
        /// <param name="distance">Additional picking options.</param>
        /// <param name="pickingOptions">The distance if picking succeeds.</param>
        public bool Intersects(Ray pickingRay, PickingOptions pickingOptions, out float distance)
        {
            distance = float.MaxValue;
            var result = false;

            for (var loop = 0; loop < _corners.Count; loop += 3)
            {
                ref var vertex1 = ref this.Owner.GetVertexBasicRef(_corners[loop].Index);
                ref var vertex2 = ref this.Owner.GetVertexBasicRef(_corners[loop + 1].Index);
Ejemplo n.º 2
0
        /// <summary>
        /// Performs a simple picking test against all triangles of this object.
        /// </summary>
        /// <param name="pickingRay">The picking ray.</param>
        /// <param name="distance">Additional picking options.</param>
        /// <param name="pickingOptions">The distance if picking succeeds.</param>
        public bool Intersects(Ray pickingRay, PickingOptions pickingOptions, out float distance)
        {
            var surfaceCount = _surfaces.Count;

            for (var loop = 0; loop < surfaceCount; loop++)
            {
                if (_surfaces[loop].Intersects(pickingRay, pickingOptions, out distance))
                {
                    return(true);
                }
            }

            distance = 0f;
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Performs an intersection test using given picking ray and picking options.
        /// </summary>
        /// <param name="pickingRay">The given picking ray.</param>
        /// <param name="pickingOptions">The picking options.</param>
        /// <param name="distance">The distance from origin to the picking point.</param>
        internal bool Intersects(Ray pickingRay, PickingOptions pickingOptions, out float distance)
        {
            distance = float.MaxValue;
            var result = false;

            for (var loop = 0; loop < _chunkTemplates.Length; loop++)
            {
                var actLoadedGeometry = _chunkTemplates[loop].Geometry;
                if (actLoadedGeometry.Intersects(pickingRay, pickingOptions, out var currentDistance))
                {
                    result = true;

                    if (currentDistance < distance)
                    {
                        distance = currentDistance;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Performs an intersection test using given picking ray and picking options.
        /// </summary>
        /// <param name="pickingRay">The given picking ray.</param>
        /// <param name="pickingOptions">The picking options.</param>
        /// <param name="distance">The distance from origin to the picking point.</param>
        public bool Intersects(Ray pickingRay, PickingOptions pickingOptions, out float distance)
        {
            distance = float.MaxValue;
            bool result = false;

            for (int loop = 0; loop < m_loadedStructures.Length; loop++)
            {
                VertexStructure actLoadedStructure = m_loadedStructures[loop].VertexStructure;

                float currentDistance = float.NaN;
                if (actLoadedStructure.Intersects(pickingRay, pickingOptions, out currentDistance))
                {
                    result = true;
                    if (currentDistance < distance)
                    {
                        distance = currentDistance;
                    }
                }
            }

            return(result);
        }
        /// <summary>
        /// Performs a simple picking test against all triangles of this object.
        /// </summary>
        /// <param name="pickingRay">The picking ray.</param>
        /// <param name="distance">Additional picking options.</param>
        /// <param name="pickingOptions">The distance if picking succeeds.</param>
        public bool Intersects(Ray pickingRay, PickingOptions pickingOptions, out float distance)
        {
            distance = float.MaxValue;
            bool result = false;

            for (int loop = 0; loop < m_indices.Count; loop += 3)
            {
                Vector3 vertex1 = m_owner.VerticesInternal[m_indices[loop]].Position;
                Vector3 vertex2 = m_owner.VerticesInternal[m_indices[loop + 1]].Position;
                Vector3 vertex3 = m_owner.VerticesInternal[m_indices[loop + 2]].Position;

                float currentDistance = 0f;
                if (pickingRay.Intersects(ref vertex1, ref vertex2, ref vertex3, out currentDistance))
                {
                    result = true;
                    if (currentDistance < distance)
                    {
                        distance = currentDistance;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Picks an object in 3D-World.
        /// </summary>
        /// <param name="rayStart">Start of picking ray.</param>
        /// <param name="rayDirection"></param>
        /// <param name="viewInfo">Information about the view that triggered picking.</param>
        /// <param name="pickingOptions">Some additional options for picking calculations.</param>
        /// <returns>
        /// Returns the distance to the object or float.NaN if object is not picked.
        /// </returns>
        internal override float Pick(Vector3 rayStart, Vector3 rayDirection, ViewInformation viewInfo, PickingOptions pickingOptions)
        {
            GeometryResource geometryResource = m_localResources[viewInfo.Device.DeviceIndex];

            if ((geometryResource != null) &&
                (geometryResource.IsLoaded))
            {
                BoundingBox boundingBox = geometryResource.BoundingBox;
                if (!boundingBox.IsEmpty())
                {
                    // Transform picking ray to local space
                    Ray       pickingRay = new Ray(rayStart, rayDirection);
                    Matrix4x4 temp;
                    Matrix4x4.Invert(base.Transform, out temp);
                    pickingRay.Transform(temp);

                    // Check for intersection on the bounding box
                    float distance = 0f;
                    if (pickingRay.Intersects(ref boundingBox, out distance))
                    {
                        if (pickingOptions.OnlyCheckBoundingBoxes)
                        {
                            return(distance);
                        }

                        // Perform picking on polygon level
                        if (geometryResource.Intersects(pickingRay, pickingOptions, out distance))
                        {
                            return(distance);
                        }
                    }
                }
            }

            return(float.NaN);
        }