protected override void AddedToScene()
        {
            base.AddedToScene();

            // Use the bounds to layout the positioning of our drawable assets
            CCRect bounds = VisibleBoundsWorldspace;

            // point to rotate around
            origin = bounds.Center;

            // Draw a magenta circle at our origin
            var originNode = new CCDrawNode();
            originNode.DrawDot(origin, 10, new CCColor4F(CCColor4B.Magenta));
            AddChild(originNode);

            PositionMonkey();

            // Register for touch events
            var touchListener = new CCEventListenerTouchAllAtOnce();
            touchListener.OnTouchesEnded = OnTouchesEnded;
            AddEventListener(touchListener, this);
        }
        public override void OnEnter()
        {
            base.OnEnter(); 
            CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;
            CCDrawNode draw = new CCDrawNode();
            AddChild(draw, 10);

			var s = windowSize;

            // Draw 10 circles
            for (int i = 0; i < 10; i++)
            {
				draw.DrawDot(s.Center, 10 * (10 - i),
                    new CCColor4F(CCRandom.Float_0_1(), CCRandom.Float_0_1(), CCRandom.Float_0_1(), 1));
            }

            // Draw polygons
            CCPoint[] points = new CCPoint[]
            {
                new CCPoint(windowSize.Height / 4, 0),
                new CCPoint(windowSize.Width, windowSize.Height / 5),
                new CCPoint(windowSize.Width / 3 * 2, windowSize.Height)
            };
            draw.DrawPolygon(points, points.Length, new CCColor4F(1.0f, 0, 0, 0.5f), 4, new CCColor4F(0, 0, 1, 1));
			
            // star poly (triggers buggs)
			{
	            const float o = 80;
	            const float w = 20;
	            const float h = 50;
	            CCPoint[] star = new CCPoint[]
	            {
	                new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o),                           // lower spike
	                new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2),           // right spike
	            };

	            draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1));
			}

            // star poly (doesn't trigger bug... order is important un tesselation is supported.
            {
                const float o = 180;
                const float w = 20;
                const float h = 50;
                var star = new CCPoint[]
                {
                    new CCPoint(o, o), new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o),        // lower spike
                    new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2),           // right spike
                    new CCPoint(o + w, o + w * 2 + h), new CCPoint(o, o + w * 2),                   // top spike
                    new CCPoint(o - h, o + w), // left spike
                };

                draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1));
            }


            // Draw segment
            draw.DrawSegment(new CCPoint(20, windowSize.Height), new CCPoint(20, windowSize.Height / 2), 10, new CCColor4F(0, 1, 0, 1));

            draw.DrawSegment(new CCPoint(10, windowSize.Height / 2), new CCPoint(windowSize.Width / 2, windowSize.Height / 2), 40,
                new CCColor4F(1, 0, 1, 0.5f));
        }
