Exemple #1
0
        public override void OnEnter()
        {
            base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;

            CCRect visibleBounds = Layer.VisibleBoundsWorldspace;

            CCCamera contentCamera = contentLayer.Camera;

            contentCamera.Projection             = CCCameraProjection.Projection3D;
            contentCamera.PerspectiveAspectRatio = 3.0f;

            CCPoint3 cameraCenter = contentCamera.CenterInWorldspace;
            CCPoint3 cameraTarget = contentCamera.TargetInWorldspace;

            float targeCenterLength = (cameraTarget - cameraCenter).Length;


            contentCamera.NearAndFarPerspectiveClipping = new CCPoint(0.15f, 100.0f);

            contentCamera.PerspectiveFieldOfView = (float)Math.Atan(visibleBounds.Size.Height / (2.0f * targeCenterLength));

            Schedule(checkAnim);

            BaseNode.Position = windowSize.Center;
            var size = BaseNode.ContentSize;

            BaseNode[EffectTestScene.kTagKathia].Position = new CCPoint(size.Width / 3, size.Center.Y);
            BaseNode[EffectTestScene.kTagTamara].Position = new CCPoint(2 * size.Width / 3, size.Center.Y);

            BaseNode.RunAction(CurrentAction);
        }
Exemple #2
0
        public override void OnEnter()
        {
            base.OnEnter();

            CCRect visibleBounds = VisibleBoundsWorldspace;

            CCCamera contentCamera = contentLayer.Camera;

            contentCamera.Projection             = CCCameraProjection.Projection3D;
            contentCamera.PerspectiveAspectRatio = 1.0f;

            CCPoint3 cameraCenter = contentCamera.CenterInWorldspace;
            CCPoint3 cameraTarget = contentCamera.TargetInWorldspace;

            float targeCenterLength = (cameraTarget - cameraCenter).Length;


            contentCamera.NearAndFarPerspectiveClipping = new CCPoint(0.15f, 100.0f);

            contentCamera.PerspectiveFieldOfView = (float)Math.Atan(visibleBounds.Size.Height / (2.0f * targeCenterLength));

            var lens      = new CCLens3D(10, new CCGridSize(64, 48), new CCPoint(100, 180), 80);
            var move      = new CCJumpBy(5, new CCPoint(600, 0), 100, 5);
            var move_back = move.Reverse();

            CCLens3DState lensState = bgNode.RunAction(lens) as CCLens3DState;

            var target = new Lens3DTarget(lensState);

            // Please make sure the target has been added to its parent.
            AddChild(target);

            target.AddActions(false, move, move_back);
        }
Exemple #3
0
 public void MoveToPosition(CCPoint value)
 {
     Position           = value;
     TargetInWorldspace = new CCPoint3(value, -1);
     CenterInWorldspace = new CCPoint3(value, 0);
     PositionUpdated?.Invoke(this, Position);
 }
Exemple #4
0
        public CCActionCameraState (CCActionCamera action, CCNode target)
            : base (action, target)
        {
            target.FauxLocalCameraCenter = new CCPoint3(target.AnchorPointInPoints, 0.0f);
            target.FauxLocalCameraTarget = new CCPoint3(target.AnchorPointInPoints, 0.0f);

            CameraCenter = target.FauxLocalCameraCenter;
            CameraTarget = target.FauxLocalCameraTarget;
            CameraUpDirection = target.FauxLocalCameraUpDirection;
        }
Exemple #5
0
        public CCActionCameraState(CCActionCamera action, CCNode target)
            : base(action, target)
        {
            target.FauxLocalCameraCenter = new CCPoint3(target.AnchorPointInPoints, 0.0f);
            target.FauxLocalCameraTarget = new CCPoint3(target.AnchorPointInPoints, 0.0f);

            CameraCenter      = target.FauxLocalCameraCenter;
            CameraTarget      = target.FauxLocalCameraTarget;
            CameraUpDirection = target.FauxLocalCameraUpDirection;
        }
Exemple #6
0
        public override void OnEnter()
        {
            base.OnEnter();

            CCRect visibleBounds = VisibleBoundsWorldspace;

            // To reuse a grid the grid size and the grid type must be the same.
            // in this case:
            //     Lens3D is Grid3D and it's size is (15,10)
            //     Waves3D is Grid3D and it's size is (15,10)


            CCCamera contentCamera = contentLayer.Camera;

            contentCamera.Projection             = CCCameraProjection.Projection3D;
            contentCamera.PerspectiveAspectRatio = 1.0f;

            CCPoint3 cameraCenter = contentCamera.CenterInWorldspace;
            CCPoint3 cameraTarget = contentCamera.TargetInWorldspace;

            float targeCenterLength = (cameraTarget - cameraCenter).Length;


            contentCamera.NearAndFarPerspectiveClipping = new CCPoint(0.1f, 100.0f);

            contentCamera.PerspectiveFieldOfView = (float)Math.PI / 3.0f; //(float)Math.Atan(visibleBounds.Size.Height / (2.0f * targeCenterLength));

            var lens  = new CCLens3D(0.0f, new CCGridSize(15, 10), bgNode.ContentSize.Center, 90);
            var waves = new CCWaves3D(10, new CCGridSize(15, 10), 18, 15);


            var reuse = new CCReuseGrid(1);
            var delay = new CCDelayTime(8);

            bgNode.AnchorPoint = CCPoint.AnchorMiddle;
            var orbit      = new CCOrbitCamera(5, 30.0f, 2, 20, 180, 0, -90);
            var orbit_back = orbit.Reverse();

            bgNode.RepeatForever(orbit, orbit_back);
            bgNode.RunActions(lens, delay, reuse, waves);
        }
Exemple #7
0
 /// <summary>
 /// Sets the camera.
 /// </summary>
 /// <param name="newTargetPoint">New target point.</param>
 /// <param name="newCameraPoint">New camera point.</param>
 private void SetCamera(CCPoint3 newTargetPoint, CCPoint3 newCameraPoint)
 {
     this.Camera.TargetInWorldspace = newTargetPoint;
     this.Camera.CenterInWorldspace = newCameraPoint;
 }
Exemple #8
0
        CCPoint3 CalculatePerspectiveCameraCenter(CCSize targetVisibleBounds, CCPoint3 target)
        {
            CCPoint3 newCenter = target;

            /*
            * Given our field of view and near and far clipping, need to find z position of camera center
            * The top coord of near bounding frustrum is y_p = - (near * y_eye) / z_eye = near * Tan(fov / 2)
            * Here, we want y_eye = 1/2 * bounds height
            * Solve for above for target z_eye
            * Finally, the center we're setting is in world coords (i.e. z_center = z_target - z_eye.
            * Note z_eye will generally have a negative value, so - z_eye > 0.
            */

            float zEye = - (targetVisibleBounds.Height / 2.0f) * (1 / (float)Math.Tan(fieldOfView / 2.0f));

            newCenter.Z -= zEye;

            return newCenter;
        }
Exemple #9
0
        public void UpdatePerspectiveCameraTargetBounds(CCSize targetVisibleDimensionsWorldspaceIn, CCPoint3 targetWorldspaceIn)
        {
            cameraProjection = CCCameraProjection.Projection3D;

            aspectRatio = targetVisibleDimensionsWorldspaceIn.Width / targetVisibleDimensionsWorldspaceIn.Height;

            targetInWorldspace = targetWorldspaceIn;

            centerInWorldspace 
                = CalculatePerspectiveCameraCenter(targetVisibleDimensionsWorldspaceIn, targetWorldspaceIn);

            UpdateCameraMatrices();
        }
Exemple #10
0
        public CCCamera(float perspectiveFieldOfViewIn, float perspectiveAspectRatioIn, CCPoint3 cameraCenterPositionWorldspaceIn, CCPoint3 targetInWorldspaceIn)
            : this(targetInWorldspaceIn)
        {
            cameraProjection = CCCameraProjection.Projection3D;

            centerInWorldspace = cameraCenterPositionWorldspaceIn;

            fieldOfView = perspectiveFieldOfViewIn;
            aspectRatio = perspectiveAspectRatioIn;

            UpdateCameraMatrices();
        }
Exemple #11
0
        public CCCamera(CCCameraProjection projection, CCSize targetVisibleDimensionsWorldspace, CCPoint3 targetInWorldspaceIn)
            : this(targetInWorldspaceIn)
        {
            cameraProjection = projection;

            if (cameraProjection == CCCameraProjection.Projection2D)
            {
                centerInWorldspace = new CCPoint3(targetInWorldspaceIn.X, 
                    targetInWorldspaceIn.Y, 
                    targetInWorldspaceIn.Z + defaultNearAndFarOrthoClipping.Near);

                orthographicViewSizeWorldspace = targetVisibleDimensionsWorldspace;
            }
            else
            {
                aspectRatio = targetVisibleDimensionsWorldspace.Width / targetVisibleDimensionsWorldspace.Height;

                centerInWorldspace 
                    = CalculatePerspectiveCameraCenter(targetVisibleDimensionsWorldspace, targetInWorldspace);


                /* Make sure the far clipping distance is longer than distance frame camera to target
                *  Give ourselves a little extra distance buffer so that there's no clipping when rotating etc
                * 
                *  If users want to customise the near and far clipping bounds, they can do that and then call
                *  UpdatePerspectiveCameraTargetBounds
                */
                nearAndFarPerspectiveClipping.Far 
                    = Math.Max(Math.Abs((centerInWorldspace.Z - targetInWorldspaceIn.Z) * 3.0f), defaultNearAndFarPerspClipping.Far);
            }

            UpdateCameraMatrices();
        }
Exemple #12
0
        // Defaults for both 2d and 3d projections
        CCCamera(CCPoint3 targetInWorldspaceIn)
        {
            targetInWorldspace = targetInWorldspaceIn;

            nearAndFarOrthographicZClipping = defaultNearAndFarOrthoClipping;
            nearAndFarPerspectiveClipping = defaultNearAndFarPerspClipping;
            fieldOfView = defaultFieldOfView;
            aspectRatio = defaultAspectRatio;
            upDirection = new CCPoint3 (Vector3.Up.X, Vector3.Up.Y, Vector3.Up.Z);
        }
Exemple #13
0
 /// <summary>
 /// Checks the view for position updats.
 /// </summary>
 /// <param name="frameTimesInSecond">Frame times in second.</param>
 private void CheckView(float frameTimesInSecond)
 {
     var oldCameraPoint = this.Camera.CenterInWorldspace;
     var oldTargetPoint = this.Camera.TargetInWorldspace;
     if (m_touchHandler.Gesture != TileTouchHandler.TouchGesture.Move)
     {           
         LoadRegionViews(m_currentWorldPoint);
     }              
     var newTargetPoint = new CCPoint3(m_currentWorldPoint.X, m_currentWorldPoint.Y, oldTargetPoint.Z);
     var newCameraPoint = new CCPoint3(m_currentWorldPoint.X, m_currentWorldPoint.Y, oldCameraPoint.Z);
     SetCamera(newTargetPoint, newCameraPoint); 
 }
Exemple #14
0
        public CCCamera(CCSize orthographicViewSizeWorldspaceIn, CCPoint3 cameraCenterPositionWorldspaceIn, CCPoint3 targetInWorldspaceIn)
            : this(cameraCenterPositionWorldspaceIn, targetInWorldspaceIn)
        {
            cameraProjection = CCCameraProjection.Projection2D;

            orthographicViewSizeWorldspace = orthographicViewSizeWorldspaceIn;

            UpdateCameraMatrices();
        }
 public static CCPoint3 Transform(CCPoint3 point, ref CCAffineTransform t)
 {
     Vector3 vec = point.XnaVector;
     Vector3.Transform(ref vec, ref t.xnaMatrix, out vec);
     return new CCPoint3(vec);
 }
 public void Transform(ref CCPoint3 point)
 {
     Transform(ref point.X, ref point.Y, ref point.Z);
 }
 public CCPoint3 Transform(CCPoint3 point)
 {
     Transform(ref point.X, ref point.Y, ref point.Z);
     return point;
 }