Beispiel #1
0
		/** Searches for physics shapes that intersects the ray. */
        public void RayCast(Func<CCPhysicsWorld, CCPhysicsRayCastInfo, RayCastContext, bool>  func, CCPoint point1, CCPoint point2, RayCastContext context)
		{
			cp.AssertWarn(func != null, "func shouldn't be nullptr");

			if (func != null)
			{
                CCRayCastCallbackInfo info = new CCRayCastCallbackInfo(this, func, point1, point2, context.data);
				//Action<cpShape, cpVect, cpVect, float, object> func
				CCPhysicsWorldCallback.Continues = true;

				this.Space.SegmentQuery(
                    PhysicsHelper.CCPointToCpVect(point1),
                    PhysicsHelper.CCPointToCpVect(point2), 1f,
									new cpShapeFilter(cp.NO_GROUP, cp.ALL_LAYERS, cp.ALL_LAYERS),
                    (shape, v1, v2, f, o) => CCPhysicsWorldCallback.RayCastCallbackFunc(shape, f, PhysicsHelper.cpVectToCCPoint(v1), ref info), context.data
									);
			}
		}
Beispiel #2
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;


        }
Beispiel #3
0
        /** Searches for physics shapes that intersects the ray. */
        public void RayCast(Func <CCPhysicsWorld, CCPhysicsRayCastInfo, RayCastContext, bool> func, CCPoint point1, CCPoint point2, RayCastContext context)
        {
            cp.AssertWarn(func != null, "func shouldn't be nullptr");

            if (func != null)
            {
                CCRayCastCallbackInfo info = new CCRayCastCallbackInfo(this, func, point1, point2, context.data);
                //Action<cpShape, cpVect, cpVect, float, object> func
                CCPhysicsWorldCallback.Continues = true;

                this.Space.SegmentQuery(
                    PhysicsHelper.CCPointToCpVect(point1),
                    PhysicsHelper.CCPointToCpVect(point2), 1f,
                    new cpShapeFilter(cp.NO_GROUP, cp.ALL_LAYERS, cp.ALL_LAYERS),
                    (shape, v1, v2, f, o) => CCPhysicsWorldCallback.RayCastCallbackFunc(shape, f, PhysicsHelper.cpVectToCCPoint(v1), ref info), context.data
                    );
            }
        }