Exemple #1
0
        /// <summary>
        /// Called when the 3D Engine wishes to render this element. This is where geometry must be drawn to the 3D scene
        /// </summary>
        /// <param name="e">The <see cref="IRenderPassInfo3D" /> containing parameters for the current render pass.</param>
        public override void RenderScene(IRenderPassInfo3D e)
        {
            if (_font == null)
            {
                return;
            }

            var currentCamera = RootSceneEntity != null ? RootSceneEntity.Viewport3D.CameraController : null;

            switch (_textDisplayMode)
            {
            case TextDisplayMode.Default:
            {
                // Just display text
                _font.Begin();
                _font.AddText(Text, _textColor, Location.X, Location.Y, Location.Z);
                _font.End();
                break;
            }

            case TextDisplayMode.FacingCameraAlways:
            {
                if (currentCamera == null)
                {
                    goto case TextDisplayMode.Default;
                }

                // Display billboarded text using camera vectors
                Vector3 cameraFwd = currentCamera.Forward;
                Vector3 cameraUp  = currentCamera.Up;

                // Compute a side vector
                Vector3 cameraSide = cameraFwd ^ cameraUp;
                cameraSide.Normalize();

                // Compute orthogonal up vector
                cameraUp = cameraSide ^ cameraFwd;
                cameraUp.Normalize();

                // Display text billboarded using camera side, up vectors (text will always face camera)
                _font.BeginBillboard(cameraSide, cameraUp);
                _font.AddText(Text, _textColor, Location.X, Location.Y, Location.Z);
                _font.End();
                break;
            }

            case TextDisplayMode.SacreenSpace:
            {
                // Screen space text 2D
                _font.BeginScreenSpace((float)RotationAngle, Location.X, Location.Y);
                _font.AddText(Text, _textColor, Location.X, Location.Y, Location.Z);
                _font.EndScreenSpace();
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        /// <summary>
        /// Called when the 3D Engine wishes to render this element. This is where geometry must be drawn to the 3D scene
        /// </summary>
        /// <param name="rpi">The <see cref="IRenderPassInfo3D" /> containing parameters for the current render pass.</param>
        public override void RenderScene(IRenderPassInfo3D rpi)
        {
            var currentCamera = RootSceneEntity != null ? RootSceneEntity.Viewport3D.CameraController : null;

            var locX = Location.X;
            var locY = Location.Y;
            var locZ = Location.Z;

            // Commented code belove is the example of treating the Location value
            // as 3D point in Data Coordinates Space but not in World Coordinates Space
            //locX = (float)e.XCalc.GetCoordinate(Location.X) - e.WorldDimensions.X / 2.0f;
            //locY = (float)e.YCalc.GetCoordinate(Location.Y);
            //locZ = (float)e.ZCalc.GetCoordinate(Location.Z) - e.WorldDimensions.Z / 2.0f;

            switch (_textDisplayMode)
            {
            case TextDisplayMode.Default:
            {
                // Just display text
                _font.Begin();
                _font.AddText(Text, _textColor, locX, locY, locZ);
                _font.End();
                break;
            }

            case TextDisplayMode.FacingCameraAlways:
            {
                if (currentCamera == null)
                {
                    goto case TextDisplayMode.Default;
                }

                // Display billboarded text using camera vectors
                Vector3 cameraFwd = currentCamera.Forward;
                Vector3 cameraUp  = currentCamera.Up;

                // Compute a side vector
                Vector3 cameraSide = cameraFwd ^ cameraUp;
                cameraSide.Normalize();

                // Compute orthogonal up vector
                cameraUp = cameraSide ^ cameraFwd;
                cameraUp.Normalize();

                // Display text billboarded using camera side, up vectors (text will always face camera)
                _font.BeginBillboard(cameraSide, cameraUp);
                _font.AddText(Text, _textColor, locX, locY, locZ);
                _font.End();
                break;
            }

            case TextDisplayMode.SacreenSpace:
            {
                // Screen space text 2D
                _font.BeginScreenSpace((float)RotationAngle, Location.X, Location.Y);
                _font.AddText(Text, _textColor, locX, locY, locZ);
                _font.EndScreenSpace();
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }