コード例 #1
0
        /// <summary>
        /// Make this camera look at a specific point in the world.
        /// </summary>
        /// <param name="position">The point to look at.</param>
        public void LookAt(Vector3 position)
        {
            //store the line between the camera and the other IPoint3D, but only on the X/Z plane, then normalize it to get a unit vector.
            OpenTK.Vector2 pitchVec = OpenTK.Vector2.Normalize(new OpenTK.Vector2(position.X - Position.X, position.Z - Position.Z));

            //convert vector to angle and roatate the right axis to that angle
            RotatePitchTo((float)(Math.Atan2(pitchVec.Y, pitchVec.X) * (180f / MathHelper.Pi) - 90));

            //update lookAxis, the normalized vector of the line between this camera and the IPoint3D.
            lookAxis = Vector3.Normalize(Vector3.Subtract(position, Position));

            //update the heading variable and upAxis
            RotateHeadingTo((float)Math.Asin(-lookAxis.Y) * (180f / MathHelper.Pi));

            //update the view matrix so our changes are reflected in the world
            RebuildView();
        }
コード例 #2
0
ファイル: Camera.cs プロジェクト: herpit/MineEdit
 void control_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
 {
     long ms = movetime.ElapsedMilliseconds;
     movetime.Reset();
     movetime.Start();
     if(MouseEnabled && _lastMouseEnabled && control.Focused)
     {
         float yaw = Rotation.X;
         float pitch = Rotation.Y;
         yaw += (e.X - MousePosition.X) * MouseSpeed * (float)ms;
         pitch += (e.Y - MousePosition.Y) * MouseSpeed * (float)ms;
         yaw = ((yaw % 360) + 360) % 360;
         pitch = Math.Max(-90, Math.Min(90, pitch));
         Cursor.Position = control.PointToScreen(MousePosition);
         Rotation = new Vector2(yaw, pitch);
         //Console.WriteLine("Camera's rotation is now {0}", Rotation);
     } else if (MouseEnabled && !_lastMouseEnabled && control.Focused) {
         Cursor.Position = control.PointToScreen(MousePosition);
         Cursor.Hide();
         _lastMouseEnabled = true;
     } else {
         Cursor.Show();
         _lastMouseEnabled = false;
     }
 }