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


C# Vec2.sub方法代码示例

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


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

示例1: initialize

 /**
    * Initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors.
    */
 public void initialize(Body b1, Body b2, Vec2 ga1, Vec2 ga2, Vec2 anchor1, Vec2 anchor2, float r)
 {
     bodyA = b1;
     bodyB = b2;
     groundAnchorA = ga1;
     groundAnchorB = ga2;
     localAnchorA = bodyA.getLocalPoint(anchor1);
     localAnchorB = bodyB.getLocalPoint(anchor2);
     Vec2 d1 = anchor1.sub(ga1);
     lengthA = d1.length();
     Vec2 d2 = anchor2.sub(ga2);
     lengthB = d2.length();
     ratio = r;
     Debug.Assert(ratio > Settings.EPSILON);
 }
开发者ID:Nomad1,项目名称:sharpbox2d,代码行数:18,代码来源:PulleyJointDef.cs

示例2: initTest

        public override void initTest(bool argDeserialized)
        {
            Body ground = null;
            {
                BodyDef bd = new BodyDef();
                ground = getWorld().createBody(bd);

                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
                ground.createFixture(shape, 0.0f);
            }

            {
                PolygonShape shape = new PolygonShape();
                shape.setAsBox(0.5f, 0.5f);

                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;

                bd.position.set(-5.0f, 5.0f);
                m_bodies[0] = getWorld().createBody(bd);
                m_bodies[0].createFixture(shape, 5.0f);

                bd.position.set(5.0f, 5.0f);
                m_bodies[1] = getWorld().createBody(bd);
                m_bodies[1].createFixture(shape, 5.0f);

                bd.position.set(5.0f, 15.0f);
                m_bodies[2] = getWorld().createBody(bd);
                m_bodies[2].createFixture(shape, 5.0f);

                bd.position.set(-5.0f, 15.0f);
                m_bodies[3] = getWorld().createBody(bd);
                m_bodies[3].createFixture(shape, 5.0f);

                DistanceJointDef jd = new DistanceJointDef();
                Vec2 p1 = new Vec2();
                Vec2 p2 = new Vec2();
                Vec2 d = new Vec2();

                jd.frequencyHz = 4.0f;
                jd.dampingRatio = 0.5f;

                jd.bodyA = ground;
                jd.bodyB = m_bodies[0];
                jd.localAnchorA.set(-10.0f, 0.0f);
                jd.localAnchorB.set(-0.5f, -0.5f);
                p1 = jd.bodyA.getWorldPoint(jd.localAnchorA);
                p2 = jd.bodyB.getWorldPoint(jd.localAnchorB);
                d = p2.sub(p1);
                jd.length = d.length();
                m_joints[0] = getWorld().createJoint(jd);

                jd.bodyA = ground;
                jd.bodyB = m_bodies[1];
                jd.localAnchorA.set(10.0f, 0.0f);
                jd.localAnchorB.set(0.5f, -0.5f);
                p1 = jd.bodyA.getWorldPoint(jd.localAnchorA);
                p2 = jd.bodyB.getWorldPoint(jd.localAnchorB);
                d = p2.sub(p1);
                jd.length = d.length();
                m_joints[1] = getWorld().createJoint(jd);

                jd.bodyA = ground;
                jd.bodyB = m_bodies[2];
                jd.localAnchorA.set(10.0f, 20.0f);
                jd.localAnchorB.set(0.5f, 0.5f);
                p1 = jd.bodyA.getWorldPoint(jd.localAnchorA);
                p2 = jd.bodyB.getWorldPoint(jd.localAnchorB);
                d = p2.sub(p1);
                jd.length = d.length();
                m_joints[2] = getWorld().createJoint(jd);

                jd.bodyA = ground;
                jd.bodyB = m_bodies[3];
                jd.localAnchorA.set(-10.0f, 20.0f);
                jd.localAnchorB.set(-0.5f, 0.5f);
                p1 = jd.bodyA.getWorldPoint(jd.localAnchorA);
                p2 = jd.bodyB.getWorldPoint(jd.localAnchorB);
                d = p2.sub(p1);
                jd.length = d.length();
                m_joints[3] = getWorld().createJoint(jd);

                jd.bodyA = m_bodies[0];
                jd.bodyB = m_bodies[1];
                jd.localAnchorA.set(0.5f, 0.0f);
                jd.localAnchorB.set(-0.5f, 0.0f);
                ;
                p1 = jd.bodyA.getWorldPoint(jd.localAnchorA);
                p2 = jd.bodyB.getWorldPoint(jd.localAnchorB);
                d = p2.sub(p1);
                jd.length = d.length();
                m_joints[4] = getWorld().createJoint(jd);

                jd.bodyA = m_bodies[1];
                jd.bodyB = m_bodies[2];
                jd.localAnchorA.set(0.0f, 0.5f);
                jd.localAnchorB.set(0.0f, -0.5f);
                p1 = jd.bodyA.getWorldPoint(jd.localAnchorA);
                p2 = jd.bodyB.getWorldPoint(jd.localAnchorB);
//.........这里部分代码省略.........
开发者ID:Nomad1,项目名称:sharpbox2d,代码行数:101,代码来源:Web.cs

示例3: createLeg

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

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

            PolygonShape poly1 = new PolygonShape();
            PolygonShape poly2 = new PolygonShape();

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

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

                vertices[0] = new Vec2();
                vertices[1] = p5.sub(p4);
                vertices[2] = p6.sub(p4);
                poly2.set(vertices, 3);
            }
            else
            {
                Vec2[] vertices = new Vec2[3];

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

                vertices[0] = new Vec2();
                vertices[1] = p6.sub(p4);
                vertices[2] = p5.sub(p4);
                poly2.set(vertices, 3);
            }

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

            BodyDef bd1 = new BodyDef(), bd2 = new BodyDef();
            bd1.type = BodyType.DYNAMIC;
            bd2.type = BodyType.DYNAMIC;
            bd1.position = m_offset;
            bd2.position = p4.add(m_offset);

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

            Body body1 = getWorld().createBody(bd1);
            Body body2 = getWorld().createBody(bd2);

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

            DistanceJointDef djd = new DistanceJointDef();

            // 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.add(m_offset), p5.add(m_offset));
            getWorld().createJoint(djd);

            djd.initialize(body1, body2, p3.add(m_offset), p4.add(m_offset));
            getWorld().createJoint(djd);

            djd.initialize(body1, m_wheel, p3.add(m_offset), wheelAnchor.add(m_offset));
            getWorld().createJoint(djd);

            djd.initialize(body2, m_wheel, p6.add(m_offset), wheelAnchor.add(m_offset));
            getWorld().createJoint(djd);

            RevoluteJointDef rjd = new RevoluteJointDef();

            rjd.initialize(body2, m_chassis, p4.add(m_offset));
            getWorld().createJoint(rjd);
        }
开发者ID:Nomad1,项目名称:sharpbox2d,代码行数:91,代码来源:TheoJansen.cs

示例4: initialize

 /**
    * Initialize the bodies, anchors, and length using the world anchors.
    *
    * @param b1 First body
    * @param b2 Second body
    * @param anchor1 World anchor on first body
    * @param anchor2 World anchor on second body
    */
 public void initialize(Body b1, Body b2, Vec2 anchor1, Vec2 anchor2)
 {
     bodyA = b1;
     bodyB = b2;
     localAnchorA.set(bodyA.getLocalPoint(anchor1));
     localAnchorB.set(bodyB.getLocalPoint(anchor2));
     Vec2 d = anchor2.sub(anchor1);
     length = d.length();
 }
开发者ID:Nomad1,项目名称:sharpbox2d,代码行数:17,代码来源:DistanceJointDef.cs


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