Example #1
0
        /// <summary>
        /// Sets up the distance for the camera and light.
        /// </summary>
        public void setupZoom()
        {
            float zoomLevel = 0;
            float minValue  = int.MaxValue;
            float maxValue  = int.MinValue;
            float midPoint  = 0;

            if (mesh[0].Mesh.NumberFaces > 0)
            {
                for (int i = 0; i < mesh.Count; i++)
                {
                    if (!mesh[i].Enabled)
                    {
                        continue;
                    }

                    if (mesh[i].Min < minValue)
                    {
                        minValue = mesh[i].Min;
                    }

                    if (mesh[i].Max > maxValue)
                    {
                        maxValue = mesh[i].Max;
                    }

                    midPoint += mesh[i].calcMidPoint();
                }

                zoomLevel = (maxValue + Math.Abs(minValue)) * 2.0f;

                if (zoomLevel == 0.0f)
                {
                    zoomLevel = 1.0f;
                }

                midPoint /= mesh.Count;

                camera.Offset = new Vector3(0, midPoint, 0);                    // Offsets the camera to be in the middle of the object.
                camera.ZoomCamera(zoomLevel);                                   // Sets the camera's distance.

                for (int i = 0; i < 3; i++)
                {
                    lights[i].Distance = zoomLevel * 2.0f;
                }

                groundPlane.Size     = zoomLevel;
                groundPlane.MinValue = minValue;

                groundPlane.CreateGroundPlane(minValue, zoomLevel, 1.0f);
            }
        }