当前位置: 首页>>代码示例>>C#>>正文


C# b2PolygonShape.Set方法代码示例

本文整理汇总了C#中Box2D.Collision.Shapes.b2PolygonShape.Set方法的典型用法代码示例。如果您正苦于以下问题:C# b2PolygonShape.Set方法的具体用法?C# b2PolygonShape.Set怎么用?C# b2PolygonShape.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Box2D.Collision.Shapes.b2PolygonShape的用法示例。


在下文中一共展示了b2PolygonShape.Set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreatePlatform

		void CreatePlatform() {
			
			// Define the dynamic body.
			var bodyDef = new b2BodyDef();
			bodyDef.type = b2BodyType.b2_staticBody; //or you could use b2_staticBody
			
			bodyDef.position.Set(initialLocation.X/Constants.PTM_RATIO, initialLocation.Y/Constants.PTM_RATIO);

			var shape = new b2PolygonShape();
			
			var num = 4;
			b2Vec2[] vertices = {
				new b2Vec2(-102.0f / Constants.PTM_RATIO, -49.5f / Constants.PTM_RATIO),
				new b2Vec2(-113.0f / Constants.PTM_RATIO, -81.5f / Constants.PTM_RATIO),
				new b2Vec2(113.0f / Constants.PTM_RATIO, -84.5f / Constants.PTM_RATIO),
				new b2Vec2(106.0f / Constants.PTM_RATIO, -47.5f / Constants.PTM_RATIO)
			};
			
			shape.Set(vertices, num);
			
			
			// Define the dynamic body fixture.
			var fixtureDef = new b2FixtureDef();
			fixtureDef.shape = shape;	
			fixtureDef.density = 1.0f;
			fixtureDef.friction = 0.3f;
			fixtureDef.restitution =  0.1f;
			
			CreateBodyWithSpriteAndFixture(theWorld, bodyDef, fixtureDef, spriteImageName);
			
			//CONTINUING TO ADD BODY SHAPE....
			
			// THIS IS THE Sling base....
			
			//row 1, col 1
			var num2 = 4;
			b2Vec2[] vertices2 = {
				new b2Vec2(41.0f / Constants.PTM_RATIO, -6.5f / Constants.PTM_RATIO),
				new b2Vec2(35.0f / Constants.PTM_RATIO, -57.5f / Constants.PTM_RATIO),
				new b2Vec2(57.0f / Constants.PTM_RATIO, -65.5f / Constants.PTM_RATIO),
				new b2Vec2(49.0f / Constants.PTM_RATIO, -7.5f / Constants.PTM_RATIO)
			};
			
			shape.Set(vertices2, num2);
			fixtureDef.shape = shape;
			body.CreateFixture(fixtureDef);
			
		}
开发者ID:alegogit,项目名称:AngryNinjas,代码行数:48,代码来源:StartPlatform.cs

示例2: CreateGround

		private void CreateGround()
		{
			// Define the dynamic body.
			var bodyDef = new b2BodyDef();
			bodyDef.type = b2BodyType.b2_staticBody; //or you could use b2_staticBody
			
			bodyDef.position.Set(initialLocation.X/Constants.PTM_RATIO, initialLocation.Y/Constants.PTM_RATIO);
			
			b2PolygonShape shape = new b2PolygonShape();
			
			int num = 4;
			b2Vec2[] vertices = {
				new b2Vec2(-1220.0f / Constants.PTM_RATIO, 54.0f / Constants.PTM_RATIO),
				new b2Vec2(-1220.0f / Constants.PTM_RATIO, -52.0f / Constants.PTM_RATIO),
				new b2Vec2(1019.0f / Constants.PTM_RATIO, -52.0f / Constants.PTM_RATIO),
				new b2Vec2(1019.0f / Constants.PTM_RATIO, 54.0f / Constants.PTM_RATIO)
			};
			
			shape.Set(vertices, num);
			
			
			// Define the dynamic body fixture.
			var fixtureDef = new b2FixtureDef();
			fixtureDef.shape = shape;	
			fixtureDef.density = 1.0f;
			fixtureDef.friction = 1.0f;
			fixtureDef.restitution =  0.1f;
			
			CreateBodyWithSpriteAndFixture(theWorld, bodyDef, fixtureDef, spriteImageName);
			
			if (!TheLevel.SharedLevel.IS_RETINA)
			{
				//non retina adjustment
				sprite.ScaleX = 1.05f;
				
			} else {
				
				// retina adjustment
				
				sprite.ScaleX = 2.05f;
				sprite.ScaleY = 2.0f;
			}

		}
开发者ID:headinthebox,项目名称:cocos-sharp-samples,代码行数:44,代码来源:GroundPlane.cs

