예제 #1
0
        public void DebugDraw()
        {
            if (_debugDraw == null)
            {
                _debugDraw = new PhysicsDebugDraw(this);

                _debugDraw.Flags = PhysicsDrawFlags.All;
            }

            //var space = this._info.getSpace();
            //_debugDraw.Begin();
            //space.EachShape(shape =>
            //{
            //	_debugDraw.DrawShape(shape);
            //});
            //_debugDraw.End();
            //return;

            if (_debugDraw != null && _bodies.Count > 0)
            {
                if (_debugDraw.Begin())
                {
                    if ((_debugDrawMask & DEBUGDRAW_SHAPE) > 0)
                    {
                        foreach (CCPhysicsBody body in _bodies)
                        {
                            //hysicsBody body = dynamic_cast<PhysicsBody*>(obj);

                            if (!body.IsEnabled())
                            {
                                continue;
                            }

                            foreach (CCPhysicsShape shape in body.GetShapes())
                            {
                                _debugDraw.DrawShape(shape);
                            }
                        }
                    }

                    if ((_debugDrawMask & DEBUGDRAW_JOINT) > 0)
                    {
                        foreach (CCPhysicsJoint joint in _joints)
                        {
                            _debugDraw.DrawJoint(joint);
                        }
                    }

                    _debugDraw.End();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Constructs a new PhysicsSimulation. Must be created on the physics thread.
        /// </summary>
        internal PhysicsSimulation()
        {
            _ghostPairCallback     = new GhostPairCallback();
            Broadphase             = new DbvtBroadphase();
            CollisionConfiguration = new DefaultCollisionConfiguration();

            Dispatcher = new CollisionDispatcher(CollisionConfiguration);
            Solver     = new SequentialImpulseConstraintSolver(); // Projected Gauss Seidel
            World      = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConfiguration)
            {
                DebugDrawer = _debugDraw = new PhysicsDebugDraw()
            };
            World.PairCache.SetInternalGhostPairCallback(_ghostPairCallback);

            _stopwatch.Start();
        }
예제 #3
0
        public void DebugDraw()
        {
            if (_debugDraw == null)
            {
                _debugDraw = new PhysicsDebugDraw(this);

                _debugDraw.Flags = PhysicsDrawFlags.All;
            }

            if (_debugDraw != null && Bodies.Count > 0)
            {
                if (_debugDraw.Begin())
                {
                    if ((debugDrawMask & DEBUGDRAW_SHAPE) > 0)
                    {
                        foreach (CCPhysicsBody body in Bodies)
                        {
                            //hysicsBody body = dynamic_cast<PhysicsBody*>(obj);

                            if (!body.IsEnabled())
                            {
                                continue;
                            }

                            foreach (CCPhysicsShape shape in body.GetShapes())
                            {
                                _debugDraw.DrawShape(shape);
                            }
                        }
                    }

                    if ((debugDrawMask & DEBUGDRAW_JOINT) > 0)
                    {
                        foreach (CCPhysicsJoint joint in Joints)
                        {
                            _debugDraw.DrawJoint(joint);
                        }
                    }

                    _debugDraw.End();
                }
            }
        }
예제 #4
0
        protected override void AddedToScene()
        {
            base.AddedToScene();

            //Our information layer it's on parent layer because our information text are statics
            background          = new CCSprite("Background.png");
            background.Position = windowSize.Center;
            background.Scale    = windowSize.Height / background.Texture.ContentSizeInPixels.Height;
            BackgroundLayer.AddChild(background, -3);
            this.Position = windowSize.Center;

            //Creation menu debug options
            var lbl1 = new CCMenuItemLabelTTF(GetDefaultFontTtf("Shapes"), (o) => { debug_shapes = !debug_shapes; RefreshDebug(); });

            lbl1.AnchorPoint = new CCPoint(0, .5f);
            var lbl2 = new CCMenuItemLabelTTF(GetDefaultFontTtf("Joins"), (o) => { debug_joints = !debug_joints; RefreshDebug(); });

            lbl2.AnchorPoint = new CCPoint(0, .5f);
            var lbl3 = new CCMenuItemLabelTTF(GetDefaultFontTtf("Contact"), (o) => { debug_contacts = !debug_contacts; RefreshDebug(); });

            lbl3.AnchorPoint = new CCPoint(0, .5f);
            var lbl4 = new CCMenuItemLabelTTF(GetDefaultFontTtf("BB"), (o) => { debug_bb = !debug_bb; RefreshDebug(); });

            lbl4.AnchorPoint = new CCPoint(0, .5f);
            CCMenu menu = new CCMenu(new CCMenuItem[] { lbl1, lbl2, lbl3, lbl4 });

            menu.AlignItemsVertically();
            menu.Position = new CCPoint(windowSize.Width * .02f, windowSize.Height * .35f);
            InformationLayer.AddChild(menu);

            background_white          = new CCSprite("Background-alone.png");
            background_white.Position = windowSize.Center;
            background_white.Scale    = windowSize.Height / background_white.Texture.ContentSizeInPixels.Height;
            background_white.Visible  = false;
            InformationLayer.AddChild(background_white, -4);

            logo = new LogoNode();
            logo.InitialPosition = new CCPoint(new CCPoint(windowSize.Width * .90f, windowSize.Height * .05f));
            logo.Position        = new CCPoint(logo.InitialPosition);

            InformationLayer.AddChild(logo, -2);

            logo.RunAction(new CCRepeatForever(
                               new CCEaseSineInOut(new CCMoveBy(1.5f, new CCPoint(0, 10))),
                               new CCEaseSineInOut(new CCMoveBy(1.5f, new CCPoint(0, -10))))
                           );

            //Debug draw initialization
            //m_debugDraw = new CCChipmunkDebugDraw(DEFAULT_FULL_FONT);

            //Space initialization
            space = new cpSpace();
            //space.SetDebugDraw(m_debugDraw);

            space.CollisionEnabled = CollisionEnabled;
            m_debugDraw            = new PhysicsDebugDraw(space);
            CollisionEnabled
            AddChild(m_debugDraw);

            RefreshDebug();

            //Title initialization
            example             = GetDefaultFontTtf("Physics examples");
            example.AnchorPoint = new CCPoint(.5f, 1f);
            //example.Scale = .3f;
            InformationLayer.AddChild(example);
            SetTitle(this.GetType().Name);

            //Player initialization
            menuLayerPlayer             = GetPlayerLayer();
            menuLayerPlayer.AnchorPoint = new CCPoint(0, 0);

            menuLayerPlayer.Position = new CCPoint(Window.WindowSizeInPixels.Width * .12f, Window.WindowSizeInPixels.Height * .05f);
            InformationLayer.AddChild(menuLayerPlayer);

            //Listeners initializations
            //eMouse = new CCEventListenerMouse();
            //eMouse.OnMouseMove += OnMouseMove;
            //eMouse.OnMouseDown += OnMouseDown;
            //eMouse.OnMouseUp += OnMouseUp;
            //eMouse.OnMouseScroll = e => CCMouse.Instance.OnMouseScroll(e, this);
            //AddEventListener(eMouse);

            eTouch = new CCEventListenerTouchAllAtOnce();
            eTouch.OnTouchesBegan     += OnTouchesBegan;
            eTouch.OnTouchesMoved     += OnTouchesMoved;
            eTouch.OnTouchesCancelled += OnTouchesCancelled;
            eTouch.OnTouchesEnded     += OnTouchesEnded;
            AddEventListener(eTouch);
        }