示例#1
0
        public CCOrbitCameraState(CCOrbitCamera action, CCNode target)
            : base(action, target)
        {
            AngleX      = action.AngleX;
            AngleZ      = action.AngleZ;
            DeltaAngleX = action.DeltaAngleX;
            DeltaAngleZ = action.DeltaAngleZ;
            DeltaRadius = action.DeltaRadius;
            Radius      = action.Radius;

            // We are assuming the local camera will be centered directly at the target
            // => Add radius to the z position of local camera
            CCPoint3 fauxLocalCameraCenter = target.FauxLocalCameraCenter;

            fauxLocalCameraCenter.Z     += Radius;
            target.FauxLocalCameraCenter = fauxLocalCameraCenter;

            //CameraCenter = fauxLocalCameraCenter;

            RadDeltaZ = CCMacros.CCDegreesToRadians(DeltaAngleZ);
            RadDeltaX = CCMacros.CCDegreesToRadians(DeltaAngleX);

            // Only calculate the SpericalRadius when needed.
            if (float.IsNaN(Radius) || float.IsNaN(AngleZ) || float.IsNaN(AngleX))
            {
                float r, zenith, azimuth;
                SphericalRadius(out r, out zenith, out azimuth);

                if (float.IsNaN(Radius))
                {
                    Radius = r;
                }

                if (float.IsNaN(AngleZ))
                {
                    AngleZ = CCMacros.CCRadiansToDegrees(zenith);
                }

                if (float.IsNaN(AngleX))
                {
                    AngleX = CCMacros.CCRadiansToDegrees(azimuth);
                }
            }

            RadZ = CCMacros.CCDegreesToRadians(AngleZ);
            RadX = CCMacros.CCDegreesToRadians(AngleX);
        }
        protected void UpdateSliderPosition(CCPoint location)
        {
            // Clamp the position of the icon within the circle
            CCRect BackgroundBox = Background.BoundingBox;

            float centerX = StartPos.X + BackgroundBox.Size.Width * 0.5f;
            float centerY = StartPos.Y + BackgroundBox.Size.Height * 0.5f;

            float dx = location.X - centerX;
            float dy = location.Y - centerY;

            // Update angle by using the direction of the location
            var   angle    = (float)Math.Atan2(dy, dx);
            float angleDeg = CCMacros.CCRadiansToDegrees(angle) + 180.0f;

            // use the position / Slider width to determin the percentage the dragger is at
            Hue = angleDeg;

            OnValueChanged();
        }