public void SetViewCenter(HorizontalCoordinate viewCenterCoord)
        {
            ViewCenterVector = viewCenterCoord.ToVector();
            HorizontalCoordinate vertAxisCoord = new HorizontalCoordinate(viewCenterCoord.Azimuth + Angle.Right, Angle.Zero);

            vertAxis = vertAxisCoord.ToVector();
            horzAxis = Vector3.Cross(this.ViewCenterVector, vertAxis);
        }
Ejemplo n.º 2
0
        public static HorizontalCoordinate From(Matrix matrix)
        {
            // Invert the matrix
            matrix = Matrix.Invert(matrix);

            // Transform (0, 0, -1) -- the vector extending from the lens
            Vector3 zAxisTransformed = Vector3.Transform(-Vector3.UnitZ, matrix);

            // Get the horizontal coordinates
            HorizontalCoordinate horzCoord = From(zAxisTransformed);

            // Find the theoretical HorizontalCoordinate for the transformed +Y vector if the phone is upright
            Angle yUprightAltitude = Angle.Zero;
            Angle yUprightAzimuth  = Angle.Zero;

            if (horzCoord.Altitude.Degrees > 0)
            {
                yUprightAltitude = Angle.Right - horzCoord.Altitude;
                yUprightAzimuth  = Angle.Straight + horzCoord.Azimuth;
            }
            else
            {
                yUprightAltitude = Angle.Right + horzCoord.Altitude;
                yUprightAzimuth  = horzCoord.Azimuth;
            }
            Vector3 yUprightVector = new HorizontalCoordinate(yUprightAzimuth, yUprightAltitude).ToVector();

            // Find the real transformed +Y vector
            Vector3 yAxisTransformed = Vector3.Transform(Vector3.UnitY, matrix);

            // Get the angle between the upright +Y vector and the real transformed +Y vector
            double  dotProduct   = Vector3.Dot(yUprightVector, yAxisTransformed);
            Vector3 crossProduct = Vector3.Cross(yUprightVector, yAxisTransformed);

            crossProduct.Normalize();

            // Sometimes dotProduct is slightly greater than 1, which
            // raises an exception in the angleBetween calculation, so....
            dotProduct = Math.Min(dotProduct, 1);

            Angle angleBetween = Angle.FromRadians(Vector3.Dot(zAxisTransformed, crossProduct) * Math.Acos(dotProduct));

            horzCoord.Tilt = angleBetween;

            return(horzCoord);
        }
        public void GetAngleOffsets(HorizontalCoordinate objectCoord, ref Angle horzAngle, ref Angle vertAngle)
        {
            Vector3 objectVector    = objectCoord.ToVector();
            Vector3 horzObjectCross = Vector3.Cross(objectVector, -horzAxis);
            Vector3 vertObjectCross = Vector3.Cross(objectVector, vertAxis);

            horzObjectCross.Normalize();
            vertObjectCross.Normalize();

            double x = Vector3.Dot(horzObjectCross, vertAxis);
            double y = Vector3.Dot(horzObjectCross, this.ViewCenterVector);

            horzAngle = -Angle.ArcTangent(y, x);

            x = Vector3.Dot(vertObjectCross, horzAxis);
            y = Vector3.Dot(vertObjectCross, this.ViewCenterVector);

            vertAngle = -Angle.ArcTangent(y, x);
        }
Ejemplo n.º 4
0
        // Called external to update HorizontalCoordinate
        public void Update(Time time, GeographicCoordinate location)
        {
            bool needsUpdate = false;

            if (!this.Time.Equals(time))
            {
                this.Time   = time;
                needsUpdate = true;
                OnTimeChanged();
            }

            if (!this.Location.Equals(location))
            {
                this.Location = location;
                needsUpdate   = true;
            }

            if (needsUpdate)
            {
                this.HorizontalCoordinate = HorizontalCoordinate.From(this.EquatorialCoordinate, this.Location, this.Time);
            }
        }