示例3: Car

        public Car()
        {
            m_hz = 4.0f;
            m_zeta = 0.7f;
            m_speed = 50.0f;

            b2Body ground = null;
            {
                b2BodyDef bd  = new b2BodyDef();
                ground = m_world.CreateBody(bd);

                b2EdgeShape shape = new b2EdgeShape();

                b2FixtureDef fd = new b2FixtureDef();
                fd.shape = shape;
                fd.density = 0.0f;
                fd.friction = 0.6f;

                shape.Set(new b2Vec2(-20.0f, 0.0f), new b2Vec2(20.0f, 0.0f));
                ground.CreateFixture(fd);

                float[] hs = {0.25f, 1.0f, 4.0f, 0.0f, 0.0f, -1.0f, -2.0f, -2.0f, -1.25f, 0.0f};

                float x = 20.0f, y1 = 0.0f, dx = 5.0f;

                for (int i = 0; i < 10; ++i)
                {
                    float y2 = hs[i];
                    shape.Set(new b2Vec2(x, y1), new b2Vec2(x + dx, y2));
                    ground.CreateFixture(fd);
                    y1 = y2;
                    x += dx;
                }

                for (int i = 0; i < 10; ++i)
                {
                    float y2 = hs[i];
                    shape.Set(new b2Vec2(x, y1), new b2Vec2(x + dx, y2));
                    ground.CreateFixture(fd);
                    y1 = y2;
                    x += dx;
                }

                shape.Set(new b2Vec2(x, 0.0f), new b2Vec2(x + 40.0f, 0.0f));
                ground.CreateFixture(fd);

                x += 80.0f;
                shape.Set(new b2Vec2(x, 0.0f), new b2Vec2(x + 40.0f, 0.0f));
                ground.CreateFixture(fd);

                x += 40.0f;
                shape.Set(new b2Vec2(x, 0.0f), new b2Vec2(x + 10.0f, 5.0f));
                ground.CreateFixture(fd);

                x += 20.0f;
                shape.Set(new b2Vec2(x, 0.0f), new b2Vec2(x + 40.0f, 0.0f));
                ground.CreateFixture(fd);

                x += 40.0f;
                shape.Set(new b2Vec2(x, 0.0f), new b2Vec2(x, 20.0f));
                ground.CreateFixture(fd);
            }

            // Teeter
            {
                b2BodyDef bd  = new b2BodyDef();
                bd.position.Set(140.0f, 1.0f);
                bd.type = b2BodyType.b2_dynamicBody;
                b2Body body = m_world.CreateBody(bd);

                b2PolygonShape box = new b2PolygonShape();
                box.SetAsBox(10.0f, 0.25f);
                body.CreateFixture(box, 1.0f);

                b2RevoluteJointDef jd = new b2RevoluteJointDef();
                jd.Initialize(ground, body, body.Position);
                jd.lowerAngle = -8.0f * b2Settings.b2_pi / 180.0f;
                jd.upperAngle = 8.0f * b2Settings.b2_pi / 180.0f;
                jd.enableLimit = true;
                m_world.CreateJoint(jd);

                body.ApplyAngularImpulse(100.0f);
            }

            // Bridge
            {
                int N = 20;
                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(1.0f, 0.125f);

                b2FixtureDef fd = new b2FixtureDef();
                fd.shape = shape;
                fd.density = 1.0f;
                fd.friction = 0.6f;

                b2RevoluteJointDef jd = new b2RevoluteJointDef();

                b2Body prevBody = ground;
                for (int i = 0; i < N; ++i)
                {
//.........这里部分代码省略.........
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:101,代码来源:Car.cs

示例4: CreateEnemy

        void CreateEnemy()
        {
            // Define the dynamic body.
            var bodyDef = b2BodyDef.Create();
            bodyDef.type = b2BodyType.b2_dynamicBody; //or you could use b2_staticBody

            bodyDef.fixedRotation = isRotationFixed;

            bodyDef.position.Set(initialLocation.X/Constants.PTM_RATIO, initialLocation.Y/Constants.PTM_RATIO);

            b2PolygonShape shape = new b2PolygonShape();
            b2CircleShape shapeCircle = new b2CircleShape();

            if (shapeCreationMethod == CreationMethod.DiameterOfImageForCircle) {

                var tempSprite = new CCSprite(spriteImageName);
                float radiusInMeters = (tempSprite.ContentSize.Width / Constants.PTM_RATIO) * 0.5f;

                shapeCircle.Radius = radiusInMeters;

            }

            else if ( shapeCreationMethod == CreationMethod.ShapeOfSourceImage) {

                var tempSprite = new CCSprite(spriteImageName);

                var num = 4;
                b2Vec2[] vertices = {
                    new b2Vec2( (tempSprite.ContentSize.Width / -2 ) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2 ) / Constants.PTM_RATIO), //top left corner
                    new b2Vec2( (tempSprite.ContentSize.Width / -2 ) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2 ) / Constants.PTM_RATIO), //bottom left corner
                    new b2Vec2( (tempSprite.ContentSize.Width / 2 ) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2 )/ Constants.PTM_RATIO), //bottom right corner
                    new b2Vec2( (tempSprite.ContentSize.Width / 2 ) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2 ) / Constants.PTM_RATIO) //top right corner
                };
                shape.Set(vertices, num);
            }
            else if ( shapeCreationMethod == CreationMethod.ShapeOfSourceImageButSlightlySmaller ) {

                var tempSprite = new CCSprite(spriteImageName);

                var num = 4;
                b2Vec2[] vertices = {
                    new b2Vec2( (tempSprite.ContentSize.Width / -2 ) *.8f / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2 )*.8f / Constants.PTM_RATIO), //top left corner
                    new b2Vec2( (tempSprite.ContentSize.Width / -2 )*.8f / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2 )*.8f / Constants.PTM_RATIO), //bottom left corner
                    new b2Vec2( (tempSprite.ContentSize.Width / 2 )*.8f / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2 )*.8f / Constants.PTM_RATIO), //bottom right corner
                    new b2Vec2( (tempSprite.ContentSize.Width / 2 )*.8f / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2 )*.8f / Constants.PTM_RATIO) //top right corner
                };
                shape.Set(vertices, num);
            }

            else if ( shapeCreationMethod == CreationMethod.Triangle) {
                var tempSprite = new CCSprite(spriteImageName);

                var num = 3;
                b2Vec2[] vertices = {
                    new b2Vec2( (tempSprite.ContentSize.Width / -2 ) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2 ) / Constants.PTM_RATIO), //bottom left corner
                    new b2Vec2( (tempSprite.ContentSize.Width / 2 ) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2 ) / Constants.PTM_RATIO), //bottom right corner
                    new b2Vec2( 0.0f / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2 )/ Constants.PTM_RATIO) // top center of image
                };

                shape.Set(vertices, num);
            }

            else if ( shapeCreationMethod == CreationMethod.TriangleRightAngle) {
                var tempSprite = new CCSprite(spriteImageName);

                var num = 3;
                b2Vec2[] vertices = {
                    new b2Vec2( (tempSprite.ContentSize.Width / 2 ) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2 ) / Constants.PTM_RATIO),  //top right corner
                    new b2Vec2( (tempSprite.ContentSize.Width / -2 ) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2 ) / Constants.PTM_RATIO), //top left corner
                    new b2Vec2( (tempSprite.ContentSize.Width / -2 ) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2 )/ Constants.PTM_RATIO) //bottom left corner
                };

                shape.Set(vertices, num);
            }

            else if ( shapeCreationMethod == CreationMethod.Trapezoid) {
                var tempSprite = new CCSprite(spriteImageName);

                var num = 4;
                b2Vec2[] vertices = {
                    new b2Vec2( (tempSprite.ContentSize.Width / 4 ) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2 ) / Constants.PTM_RATIO),  //top of image, 3/4's across
                    new b2Vec2( (tempSprite.ContentSize.Width / -4 ) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2 ) / Constants.PTM_RATIO),  //top of image, 1/4's across
                    new b2Vec2( (tempSprite.ContentSize.Width / -2 ) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2 ) / Constants.PTM_RATIO), //bottom left corner
                    new b2Vec2( (tempSprite.ContentSize.Width / 2 ) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2 ) / Constants.PTM_RATIO), //bottom right corner
                };

                shape.Set(vertices, num);
            }

            else if ( shapeCreationMethod == CreationMethod.Hexagon) {

                var tempSprite = new CCSprite(spriteImageName);

                var num = 6;
                b2Vec2[] vertices = {
                    new b2Vec2( (tempSprite.ContentSize.Width / -4 ) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / 2 ) / Constants.PTM_RATIO), //top of image, 1/4 across
                    new b2Vec2( (tempSprite.ContentSize.Width / -2 )  / Constants.PTM_RATIO, 0.0f / Constants.PTM_RATIO), // left, center
                    new b2Vec2( (tempSprite.ContentSize.Width / -4 ) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2 ) / Constants.PTM_RATIO), //bottom of image, 1/4 across
                    new b2Vec2( (tempSprite.ContentSize.Width / 4 ) / Constants.PTM_RATIO, (tempSprite.ContentSize.Height / -2 ) / Constants.PTM_RATIO), //bottom of image, 3/4's across
                    new b2Vec2( (tempSprite.ContentSize.Width /  2 ) / Constants.PTM_RATIO, 0.0f / Constants.PTM_RATIO), // right, center
//.........这里部分代码省略.........
开发者ID:CasperWollesen,项目名称:AngryNinjas,代码行数:101,代码来源:Enemy.cs

