コード例 #1
0
ファイル: Viewer.cs プロジェクト: elix22/Effekseer
        public void UpdateViewer()
        {
            if (isViewerShown)
            {
                if ((IsChanged && (IsPlaying || IsPaused)) || IsRequiredToReload)
                {
                    if (IsRequiredToReload)
                    {
                        Reload(true);
                    }
                    else
                    {
                        Reload(false);
                    }

                    IsChanged          = false;
                    IsRequiredToReload = false;
                }

                if (IsPlaying && !IsPaused)
                {
                    var stepFrame = Manager.NativeManager.GetDeltaSecond() * 60.0f;

                    // regard as 1 frame because of accuracy problem
                    if (Math.Abs(1.0f - stepFrame) < 0.05f)
                    {
                        stepFrame = 1.0f;
                    }

                    // large step is not better than slow
                    stepFrame = Math.Min(stepFrame, 4);

                    StepViewer(stepFrame, true);
                }

                // update environment
                var renderParam = EffectRenderer.GetParameter();
                renderParam.IsGroundShown = Core.Environment.Ground.IsShown.Value;
                renderParam.GroundHeight  = Core.Environment.Ground.Height.Value;
                renderParam.GroundExtent  = Core.Environment.Ground.Extent.Value;

                renderParam.BackgroundColor = new swig.Color
                {
                    R = (byte)Core.Environment.Background.BackgroundColor.R,
                    G = (byte)Core.Environment.Background.BackgroundColor.G,
                    B = (byte)Core.Environment.Background.BackgroundColor.B,
                    A = 255,
                };

                renderParam.LightDirection = new swig.Vector3F
                {
                    X = Core.Environment.Lighting.LightDirection.X,
                    Y = Core.Environment.Lighting.LightDirection.Y,
                    Z = Core.Environment.Lighting.LightDirection.Z,
                };

                renderParam.LightColor = new swig.Color
                {
                    R = (byte)Core.Environment.Lighting.LightColor.R,
                    G = (byte)Core.Environment.Lighting.LightColor.G,
                    B = (byte)Core.Environment.Lighting.LightColor.B,
                    A = (byte)Core.Environment.Lighting.LightColor.A
                };

                renderParam.LightAmbientColor = new swig.Color
                {
                    R = (byte)Core.Environment.Lighting.LightAmbientColor.R,
                    G = (byte)Core.Environment.Lighting.LightAmbientColor.G,
                    B = (byte)Core.Environment.Lighting.LightAmbientColor.B,
                    A = (byte)Core.Environment.Lighting.LightAmbientColor.A
                };

                renderParam.Distortion = (swig.DistortionType)(int) Core.Option.DistortionType.Value;

                renderParam.RenderingMethod = (swig.RenderingMethodType)(int) Core.Option.RenderingMode.Value;

                EffectRenderer.SetParameter(renderParam);

                EffectRenderer.LoadBackgroundImage(Core.Environment.Background.BackgroundImage.AbsolutePath);

                EffectRenderer.GridColor = new swig.Color
                {
                    R = (byte)Core.Option.GridColor.R,
                    G = (byte)Core.Option.GridColor.G,
                    B = (byte)Core.Option.GridColor.B,
                    A = (byte)Core.Option.GridColor.A
                };

                EffectRenderer.GridLength    = Core.Option.GridLength;
                EffectRenderer.IsGridShown   = Core.Option.IsGridShown;
                EffectRenderer.IsGridXYShown = Core.Option.IsXYGridShown;
                EffectRenderer.IsGridXZShown = Core.Option.IsXZGridShown;
                EffectRenderer.IsGridYZShown = Core.Option.IsYZGridShown;

                if (Core.Culling.Type.Value == Data.EffectCullingValues.ParamaterType.Sphere)
                {
                    EffectRenderer.IsCullingShown    = true;
                    EffectRenderer.CullingRadius     = Core.Culling.Sphere.Radius.Value;
                    EffectRenderer.CullingPosition.X = Core.Culling.Sphere.Location.X;
                    EffectRenderer.CullingPosition.Y = Core.Culling.Sphere.Location.Y;
                    EffectRenderer.CullingPosition.Z = Core.Culling.Sphere.Location.Z;
                }
                else if (Core.Culling.Type.Value == Data.EffectCullingValues.ParamaterType.None)
                {
                    EffectRenderer.IsCullingShown    = false;
                    EffectRenderer.CullingRadius     = 0.0f;
                    EffectRenderer.CullingPosition.X = 0.0f;
                    EffectRenderer.CullingPosition.Y = 0.0f;
                    EffectRenderer.CullingPosition.Z = 0.0f;
                }

                ViewPointController.SetMouseInverseFlag(
                    Core.Option.MouseRotInvX,
                    Core.Option.MouseRotInvY,
                    Core.Option.MouseSlideInvX,
                    Core.Option.MouseSlideInvY);
            }
            else
            {
                System.Threading.Thread.Sleep(1);
            }
        }