Exemple #3
0
        public override void Update(float dt)
        {
            base.Update(dt);

            float L = 150.0f;
            CCPoint point1 = Window.WindowSizeInPixels.Center;
            CCPoint d = new CCPoint(L * (float)Math.Cos(_angle), L * (float)Math.Sin(_angle));
            CCPoint point2 = point1 + d;

            RemoveChild(_node);
            _node = new CCDrawNode();
            switch (_mode)
            {
                case 0:
                    {
                        CCPoint point3 = point2;
                        //var func = Func< (PhysicsDemoRayCast::anyRay, this);

                        var ctx = new RayCastContext(point3);

                        Scene.PhysicsWorld.RayCast((world, info, data) =>
                        {
                            point3 = info.Contact;
                            return false;

                        }, point1, point2, ctx);

                        _node.DrawSegment(point1, point3, 1, STATIC_COLOR);

                        if (point2 != point3)
                        {
                            _node.DrawDot(point3, 2, new CCColor4F(1.0f, 1.0f, 1.0f, 1.0f));
                        }

                        AddChild(_node);

                        break;
                    }
                case 1:
                    {
                        CCPoint point3 = point2;
                        float friction = 1.0f;

                        Func<CCPhysicsWorld, CCPhysicsRayCastInfo, RayCastContext, bool> func = new Func<CCPhysicsWorld, CCPhysicsRayCastInfo, RayCastContext, bool>(
                           (world, info, ctx) =>
                           {
                               if (friction > info.Fraction)
                               {
                                   point3 = info.Contact;
                                   friction = info.Fraction;
                               }

                               return true;
                           });

                        _node.DrawSegment(point1, point3, 1, STATIC_COLOR);

                        if (point2 != point3)
                        {
                            _node.DrawDot(point3, 2, new CCColor4F(1.0f, 1.0f, 1.0f, 1.0f));
                        }
                        AddChild(_node);

                        break;
                    }
                case 2:
                    {
                        int MAX_MULTI_RAYCAST_NUM = 5;
                        CCPoint[] points = new CCPoint[MAX_MULTI_RAYCAST_NUM];
                        int num = 0;

                        Func<CCPhysicsWorld, CCPhysicsRayCastInfo, RayCastContext, bool> func = new Func<CCPhysicsWorld, CCPhysicsRayCastInfo, RayCastContext, bool>(
                             (world, info, data) =>
                             {
                                 if (num < MAX_MULTI_RAYCAST_NUM)
                                 {
                                     points[num++] = info.Contact;
                                 }

                                 return true;
                             });

                        // Scene.PhysicsWorld.RayCast(func, point1, point2, null);

                        _node.DrawSegment(point1, point2, 1, STATIC_COLOR);

                        for (int i = 0; i < num; ++i)
                        {
                            _node.DrawDot(points[i], 2, new CCColor4F(1.0f, 1.0f, 1.0f, 1.0f));
                        }

                        AddChild(_node);

                        break;
                    }

                default:
                    break;
            }

            _angle += 0.25f * (float)cp.M_PI / 180.0f;


        }
        public override void OnEnter()
        {
            base.OnEnter(); 
            CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;
            CCDrawNode draw = new CCDrawNode();
            AddChild(draw, 10);

			var s = windowSize;

            // Draw 10 circles
            for (int i = 0; i < 10; i++)
            {
				draw.DrawDot(s.Center, 10 * (10 - i),
                    new CCColor4F(CCRandom.Float_0_1(), CCRandom.Float_0_1(), CCRandom.Float_0_1(), 1));
            }

            // Draw polygons
            CCPoint[] points = new CCPoint[]
            {
                new CCPoint(windowSize.Height / 4, 0),
                new CCPoint(windowSize.Width, windowSize.Height / 5),
                new CCPoint(windowSize.Width / 3 * 2, windowSize.Height)
            };
            draw.DrawPolygon(points, points.Length, new CCColor4F(1.0f, 0, 0, 0.5f), 4, new CCColor4F(0, 0, 1, 1));
			
            // star poly (triggers buggs)
			{
	            const float o = 80;
	            const float w = 20;
	            const float h = 50;
	            CCPoint[] star = new CCPoint[]
	            {
	                new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o),                           // lower spike
	                new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2),           // right spike
	            };

	            draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1));
			}

            // star poly (doesn't trigger bug... order is important un tesselation is supported.
            {
                const float o = 180;
                const float w = 20;
                const float h = 50;
                var star = new CCPoint[]
                {
                    new CCPoint(o, o), new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o),        // lower spike
                    new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2),           // right spike
                    new CCPoint(o + w, o + w * 2 + h), new CCPoint(o, o + w * 2),                   // top spike
                    new CCPoint(o - h, o + w), // left spike
                };

                draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1));
            }


            // Draw segment
            draw.DrawSegment(new CCPoint(20, windowSize.Height), new CCPoint(20, windowSize.Height / 2), 10, new CCColor4F(0, 1, 0, 1));

            draw.DrawSegment(new CCPoint(10, windowSize.Height / 2), new CCPoint(windowSize.Width / 2, windowSize.Height / 2), 40,
                new CCColor4F(1, 0, 1, 0.5f));

            CCSize size = Layer.VisibleBoundsWorldspace.Size;

            var visibleRect = VisibleBoundsWorldspace;

            // draw quad bezier path
            draw.DrawQuadBezier(new CCPoint(0, size.Height),
                visibleRect.Center,
                (CCPoint)visibleRect.Size,
                50, 3,
                new CCColor4B(255, 0, 255, 255));

            // draw cubic bezier path
            draw.DrawCubicBezier(visibleRect.Center,
                new CCPoint(size.Width / 2 + 30, size.Height / 2 + 50),
                new CCPoint(size.Width / 2 + 60, size.Height / 2 - 50),
                new CCPoint(size.Width, size.Height / 2), 100, 2, CCColor4B.Green);

            // draw an ellipse within rectangular region
            draw.DrawEllipse(new CCRect(100, 300, 100, 200), 2, CCColor4B.AliceBlue);
        }