Esempio n. 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.
            Vector2 pitchVec = Vector2.Normalize(new 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();
        }