예제 #1
0
        public override bool FrameRenderingQueued(FrameEventArgs evt)
        {
            if (this.mode != Mode.Normal)
            {
                // fire ray
                Ray ray;
                ray = TrayManager.GetCursorRay(Camera);

                var rayResult = this.terrainGroup.RayIntersects(ray);
                if (rayResult.Hit)
                {
                    this.editMarker.IsVisible = true;
                    this.editNode.Position    = rayResult.Position;

                    // figure out which terrains this affects
                    List <Axiom.Components.Terrain.Terrain> terrainList;
                    var brushSizeWorldSpace = TerrainWorldSize * this.brushSizeTerrainSpace;
                    var sphere = new Sphere(rayResult.Position, brushSizeWorldSpace);
                    this.terrainGroup.SphereIntersects(sphere, out terrainList);

                    foreach (var ti in terrainList)
                    {
                        DoTerrainModify(ti, rayResult.Position, evt.TimeSinceLastFrame);
                    }
                }
                else
                {
                    this.editMarker.IsVisible = false;
                }
            }

            if (!this.fly)
            {
                // clamp to terrain
                var camPos = Camera.Position;
                var ray    = new Ray(new Vector3(camPos.x, this.terrainPos.y + 10000, camPos.z), Vector3.NegativeUnitY);

                TerrainGroup.RayResult rayResult = this.terrainGroup.RayIntersects(ray);
                Real distanceAboveTerrain        = 50;
                Real fallSpeed = 300;
                Real newy      = camPos.y;
                if (rayResult.Hit)
                {
                    if (camPos.y > rayResult.Position.y + distanceAboveTerrain)
                    {
                        this.fallVelocity += evt.TimeSinceLastFrame * 20;
                        this.fallVelocity  = Utility.Min(this.fallVelocity, fallSpeed);
                        newy = camPos.y - this.fallVelocity * evt.TimeSinceLastFrame;
                    }
                    newy            = Utility.Max(rayResult.Position.y + distanceAboveTerrain, newy);
                    Camera.Position = new Vector3(camPos.x, newy, camPos.z);
                }
            }

            if (this.heightUpdateCountDown > 0)
            {
                this.heightUpdateCountDown -= evt.TimeSinceLastFrame;
                if (this.heightUpdateCountDown <= 0)
                {
                    this.terrainGroup.Update();
                    this.heightUpdateCountDown = 0;
                }
            }

            if (this.terrainGroup.IsDerivedDataUpdateInProgress)
            {
                TrayManager.MoveWidgetToTray(this.infoLabel, TrayLocation.Top, 0);
                this.infoLabel.Show();
                if (this.terrainsImported)
                {
                    this.infoLabel.Caption = "Building terrain, please wait...";
                }
                else
                {
                    this.infoLabel.Caption = "Updating textures, patience...";
                }
            }
            else
            {
                TrayManager.RemoveWidgetFromTray(this.infoLabel);
                this.infoLabel.Hide();
                if (this.terrainsImported)
                {
                    SaveTerrains(true);
                    this.terrainsImported = false;
                }
            }

            return(base.FrameRenderingQueued(evt));
        }