Exemplo n.º 1
0
        /// <summary>
        /// Rotates the camera according mouse movements.
        /// </summary>
        protected void HandleMouseMove(Vector mouseMove)
        {
            double factor = WFUtils.IsShiftDown() ? 0.5 : 0.1;
            double angleX = mouseMove.X * factor;
            double angleY = mouseMove.Y * factor;

            Camera.StopAnyTurn();
            if (Camera.Speed == 0)
            {
                Camera.Rotate(Math3D.UnitZ, 2 * angleX, touchPoint);
                Camera.Rotate(Camera.RightDirection, 2 * angleY, touchPoint);
            }
            else
            {
                if (Camera.MovingDirectionIsLocked)
                {
                    Camera.ChangeHeading(angleX);
                    Camera.ChangePitch(angleY);
                }
                else
                {
                    Camera.ChangeRoll(-angleX);
                    Camera.ChangePitch(angleY);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Timer tick event handler. Moves the cameras to their new position.
        /// </summary>
        void TimerTick(object sender, EventArgs e)
        {
            Camera.MovingDirectionIsLocked = WFUtils.IsCtrlDown() || Console.CapsLock;

            foreach (var camera in Cameras)
            {
                camera.Update();
            }

            UpdateHelperModels();

            if (TimerTicked != null)
            {
                TimerTicked(sender, e);
            }
        }
Exemplo n.º 3
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            Focus();
            base.OnMouseDown(e);
            if (!IsInteractive)
            {
                return;
            }

            if (WFUtils.IsCtrlDown())
            {
                touchPoint = GetTouchPoint(e.GetPosition(this));

                if (adi != null && WFUtils.IsAltDown())
                {
                    adi.TargetPoint = touchPoint;
                    adi.Update(Camera);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a cylinder mesh in the xy plane from z = -1 to z = 1.
        /// </summary>
        static public MeshGeometry3D Create(int nPoints, bool isClosed)
        {
            if (nPoints < 3)
            {
                return(null);
            }

            MeshGeometry3D mesh = new MeshGeometry3D();

            double dPhi = MathUtils.PIx2 / nPoints;
            double phi0 = dPhi * 0.5;

            for (int n = 0; n <= nPoints; n++)
            {
                double phi = n * dPhi + phi0;
                double tx  = phi / MathUtils.PIx2;
                double x   = Math.Cos(phi);
                double y   = Math.Sin(phi);

                mesh.Positions.Add(new Point3D(x, y, -1));
                mesh.Normals.Add(new Vector3D(x, y, 0));
                mesh.TextureCoordinates.Add(new Point(tx, 1));

                mesh.Positions.Add(new Point3D(x, y, 1));
                mesh.Normals.Add(new Vector3D(x, y, 0));
                mesh.TextureCoordinates.Add(new Point(tx, 0));

                if (n > 0)
                {
                    int i = 2 * n;
                    WFUtils.AddTriangle(mesh, i, i - 1, i - 2);
                    WFUtils.AddTriangle(mesh, i, i + 1, i - 1);
                }
            }

            if (isClosed)
            {
                int i1 = mesh.Positions.Count;
                mesh.Positions.Add(new Point3D(0, 0, -1));
                mesh.Normals.Add(new Vector3D(0, 0, -1));
                mesh.TextureCoordinates.Add(new Point(0.5, 0.5));

                mesh.Positions.Add(new Point3D(0, 0, 1));
                mesh.Normals.Add(new Vector3D(0, 0, +1));
                mesh.TextureCoordinates.Add(new Point(0.5, 0.5));

                for (int n = 0; n <= nPoints; n++)
                {
                    double phi = n * dPhi + phi0;
                    double x   = Math.Cos(phi);
                    double y   = Math.Sin(phi);

                    mesh.Positions.Add(new Point3D(x, y, -1));
                    mesh.Normals.Add(new Vector3D(0, 0, -1));

                    Point pt = new Point((1 - x) * 0.5, (1 - y) * 0.5);
                    mesh.TextureCoordinates.Add(pt);

                    mesh.Positions.Add(new Point3D(x, y, 1));
                    mesh.Normals.Add(new Vector3D(0, 0, +1));

                    pt.X = 1 - pt.X;
                    mesh.TextureCoordinates.Add(pt);

                    if (n > 0)
                    {
                        int i = i1 + 2 * n;
                        WFUtils.AddTriangle(mesh, i1, i + 2, i);
                        WFUtils.AddTriangle(mesh, i1 + 1, i + 1, i + 3);
                    }
                }
            }

            //WFUtils.FlipTexture(mesh);
            return(mesh);
        }
Exemplo n.º 5
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            if (!IsInteractive)
            {
                return;
            }

            //--- assume we are handling the key
            e.Handled = true;
            double amount = WFUtils.IsShiftDown() ? 1 : 0.2;

            if (WFUtils.IsCtrlDown())
            {
                amount *= WFUtils.IsAltDown() ? 0.1 : 0.5;
                amount *= Camera.Scale;
                switch (e.Key)
                {
                case Key.Up: Camera.Move(Camera.LookDirection, +amount); return;

                case Key.Down: Camera.Move(Camera.LookDirection, -amount); return;

                case Key.Left: Camera.Move(Camera.LeftDirection, +amount); return;

                case Key.Right: Camera.Move(Camera.LeftDirection, -amount); return;

                case Key.Prior: Camera.Move(Camera.UpDirection, +amount); return;

                case Key.Next: Camera.Move(Camera.UpDirection, -amount); return;

                default: e.Handled = false; return;
                }
            }

            switch (e.Key)
            {
            case Key.Up: Camera.ChangePitch(amount); break;

            case Key.Down: Camera.ChangePitch(-amount); break;

            case Key.Left: if (Camera.Speed == 0)
                {
                    Camera.ChangeYaw(amount);
                }
                else
                {
                    Camera.ChangeRoll(-amount);
                } break;

            case Key.Right: if (Camera.Speed == 0)
                {
                    Camera.ChangeYaw(-amount);
                }
                else
                {
                    Camera.ChangeRoll(+amount);
                } break;

            case Key.Prior: Camera.ChangeRoll(-amount); break;

            case Key.Next: Camera.ChangeRoll(+amount); break;

            case Key.W: Camera.Speed++; return;

            case Key.S: Camera.Speed--; return;

            case Key.X: Camera.Speed = 0; return;

            case Key.F: Camera.FlyParallel(); return;

            case Key.A: Camera.FlyParallel(-1); return;

            case Key.D: Camera.FlyParallel(+1); return;

            case Key.T: Camera.LookBack(); return;

            case Key.H: ToggleHelperModels(); return;

            case Key.Space: Camera.LookAtOrigin(); return;

            case Key.D1: ActivateCamera(0); return;

            case Key.D2: ActivateCamera(1); return;

            case Key.D3: ActivateCamera(2); return;

            default: e.Handled = false; return;
            }

            Camera.StopAnyTurn();
        }