示例5: Revolute

        public Revolute()
        {
            b2Body ground;
            {
                b2BodyDef bd  = new b2BodyDef();
                ground = m_world.CreateBody(bd);

                b2EdgeShape shape = new b2EdgeShape();
                shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));

                b2FixtureDef fd = new b2FixtureDef();
                fd.shape = shape;
                //fd.filter.categoryBits = 2;

                ground.CreateFixture(fd);
            }

            {
                b2CircleShape shape = new b2CircleShape();
                shape.Radius = 0.5f;

                b2BodyDef bd  = new b2BodyDef();
                bd.type = b2BodyType.b2_dynamicBody;

                b2RevoluteJointDef rjd = new b2RevoluteJointDef();

                bd.position.Set(-10.0f, 20.0f);
                b2Body body = m_world.CreateBody(bd);
                body.CreateFixture(shape, 5.0f);

                float w = 100.0f;
                body.AngularVelocity = w;
                body.LinearVelocity = new b2Vec2(-8.0f * w, 0.0f);

                rjd.Initialize(ground, body, new b2Vec2(-10.0f, 12.0f));
                rjd.motorSpeed = 1.0f * b2Settings.b2_pi;
                rjd.maxMotorTorque = 10000.0f;
                rjd.enableMotor = false;
                rjd.lowerAngle = -0.25f * b2Settings.b2_pi;
                rjd.upperAngle = 0.5f * b2Settings.b2_pi;
                rjd.enableLimit = true;
                rjd.CollideConnected = true;

                m_joint = (b2RevoluteJoint) m_world.CreateJoint(rjd);
            }

            {
                b2CircleShape circle_shape = new b2CircleShape();
                circle_shape.Radius = 3.0f;

                b2BodyDef circle_bd  = new b2BodyDef();
                circle_bd.type = b2BodyType.b2_dynamicBody;
                circle_bd.position.Set(5.0f, 30.0f);

                b2FixtureDef fd = new b2FixtureDef();
                fd.density = 5.0f;
                fd.filter.maskBits = 1;
                fd.shape = circle_shape;

                m_ball = m_world.CreateBody(circle_bd);
                m_ball.CreateFixture(fd);

                b2PolygonShape polygon_shape = new b2PolygonShape();
                polygon_shape.SetAsBox(10.0f, 0.2f, new b2Vec2(-10.0f, 0.0f), 0.0f);

                b2BodyDef polygon_bd  = new b2BodyDef();
                polygon_bd.position.Set(20.0f, 10.0f);
                polygon_bd.type = b2BodyType.b2_dynamicBody;
                polygon_bd.bullet = true;
                b2Body polygon_body = m_world.CreateBody(polygon_bd);
                polygon_body.CreateFixture(polygon_shape, 2.0f);

                b2RevoluteJointDef rjd = new b2RevoluteJointDef();
                rjd.Initialize(ground, polygon_body, new b2Vec2(20.0f, 10.0f));
                rjd.lowerAngle = -0.25f * b2Settings.b2_pi;
                rjd.upperAngle = 0.0f * b2Settings.b2_pi;
                rjd.enableLimit = true;
                m_world.CreateJoint(rjd);
            }

            // Tests mass computation of a small object far from the origin
            {
                b2BodyDef bodyDef  = new b2BodyDef();
                bodyDef.type = b2BodyType.b2_dynamicBody;
                b2Body body = m_world.CreateBody(bodyDef);

                b2PolygonShape polyShape = new b2PolygonShape();
                b2Vec2[] verts = new b2Vec2[3];
                verts[0].Set(17.63f, 36.31f);
                verts[1].Set(17.52f, 36.69f);
                verts[2].Set(17.19f, 36.36f);
                polyShape.Set(verts, 3);

                b2FixtureDef polyFixtureDef = new b2FixtureDef();
                polyFixtureDef.shape = polyShape;
                polyFixtureDef.density = 1;

                body.CreateFixture(polyFixtureDef); //assertion hits inside here
            }

//.........这里部分代码省略.........
开发者ID:Karunp,项目名称:cocos2d-xna,代码行数:101,代码来源:Revolute.cs

