Beispiel #1
0
        public Body[] GenerateBodies(World world, Vec2 basePosition, FixtureDef def)
        {
            if (_vecs.Count <= 1)
                throw new ArgumentOutOfRangeException("Vecs");

            Body[] bodies = new Body[_vecs.Count - 1];

            for (int i = 0; i < _vecs.Count - 1; ++i)
            {
                PolygonShape edge = new PolygonShape(_vecs[i], _vecs[i + 1]);

                BodyDef bd = new BodyDef();
                bd.Position = basePosition;

                bodies[i] = world.CreateBody(bd);
                bodies[i].CreateFixture(new FixtureDef(edge, 0, def.Restitution, def.Friction, false, def.UserData));
            }

            return bodies;
        }
Beispiel #2
0
        public void Start(World world, float totalLength, Vec2 start, Vec2 normal)
        {
            Clear();

            _hit = 0;
            _totalLength = totalLength;
            _length = totalLength;
            _start = start;
            _normal = normal;
            _world = world;

            // Send a beam out
            _callback.m_hit = false;
            _world.RayCast(_callback, start, start + (normal * _length));

            if (_callback.m_hit)
                Report(_callback.m_point, _callback.m_normal);
            else
            {
                starts.Add(_start);
                ends.Add(_start  + (_normal * _length));
            }
        }
Beispiel #3
0
        public TitleState(StateStack stack, Context context)
            : base(stack, context)
        {
            starttimer = new Clock();
            starttimer.Restart();

            titletext = new Text();
            titletext.Scale = new Vector2f(2, 2);
            titletext.DisplayedString = "PIXELTASIM";
            titletext.Font = mContext.mFonts.get(FontID.Title);
            titletext.centerOrigin();
            titletext.Position = new Vector2f(mContext.mWindow.Size.X/2, mContext.mWindow.Size.Y / 8);
            titletext.Color = Color.Black;

            square = new RectangleShape(new Vector2f(UnitConverter.toPixScale(0.5f), UnitConverter.toPixScale(0.5f)));
            square.centerOrigin();
            square.FillColor = Color.Red;
            square.OutlineColor = Color.Black;
            square.OutlineThickness = 1;

            b2World = new World(new Vec2(0, 10), false);
            BodyDef b2Def = new BodyDef();
            b2Def.BodyType = BodyType.Dynamic;
            b2Def.Position = new Vec2(UnitConverter.toSimScale(mContext.mWindow.Size.X / 2), UnitConverter.toSimScale(mContext.mWindow.Size.Y / 8*3));
            b2Body = b2World.CreateBody(b2Def);

            PolygonShape dynamicbox = new PolygonShape();
            dynamicbox.SetAsBox(UnitConverter.toSimScale(32), UnitConverter.toSimScale(32));

            FixtureDef fixDef = new FixtureDef();
            fixDef.Shape = dynamicbox;
            fixDef.Density = 1;
            fixDef.Friction = 0.3f;
            b2Body.CreateFixture(fixDef);

            square.Position = new Vector2f(UnitConverter.toPixScale(b2Body.Position.X), UnitConverter.toPixScale(b2Body.Position.Y));
        }
Beispiel #4
0
        public Test()
        {
            Vec2 gravity;
            gravity = new Vec2(0.0f, -10.0f);
            bool doSleep = true;
            m_world = new World(gravity, doSleep);
            m_bomb = null;
            m_textLine = 30;
            m_mouseJoint = null;
            m_pointCount = 0;

            m_destructionListener.test = this;
            m_world.DestructionListener = m_destructionListener;
            m_world.ContactListener = this;
            m_world.DebugDraw = m_debugDraw;

            m_bombSpawning = false;

            m_stepCount = 0;

            BodyDef bodyDef = new BodyDef();
            m_groundBody = m_world.CreateBody(bodyDef);
            m_groundBody.UserData = "Ground";
        }
Beispiel #5
0
 void EndTest()
 {
     _testing = false;
     _world = null;
     //simulationThread.Abort();
     //simulationThread = null;
 }
Beispiel #6
0
        void StartTest()
        {
            _testing = true;
            _world = new World(new Vec2(0, -10.0f), true);
            _world.DebugDraw = debugDraw;

            System.Collections.Generic.List<Body> bodies = new System.Collections.Generic.List<Body>();

            foreach (var x in WorldObject.Bodies)
            {
                var body = _world.CreateBody(x.Body);

                bodies.Add(body);

                foreach (var f in x.Fixtures)
                    body.CreateFixture(f.Fixture);

                body.MassData = x.Mass;
            }

            /*foreach (var j in WorldObject.Joints)
            {
                j.Joint.BodyA = bodies[j.BodyAIndex];
                j.Joint.BodyB = bodies[j.BodyBIndex];

                var joint = _world.CreateJoint(j.Joint);
            }*/
        }