示例6: CreateObject

		void CreateObject()
		{
			
			
			// Define the dynamic body.
			var bodyDef = new b2BodyDef();
			bodyDef.type = b2BodyType.b2_dynamicBody; //or you could use b2_staticBody

			bodyDef.position.Set(initialLocation.X/Constants.PTM_RATIO, initialLocation.Y/Constants.PTM_RATIO);
			
			var shape = new b2PolygonShape();
			var shapeCircle = new b2CircleShape();
			
			if (shapeCreationMethod == CreationMethod.DiameterOfImageForCircle) {
				
				var tempSprite = new CCSprite(spriteImageName);
                var radiusInMeters = (tempSprite.Texture.ContentSizeInPixels.Width / Constants.PTM_RATIO) * 0.5f;
				
				shapeCircle.Radius = radiusInMeters;
				
			}
			
			
			else if ( shapeCreationMethod == CreationMethod.ShapeOfSourceImage) {
				
				var tempSprite = new CCSprite(spriteImageName);
				
				var num = 4;
				b2Vec2[] vertices = {
					new b2Vec2( (tempSprite.Texture.ContentSizeInPixels.Width / -2 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2 ) / Constants.PTM_RATIO), //top left corner
					new b2Vec2( (tempSprite.Texture.ContentSizeInPixels.Width / -2 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2 ) / Constants.PTM_RATIO), //bottom left corner
					new b2Vec2( (tempSprite.Texture.ContentSizeInPixels.Width / 2 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2 )/ Constants.PTM_RATIO), //bottom right corner
					new b2Vec2( (tempSprite.Texture.ContentSizeInPixels.Width / 2 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2 ) / Constants.PTM_RATIO) //top right corner
				};
				shape.Set(vertices, num);
			}
			
			else if ( shapeCreationMethod == CreationMethod.Triangle) {
				var tempSprite = new CCSprite(spriteImageName);
				
				var num = 3;
				b2Vec2[] vertices = {
					new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -2 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2 ) / Constants.PTM_RATIO), //bottom left corner
					new b2Vec2( (tempSprite.Texture.ContentSizeInPixels.Width / 2 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2 ) / Constants.PTM_RATIO), //bottom right corner
					new b2Vec2( 0.0f / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2 )/ Constants.PTM_RATIO) // top center of image
				};
				
				shape.Set(vertices, num);
			}
			
			else if ( shapeCreationMethod == CreationMethod.TriangleRightAngle) {
				var tempSprite = new CCSprite(spriteImageName);
				
				var num = 3;
				b2Vec2[] vertices = {
					new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 2 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2 ) / Constants.PTM_RATIO),  //top right corner
					new b2Vec2( (tempSprite.Texture.ContentSizeInPixels.Width / -2 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2 ) / Constants.PTM_RATIO), //top left corner
					new b2Vec2( (tempSprite.Texture.ContentSizeInPixels.Width / -2 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2 )/ Constants.PTM_RATIO) //bottom left corner
				};
				
				shape.Set(vertices, num);
			}
			
			else if ( shapeCreationMethod == CreationMethod.Trapezoid) {
				var tempSprite = new CCSprite(spriteImageName);
				
				var num = 4;
				b2Vec2[] vertices = {
					new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 4 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2 ) / Constants.PTM_RATIO),  //top of image, 3/4's across
					new b2Vec2( (tempSprite.Texture.ContentSizeInPixels.Width / -4 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2 ) / Constants.PTM_RATIO),  //top of image, 1/4's across
					new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -2 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2 ) / Constants.PTM_RATIO), //bottom left corner
					new b2Vec2( (tempSprite.Texture.ContentSizeInPixels.Width / 2 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2 ) / Constants.PTM_RATIO), //bottom right corner
				};
				
				shape.Set(vertices, num);
			}
			
			
			else if ( shapeCreationMethod == CreationMethod.Hexagon) {
				
				var tempSprite = new CCSprite(spriteImageName);
				
				var num = 6;
				b2Vec2[] vertices = {
					new b2Vec2( (tempSprite.Texture.ContentSizeInPixels.Width / -4 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2 ) / Constants.PTM_RATIO), //top of image, 1/4 across
					new b2Vec2( (tempSprite.Texture.ContentSizeInPixels.Width / -2 )  / Constants.PTM_RATIO, 0.0f / Constants.PTM_RATIO), // left, center
					new b2Vec2( (tempSprite.Texture.ContentSizeInPixels.Width / -4 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2 ) / Constants.PTM_RATIO), //bottom of image, 1/4 across
					new b2Vec2( (tempSprite.Texture.ContentSizeInPixels.Width / 4 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2 ) / Constants.PTM_RATIO), //bottom of image, 3/4's across
					new b2Vec2( (tempSprite.Texture.ContentSizeInPixels.Width /  2 ) / Constants.PTM_RATIO, 0.0f / Constants.PTM_RATIO), // right, center
					new b2Vec2( (tempSprite.Texture.ContentSizeInPixels.Width / 4 ) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2 ) / Constants.PTM_RATIO) //top of image, 3/4's across
				};
				
				shape.Set(vertices, num);
			}
			
			else if ( shapeCreationMethod == CreationMethod.Pentagon) {
				
				var tempSprite = new CCSprite(spriteImageName);
				
				var num = 5;
//.........这里部分代码省略.........
开发者ID:460189852,项目名称:cocos-sharp-samples,代码行数:101,代码来源:StackObject.cs

示例7: CompoundShapes

        public CompoundShapes()
        {
            {
                b2BodyDef bd  = new b2BodyDef();
                bd.position.Set(0.0f, 0.0f);
                b2Body body = m_world.CreateBody(bd);

                b2EdgeShape shape = new b2EdgeShape();
                shape.Set(new b2Vec2(50.0f, 0.0f), new b2Vec2(-50.0f, 0.0f));

                body.CreateFixture(shape, 0.0f);
            }

            {
                b2CircleShape circle1 = new b2CircleShape();
                circle1.Radius = 0.5f;
                circle1.Position = new b2Vec2(-0.5f, 0.5f);

                b2CircleShape circle2 = new b2CircleShape();
                circle2.Radius = 0.5f;
                circle2.Position = new b2Vec2(0.5f, 0.5f);

                for (int i = 0; i < 10; ++i)
                {
                    float x = Rand.RandomFloat(-0.1f, 0.1f);
                    b2BodyDef bd  = new b2BodyDef();
                    bd.type = b2BodyType.b2_dynamicBody;
                    bd.position.Set(x + 5.0f, 1.05f + 2.5f * i);
                    bd.angle = Rand.RandomFloat(-b2Settings.b2_pi, b2Settings.b2_pi);
                    b2Body body = m_world.CreateBody(bd);
                    body.CreateFixture(circle1, 2.0f);
                    body.CreateFixture(circle2, 0.0f);
                }
            }

            {
                b2PolygonShape polygon1 = new b2PolygonShape();
                polygon1.SetAsBox(0.25f, 0.5f);

                b2PolygonShape polygon2 = new b2PolygonShape();
                polygon2.SetAsBox(0.25f, 0.5f, new b2Vec2(0.0f, -0.5f), 0.5f * b2Settings.b2_pi);

                for (int i = 0; i < 10; ++i)
                {
                    float x = Rand.RandomFloat(-0.1f, 0.1f);
                    b2BodyDef bd  = new b2BodyDef();
                    bd.type = b2BodyType.b2_dynamicBody;
                    bd.position.Set(x - 5.0f, 1.05f + 2.5f * i);
                    bd.angle = Rand.RandomFloat(-b2Settings.b2_pi, b2Settings.b2_pi);
                    b2Body body = m_world.CreateBody(bd);
                    body.CreateFixture(polygon1, 2.0f);
                    body.CreateFixture(polygon2, 2.0f);
                }
            }

            {
                b2Transform xf1 = new b2Transform();
                xf1.q.Set(0.3524f * b2Settings.b2_pi);
                xf1.p = xf1.q.GetXAxis();

                b2Vec2[] vertices = new b2Vec2[3];

                b2PolygonShape triangle1 = new b2PolygonShape();
                vertices[0] = b2Math.b2Mul(xf1, new b2Vec2(-1.0f, 0.0f));
                vertices[1] = b2Math.b2Mul(xf1, new b2Vec2(1.0f, 0.0f));
                vertices[2] = b2Math.b2Mul(xf1, new b2Vec2(0.0f, 0.5f));
                triangle1.Set(vertices, 3);

                b2Transform xf2 = new b2Transform();
                xf2.q.Set(-0.3524f * b2Settings.b2_pi);
                xf2.p = -xf2.q.GetXAxis();

                b2PolygonShape triangle2 = new b2PolygonShape();
                vertices[0] = b2Math.b2Mul(xf2, new b2Vec2(-1.0f, 0.0f));
                vertices[1] = b2Math.b2Mul(xf2, new b2Vec2(1.0f, 0.0f));
                vertices[2] = b2Math.b2Mul(xf2, new b2Vec2(0.0f, 0.5f));
                triangle2.Set(vertices, 3);

                for (int i = 0; i < 10; ++i)
                {
                    float x = Rand.RandomFloat(-0.1f, 0.1f);
                    b2BodyDef bd  = new b2BodyDef();
                    bd.type = b2BodyType.b2_dynamicBody;
                    bd.position.Set(x, 2.05f + 2.5f * i);
                    bd.angle = 0.0f;
                    b2Body body = m_world.CreateBody(bd);
                    body.CreateFixture(triangle1, 2.0f);
                    body.CreateFixture(triangle2, 2.0f);
                }
            }

            {
                b2PolygonShape bottom = new b2PolygonShape();
                bottom.SetAsBox(1.5f, 0.15f);

                b2PolygonShape left = new b2PolygonShape();
                left.SetAsBox(0.15f, 2.7f, new b2Vec2(-1.45f, 2.35f), 0.2f);

                b2PolygonShape right = new b2PolygonShape();
                right.SetAsBox(0.15f, 2.7f, new b2Vec2(1.45f, 2.35f), -0.2f);
//.........这里部分代码省略.........
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:101,代码来源:CompoundShapes.cs

示例8: CreateLeg

        public void CreateLeg(float s, b2Vec2 wheelAnchor)
        {
            b2Vec2 p1 = new b2Vec2(5.4f * s, -6.1f);
            b2Vec2 p2 = new b2Vec2(7.2f * s, -1.2f);
            b2Vec2 p3 = new b2Vec2(4.3f * s, -1.9f);
            b2Vec2 p4 = new b2Vec2(3.1f * s, 0.8f);
            b2Vec2 p5 = new b2Vec2(6.0f * s, 1.5f);
            b2Vec2 p6 = new b2Vec2(2.5f * s, 3.7f);

            b2FixtureDef fd1 = new b2FixtureDef();
            b2FixtureDef fd2 = new b2FixtureDef();
            fd1.filter.groupIndex = -1;
            fd2.filter.groupIndex = -1;
            fd1.density = 1.0f;
            fd2.density = 1.0f;

            b2PolygonShape poly1 = new b2PolygonShape();
            b2PolygonShape poly2 = new b2PolygonShape();

            if (s > 0.0f)
            {
                b2Vec2[] vertices = new b2Vec2[3];

                vertices[0] = p1;
                vertices[1] = p2;
                vertices[2] = p3;
                poly1.Set(vertices, 3);

                vertices[0] = b2Vec2.Zero;
                vertices[1] = p5 - p4;
                vertices[2] = p6 - p4;
                poly2.Set(vertices, 3);
            }
            else
            {
                b2Vec2[] vertices = new b2Vec2[3];

                vertices[0] = p1;
                vertices[1] = p3;
                vertices[2] = p2;
                poly1.Set(vertices, 3);

                vertices[0] = b2Vec2.Zero;
                vertices[1] = p6 - p4;
                vertices[2] = p5 - p4;
                poly2.Set(vertices, 3);
            }

            fd1.shape = poly1;
            fd2.shape = poly2;

            b2BodyDef bd1  = new b2BodyDef();
            b2BodyDef bd2  = new b2BodyDef();
            bd1.type = b2BodyType.b2_dynamicBody;
            bd2.type = b2BodyType.b2_dynamicBody;
            bd1.position = m_offset;
            bd2.position = p4 + m_offset;

            bd1.angularDamping = 10.0f;
            bd2.angularDamping = 10.0f;

            b2Body body1 = m_world.CreateBody(bd1);
            b2Body body2 = m_world.CreateBody(bd2);

            body1.CreateFixture(fd1);
            body2.CreateFixture(fd2);

            b2DistanceJointDef djd = new b2DistanceJointDef();

            // Using a soft distance constraint can reduce some jitter.
            // It also makes the structure seem a bit more fluid by
            // acting like a suspension system.
            djd.dampingRatio = 0.5f;
            djd.frequencyHz = 10.0f;

            djd.Initialize(body1, body2, p2 + m_offset, p5 + m_offset);
            m_world.CreateJoint(djd);

            djd.Initialize(body1, body2, p3 + m_offset, p4 + m_offset);
            m_world.CreateJoint(djd);

            djd.Initialize(body1, m_wheel, p3 + m_offset, wheelAnchor + m_offset);
            m_world.CreateJoint(djd);

            djd.Initialize(body2, m_wheel, p6 + m_offset, wheelAnchor + m_offset);
            m_world.CreateJoint(djd);

            b2RevoluteJointDef rjd = new b2RevoluteJointDef();

            rjd.Initialize(body2, m_chassis, p4 + m_offset);
            m_world.CreateJoint(rjd);
        }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:92,代码来源:TheoJansen.cs

示例9: ApplyForce

        public ApplyForce()
        {
            m_world.Gravity = new b2Vec2(0.0f, 0.0f);

            float k_restitution = 0.4f;

            b2Body ground;
            {
                b2BodyDef bd  = new b2BodyDef();
                bd.position = new b2Vec2(0.0f, 20.0f);
                ground = m_world.CreateBody(bd);

                b2EdgeShape shape = new b2EdgeShape();

                b2FixtureDef sd = new b2FixtureDef();
                sd.shape = shape;
                sd.density = 0.0f;
                sd.restitution = k_restitution;

                // Left vertical
                shape.Set(new b2Vec2(-20.0f, -20.0f), new b2Vec2(-20.0f, 20.0f));
                ground.CreateFixture(sd);

                // Right vertical
                shape.Set(new b2Vec2(20.0f, -20.0f), new b2Vec2(20.0f, 20.0f));
                ground.CreateFixture(sd);

                // Top horizontal
                shape.Set(new b2Vec2(-20.0f, 20.0f), new b2Vec2(20.0f, 20.0f));
                ground.CreateFixture(sd);

                // Bottom horizontal
                shape.Set(new b2Vec2(-20.0f, -20.0f), new b2Vec2(20.0f, -20.0f));
                ground.CreateFixture(sd);
            }

            {
                b2Transform xf1;
                xf1.q = new b2Rot(0.3524f * b2Settings.b2_pi);
                xf1.p = xf1.q.GetXAxis();

                b2Vec2[] vertices = new b2Vec2[3];
                vertices[0] = b2Math.b2Mul(xf1, new b2Vec2(-1.0f, 0.0f));
                vertices[1] = b2Math.b2Mul(xf1, new b2Vec2(1.0f, 0.0f));
                vertices[2] = b2Math.b2Mul(xf1, new b2Vec2(0.0f, 0.5f));

                b2PolygonShape poly1 = new b2PolygonShape();
                poly1.Set(vertices, 3);

                b2FixtureDef sd1 = new b2FixtureDef();
                sd1.shape = poly1;
                sd1.density = 4.0f;

                b2Transform xf2 = new b2Transform();
                xf2.q.Set(-0.3524f * b2Settings.b2_pi);
                xf2.p = -xf2.q.GetXAxis();

                vertices[0] = b2Math.b2Mul(xf2, new b2Vec2(-1.0f, 0.0f));
                vertices[1] = b2Math.b2Mul(xf2, new b2Vec2(1.0f, 0.0f));
                vertices[2] = b2Math.b2Mul(xf2, new b2Vec2(0.0f, 0.5f));

                b2PolygonShape poly2 = new b2PolygonShape();
                poly2.Set(vertices, 3);

                b2FixtureDef sd2 = new b2FixtureDef();
                sd2.shape = poly2;
                sd2.density = 2.0f;

                b2BodyDef bd  = new b2BodyDef();
                bd.type = b2BodyType.b2_dynamicBody;
                bd.angularDamping = 5.0f;
                bd.linearDamping = 0.1f;

                bd.position.Set(0.0f, 2.0f);
                bd.angle = b2Settings.b2_pi;
                bd.allowSleep = false;
                m_body = m_world.CreateBody(bd);
                m_body.CreateFixture(sd1);
                m_body.CreateFixture(sd2);
            }

            {
                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(0.5f, 0.5f);

                b2FixtureDef fd = new b2FixtureDef();
                fd.shape = shape;
                fd.density = 1.0f;
                fd.friction = 0.3f;

                for (int i = 0; i < 10; ++i)
                {
                    b2BodyDef bd  = new b2BodyDef();
                    bd.type = b2BodyType.b2_dynamicBody;

                    bd.position = new b2Vec2(0.0f, 5.0f + 1.54f * i);
                    b2Body body = m_world.CreateBody(bd);

                    body.CreateFixture(fd);

//.........这里部分代码省略.........
开发者ID:p07r0457,项目名称:cocos2d-xna,代码行数:101,代码来源:ApplyForce.cs

示例10: Bridge

        public Bridge()
        {
            b2Body ground = null;
            {
                b2BodyDef bd  = new b2BodyDef();
                ground = m_world.CreateBody(bd);

                b2EdgeShape shape = new b2EdgeShape();
                shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));
                ground.CreateFixture(shape, 0.0f);
            }

            {
                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(0.5f, 0.125f);

                b2FixtureDef fd = new b2FixtureDef();
                fd.shape = shape;
                fd.density = 20.0f;
                fd.friction = 0.2f;

                b2RevoluteJointDef jd = new b2RevoluteJointDef();

                b2Body prevBody = ground;
                for (int i = 0; i < e_count; ++i)
                {
                    b2BodyDef bd  = new b2BodyDef();
                    bd.type = b2BodyType.b2_dynamicBody;
                    bd.position = new b2Vec2(-14.5f + 1.0f * i, 5.0f);
                    b2Body body = m_world.CreateBody(bd);
                    body.CreateFixture(fd);

                    b2Vec2 anchor = new b2Vec2(-15.0f + 1.0f * i, 5.0f);
                    jd.Initialize(prevBody, body, anchor);
                    m_world.CreateJoint(jd);

                    if (i == (e_count >> 1))
                    {
                        m_middle = body;
                    }
                    prevBody = body;
                }

                b2Vec2 anchor1 = new b2Vec2(-15.0f + 1.0f * e_count, 5.0f);
                jd.Initialize(prevBody, ground, anchor1);
                m_world.CreateJoint(jd);
            }

            for (int i = 0; i < 2; ++i)
            {
                b2Vec2[] vertices = new b2Vec2[3];
                vertices[0].Set(-0.5f, 0.0f);
                vertices[1].Set(0.5f, 0.0f);
                vertices[2].Set(0.0f, 1.5f);

                b2PolygonShape shape = new b2PolygonShape();
                shape.Set(vertices, 3);

                b2FixtureDef fd = new b2FixtureDef();
                fd.shape = shape;
                fd.density = 1.0f;

                b2BodyDef bd  = new b2BodyDef();
                bd.type = b2BodyType.b2_dynamicBody;
                bd.position = new b2Vec2(-8.0f + 8.0f * i, 12.0f);
                b2Body body = m_world.CreateBody(bd);
                body.CreateFixture(fd);
            }

            for (int i = 0; i < 3; ++i)
            {
                b2CircleShape shape = new b2CircleShape();
                shape.Radius = 0.5f;

                b2FixtureDef fd = new b2FixtureDef();
                fd.shape = shape;
                fd.density = 1.0f;

                b2BodyDef bd  = new b2BodyDef();
                bd.type = b2BodyType.b2_dynamicBody;
                bd.position.Set(-6.0f + 6.0f * i, 10.0f);
                b2Body body = m_world.CreateBody(bd);
                body.CreateFixture(fd);
            }
        }
开发者ID:Karunp,项目名称:cocos2d-xna,代码行数:85,代码来源:Bridge.cs

示例11: CollisionFiltering

        public CollisionFiltering()
        {
            // Ground body
            {
                b2EdgeShape shape = new b2EdgeShape();
                shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));

                b2FixtureDef sd = new b2FixtureDef();
                sd.shape = shape;
                sd.friction = 0.3f;

                b2BodyDef bd  = new b2BodyDef();
                b2Body ground = m_world.CreateBody(bd);
                ground.CreateFixture(sd);
            }

            // Small triangle
            b2Vec2[] vertices = new b2Vec2[3];
            vertices[0].Set(-1.0f, 0.0f);
            vertices[1].Set(1.0f, 0.0f);
            vertices[2].Set(0.0f, 2.0f);
            b2PolygonShape polygon = new b2PolygonShape();
            polygon.Set(vertices, 3);

            b2FixtureDef triangleShapeDef = new b2FixtureDef();
            triangleShapeDef.shape = polygon;
            triangleShapeDef.density = 1.0f;

            triangleShapeDef.filter.groupIndex = k_smallGroup;
            triangleShapeDef.filter.categoryBits = k_triangleCategory;
            triangleShapeDef.filter.maskBits = k_triangleMask;

            b2BodyDef triangleBodyDef  = new b2BodyDef();
            triangleBodyDef.type = b2BodyType.b2_dynamicBody;
            triangleBodyDef.position.Set(-5.0f, 2.0f);

            b2Body body1 = m_world.CreateBody(triangleBodyDef);
            body1.CreateFixture(triangleShapeDef);

            // Large triangle (recycle definitions)
            vertices[0] *= 2.0f;
            vertices[1] *= 2.0f;
            vertices[2] *= 2.0f;
            polygon.Set(vertices, 3);
            triangleShapeDef.filter.groupIndex = k_largeGroup;
            triangleBodyDef.position.Set(-5.0f, 6.0f);
            triangleBodyDef.fixedRotation = true; // look at me!

            b2Body body2 = m_world.CreateBody(triangleBodyDef);
            body2.CreateFixture(triangleShapeDef);

            {
                b2BodyDef bd  = new b2BodyDef();
                bd.type = b2BodyType.b2_dynamicBody;
                bd.position.Set(-5.0f, 10.0f);
                b2Body body = m_world.CreateBody(bd);

                b2PolygonShape p = new b2PolygonShape();
                p.SetAsBox(0.5f, 1.0f);
                body.CreateFixture(p, 1.0f);

                b2PrismaticJointDef jd = new b2PrismaticJointDef();
                jd.BodyA = body2;
                jd.BodyB = body;
                jd.enableLimit = true;
                jd.localAnchorA.Set(0.0f, 4.0f);
                jd.localAnchorB.SetZero();
                jd.localAxisA.Set(0.0f, 1.0f);
                jd.lowerTranslation = -1.0f;
                jd.upperTranslation = 1.0f;

                m_world.CreateJoint(jd);
            }

            // Small box
            polygon.SetAsBox(1.0f, 0.5f);
            b2FixtureDef boxShapeDef = new b2FixtureDef();
            boxShapeDef.shape = polygon;
            boxShapeDef.density = 1.0f;
            boxShapeDef.restitution = 0.1f;

            boxShapeDef.filter.groupIndex = k_smallGroup;
            boxShapeDef.filter.categoryBits = k_boxCategory;
            boxShapeDef.filter.maskBits = k_boxMask;

            b2BodyDef boxBodyDef  = new b2BodyDef();
            boxBodyDef.type = b2BodyType.b2_dynamicBody;
            boxBodyDef.position.Set(0.0f, 2.0f);

            b2Body body3 = m_world.CreateBody(boxBodyDef);
            body3.CreateFixture(boxShapeDef);

            // Large box (recycle definitions)
            polygon.SetAsBox(2.0f, 1.0f);
            boxShapeDef.filter.groupIndex = k_largeGroup;
            boxBodyDef.position.Set(0.0f, 6.0f);

            b2Body body4 = m_world.CreateBody(boxBodyDef);
            body4.CreateFixture(boxShapeDef);

//.........这里部分代码省略.........
开发者ID:h7ing,项目名称:CocosSharp,代码行数:101,代码来源:CollisionFiltering.cs

示例12: Cantilever

        public Cantilever()
        {
            b2Body ground = null;
            {
                b2BodyDef bd  = new b2BodyDef();
                ground = m_world.CreateBody(bd);

                b2EdgeShape shape = new b2EdgeShape();
                shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));
                ground.CreateFixture(shape, 0.0f);
            }

            {
                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(0.5f, 0.125f);

                b2FixtureDef fd = new b2FixtureDef();
                fd.shape = shape;
                fd.density = 20.0f;

                b2WeldJointDef jd = new b2WeldJointDef();

                b2Body prevBody = ground;
                for (int i = 0; i < e_count; ++i)
                {
                    b2BodyDef bd  = new b2BodyDef();
                    bd.type = b2BodyType.b2_dynamicBody;
                    bd.position.Set(-14.5f + 1.0f * i, 5.0f);
                    b2Body body = m_world.CreateBody(bd);
                    body.CreateFixture(fd);

                    b2Vec2 anchor = new b2Vec2(-15.0f + 1.0f * i, 5.0f);
                    jd.Initialize(prevBody, body, anchor);
                    m_world.CreateJoint(jd);

                    prevBody = body;
                }
            }

            {
                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(1.0f, 0.125f);

                b2FixtureDef fd = new b2FixtureDef();
                fd.shape = shape;
                fd.density = 20.0f;

                b2WeldJointDef jd = new b2WeldJointDef();
                jd.frequencyHz = 5.0f;
                jd.dampingRatio = 0.7f;

                b2Body prevBody = ground;
                for (int i = 0; i < 3; ++i)
                {
                    b2BodyDef bd  = new b2BodyDef();
                    bd.type = b2BodyType.b2_dynamicBody;
                    bd.position.Set(-14.0f + 2.0f * i, 15.0f);
                    b2Body body = m_world.CreateBody(bd);
                    body.CreateFixture(fd);

                    b2Vec2 anchor = new b2Vec2(-15.0f + 2.0f * i, 15.0f);
                    jd.Initialize(prevBody, body, anchor);
                    m_world.CreateJoint(jd);

                    prevBody = body;
                }
            }

            {
                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(0.5f, 0.125f);

                b2FixtureDef fd = new b2FixtureDef();
                fd.shape = shape;
                fd.density = 20.0f;

                b2WeldJointDef jd = new b2WeldJointDef();

                b2Body prevBody = ground;
                for (int i = 0; i < e_count; ++i)
                {
                    b2BodyDef bd  = new b2BodyDef();
                    bd.type = b2BodyType.b2_dynamicBody;
                    bd.position.Set(-4.5f + 1.0f * i, 5.0f);
                    b2Body body = m_world.CreateBody(bd);
                    body.CreateFixture(fd);

                    if (i > 0)
                    {
                        b2Vec2 anchor = new b2Vec2(-5.0f + 1.0f * i, 5.0f);
                        jd.Initialize(prevBody, body, anchor);
                        m_world.CreateJoint(jd);
                    }

                    prevBody = body;
                }
            }

            {
                b2PolygonShape shape = new b2PolygonShape();
//.........这里部分代码省略.........
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:101,代码来源:Cantilever.cs

示例13: j2b2Fixture


//.........这里部分代码省略.........

                if (edgeShape.HasVertex0)
                    edgeShape.Vertex0 = jsonToVec("vertex0", edgeValue);
                if (edgeShape.HasVertex3)
                    edgeShape.Vertex3 = jsonToVec("vertex3", edgeValue);
                fixtureDef.shape = edgeShape;

                fixture = body.CreateFixture(fixtureDef);
            }
            else if (null != fixtureValue["loop"])
            {// support old
                // format (r197)

                JObject chainValue = (JObject)fixtureValue["loop"];
                b2ChainShape chainShape = new b2ChainShape();

                int numVertices = ((JArray)chainValue["x"]).Count;

                b2Vec2[] vertices = new b2Vec2[numVertices];
                for (int i = 0; i < numVertices; i++)
                    vertices[i] = jsonToVec("vertices", chainValue, i);

                chainShape.CreateLoop(vertices, numVertices);

                fixtureDef.shape = chainShape;
                fixture = body.CreateFixture(fixtureDef);

            }
            else if (null != fixtureValue["chain"])
            {

                // FPE. See http://www.box2d.org/forum/viewtopic.php?f=4&t=7973&p=35363

                JObject chainValue = (JObject)fixtureValue["chain"];
                b2ChainShape chainShape = new b2ChainShape();
                int numVertices = ((JArray)chainValue["vertices"]["x"]).Count;
                var vertices = new b2Vec2[numVertices];

                for (int i = 0; i < numVertices; i++)
                    vertices[i] = jsonToVec("vertices", chainValue, i);

                chainShape.CreateChain(vertices, numVertices);
                chainShape.HasPrevVertex = chainValue["hasPrevVertex"] == null ? false : (bool)chainValue["hasPrevVertex"];
                chainShape.HasNextVertex = chainValue["hasNextVertex"] == null ? false : (bool)chainValue["hasNextVertex"];

                if (chainShape.HasPrevVertex)
                    chainShape.PrevVertex = (jsonToVec("prevVertex", chainValue));
                if (chainShape.HasNextVertex)
                    chainShape.NextVertex = (jsonToVec("nextVertex", chainValue));

                fixtureDef.shape = chainShape;
                fixture = body.CreateFixture(fixtureDef);

            }
            else if (null != fixtureValue["polygon"])
            {

                JObject polygonValue = (JObject)fixtureValue["polygon"];
                b2Vec2[] vertices = new b2Vec2[b2Settings.b2_maxPolygonVertices];

                int numVertices = ((JArray)polygonValue["vertices"]["x"]).Count;
                if (numVertices > b2Settings.b2_maxPolygonVertices)
                {
                    Console.WriteLine("Ignoring polygon fixture with too many vertices.");
                }
                else if (numVertices < 2)
                {
                    Console.WriteLine("Ignoring polygon fixture less than two vertices.");
                }
                else if (numVertices == 2)
                {
                    Console.WriteLine("Creating edge shape instead of polygon with two vertices.");

                    b2EdgeShape edgeShape = new b2EdgeShape();
                    edgeShape.Vertex1 = jsonToVec("vertices", polygonValue, 0);
                    edgeShape.Vertex2 = jsonToVec("vertices", polygonValue, 1);
                    fixtureDef.shape = edgeShape;
                    fixture = body.CreateFixture(fixtureDef);

                }
                else
                {

                    b2PolygonShape polygonShape = new b2PolygonShape();
                    for (int i = 0; i < numVertices; i++)
                        vertices[i] = jsonToVec("vertices", polygonValue, i);
                    polygonShape.Set(vertices, numVertices);
                    fixtureDef.shape = polygonShape;
                    fixture = body.CreateFixture(fixtureDef);
                }
            }

            String fixtureName = fixtureValue["name"] == null ? "" : fixtureValue["name"].ToString();
            if (fixtureName != "")
            {
                SetFixtureName(fixture, fixtureName);
            }

            return fixture;
        }
开发者ID:netonjm,项目名称:RubeLoader,代码行数:101,代码来源:Nb2dJson.cs

示例14: CharacterCollision

        public CharacterCollision()
        {
            // Ground body
            {
                b2BodyDef bd  = new b2BodyDef();
                b2Body ground = m_world.CreateBody(bd);

                b2EdgeShape shape = new b2EdgeShape();
                shape.Set(new b2Vec2(-20.0f, 0.0f), new b2Vec2(20.0f, 0.0f));
                ground.CreateFixture(shape, 0.0f);
            }

            // Collinear edges with no adjacency information.
            // This shows the problematic case where a box shape can hit
            // an internal vertex.
            {
                b2BodyDef bd  = new b2BodyDef();
                b2Body ground = m_world.CreateBody(bd);

                b2EdgeShape shape = new b2EdgeShape();
                shape.Set(new b2Vec2(-8.0f, 1.0f), new b2Vec2(-6.0f, 1.0f));
                ground.CreateFixture(shape, 0.0f);
                shape.Set(new b2Vec2(-6.0f, 1.0f), new b2Vec2(-4.0f, 1.0f));
                ground.CreateFixture(shape, 0.0f);
                shape.Set(new b2Vec2(-4.0f, 1.0f), new b2Vec2(-2.0f, 1.0f));
                ground.CreateFixture(shape, 0.0f);
            }

            // Chain shape
            {
                b2BodyDef bd  = new b2BodyDef();
                bd.angle = 0.25f * b2Settings.b2_pi;
                b2Body ground = m_world.CreateBody(bd);

                b2Vec2[] vs = new b2Vec2[4];
                vs[0].Set(5.0f, 7.0f);
                vs[1].Set(6.0f, 8.0f);
                vs[2].Set(7.0f, 8.0f);
                vs[3].Set(8.0f, 7.0f);
                b2ChainShape shape = new b2ChainShape();
                shape.CreateChain(vs, 4);
                ground.CreateFixture(shape, 0.0f);
            }

            // Square tiles. This shows that adjacency shapes may
            // have non-smooth collision. There is no solution
            // to this problem.
            {
                b2BodyDef bd  = new b2BodyDef();
                b2Body ground = m_world.CreateBody(bd);

                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsBox(1.0f, 1.0f, new b2Vec2(4.0f, 3.0f), 0.0f);
                ground.CreateFixture(shape, 0.0f);
                shape.SetAsBox(1.0f, 1.0f, new b2Vec2(6.0f, 3.0f), 0.0f);
                ground.CreateFixture(shape, 0.0f);
                shape.SetAsBox(1.0f, 1.0f, new b2Vec2(8.0f, 3.0f), 0.0f);
                ground.CreateFixture(shape, 0.0f);
            }

            // Square made from an edge loop. Collision should be smooth.
            {
                b2BodyDef bd  = new b2BodyDef();
                b2Body ground = m_world.CreateBody(bd);

                b2Vec2[] vs = new b2Vec2[4];
                vs[0].Set(-1.0f, 3.0f);
                vs[1].Set(1.0f, 3.0f);
                vs[2].Set(1.0f, 5.0f);
                vs[3].Set(-1.0f, 5.0f);
                b2ChainShape shape = new b2ChainShape();
                shape.CreateLoop(vs, 4);
                ground.CreateFixture(shape, 0.0f);
            }

            // Edge loop. Collision should be smooth.
            {
                b2BodyDef bd  = new b2BodyDef();
                bd.position.Set(-10.0f, 4.0f);
                b2Body ground = m_world.CreateBody(bd);

                b2Vec2[] vs = new b2Vec2[10];
                vs[0].Set(0.0f, 0.0f);
                vs[1].Set(6.0f, 0.0f);
                vs[2].Set(6.0f, 2.0f);
                vs[3].Set(4.0f, 1.0f);
                vs[4].Set(2.0f, 2.0f);
                vs[5].Set(0.0f, 2.0f);
                vs[6].Set(-2.0f, 2.0f);
                vs[7].Set(-4.0f, 3.0f);
                vs[8].Set(-6.0f, 2.0f);
                vs[9].Set(-6.0f, 0.0f);
                b2ChainShape shape = new b2ChainShape();
                shape.CreateLoop(vs, 10);
                ground.CreateFixture(shape, 0.0f);
            }

            // Square character 1
            {
                b2BodyDef bd  = new b2BodyDef();
//.........这里部分代码省略.........
开发者ID:Karunp,项目名称:cocos2d-xna,代码行数:101,代码来源:CharacterCollision.cs

示例15: CollisionProcessing

        public CollisionProcessing()
        {
            // Ground body
            {
                b2EdgeShape shape = new b2EdgeShape();
                shape.Set(new b2Vec2(-50.0f, 0.0f), new b2Vec2(50.0f, 0.0f));

                b2FixtureDef sd = new b2FixtureDef();
                sd.shape = shape;

                b2BodyDef bd  = new b2BodyDef();
                b2Body ground = m_world.CreateBody(bd);
                ground.CreateFixture(sd);
            }

            float xLo = -5.0f, xHi = 5.0f;
            float yLo = 2.0f, yHi = 35.0f;

            // Small triangle
            b2Vec2[] vertices = new b2Vec2[3];
            vertices[0].Set(-1.0f, 0.0f);
            vertices[1].Set(1.0f, 0.0f);
            vertices[2].Set(0.0f, 2.0f);

            b2PolygonShape polygon = new b2PolygonShape();
            polygon.Set(vertices, 3);

            b2FixtureDef triangleShapeDef = new b2FixtureDef();
            triangleShapeDef.shape = polygon;
            triangleShapeDef.density = 1.0f;

            b2BodyDef triangleBodyDef  = new b2BodyDef();
            triangleBodyDef.type = b2BodyType.b2_dynamicBody;
            triangleBodyDef.position.Set(Rand.RandomFloat(xLo, xHi), Rand.RandomFloat(yLo, yHi));

            b2Body body1 = m_world.CreateBody(triangleBodyDef);
            body1.CreateFixture(triangleShapeDef);

            // Large triangle (recycle definitions)
            vertices[0] *= 2.0f;
            vertices[1] *= 2.0f;
            vertices[2] *= 2.0f;
            polygon.Set(vertices, 3);

            triangleBodyDef.position.Set(Rand.RandomFloat(xLo, xHi), Rand.RandomFloat(yLo, yHi));

            b2Body body2 = m_world.CreateBody(triangleBodyDef);
            body2.CreateFixture(triangleShapeDef);

            // Small box
            polygon.SetAsBox(1.0f, 0.5f);

            b2FixtureDef boxShapeDef = new b2FixtureDef();
            boxShapeDef.shape = polygon;
            boxShapeDef.density = 1.0f;

            b2BodyDef boxBodyDef  = new b2BodyDef();
            boxBodyDef.type = b2BodyType.b2_dynamicBody;
            boxBodyDef.position.Set(Rand.RandomFloat(xLo, xHi), Rand.RandomFloat(yLo, yHi));

            b2Body body3 = m_world.CreateBody(boxBodyDef);
            body3.CreateFixture(boxShapeDef);

            // Large box (recycle definitions)
            polygon.SetAsBox(2.0f, 1.0f);
            boxBodyDef.position.Set(Rand.RandomFloat(xLo, xHi), Rand.RandomFloat(yLo, yHi));

            b2Body body4 = m_world.CreateBody(boxBodyDef);
            body4.CreateFixture(boxShapeDef);

            // Small circle
            b2CircleShape circle = new b2CircleShape();
            circle.Radius = 1.0f;

            b2FixtureDef circleShapeDef = new b2FixtureDef();
            circleShapeDef.shape = circle;
            circleShapeDef.density = 1.0f;

            b2BodyDef circleBodyDef  = new b2BodyDef();
            circleBodyDef.type = b2BodyType.b2_dynamicBody;
            circleBodyDef.position.Set(Rand.RandomFloat(xLo, xHi), Rand.RandomFloat(yLo, yHi));

            b2Body body5 = m_world.CreateBody(circleBodyDef);
            body5.CreateFixture(circleShapeDef);

            // Large circle
            circle.Radius *= 2.0f;
            circleBodyDef.position.Set(Rand.RandomFloat(xLo, xHi), Rand.RandomFloat(yLo, yHi));

            b2Body body6 = m_world.CreateBody(circleBodyDef);
            body6.CreateFixture(circleShapeDef);
        }
开发者ID:p07r0457,项目名称:cocos2d-xna,代码行数:92,代码来源:CollisionProcessing.cs


注:本文中的Box2D.Collision.Shapes.b2PolygonShape.Set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。