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


C# Vec2.normalize方法代码示例

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


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

示例1: initTest

        public override void initTest(bool deserialized)
        {
            if (deserialized)
            {
                return;
            }
            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(2.0f, 0.5f);

                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                bd.position.set(-10.0f, 10.0f);
                bd.angle = 0.5f*MathUtils.PI;
                bd.allowSleep = false;
                Body body = getWorld().createBody(bd);
                body.createFixture(shape, 5.0f);

                PrismaticJointDef pjd = new PrismaticJointDef();

                // Bouncy limit
                Vec2 axis = new Vec2(2.0f, 1.0f);
                axis.normalize();
                pjd.initialize(ground, body, new Vec2(0.0f, 0.0f), axis);

                // Non-bouncy limit
                // pjd.Initialize(ground, body, Vec2(-10.0f, 10.0f), Vec2(1.0f, 0.0f));

                pjd.motorSpeed = 10.0f;
                pjd.maxMotorForce = 10000.0f;
                pjd.enableMotor = true;
                pjd.lowerTranslation = 0.0f;
                pjd.upperTranslation = 20.0f;
                pjd.enableLimit = true;

                m_joint = (PrismaticJoint) getWorld().createJoint(pjd);
            }
        }
开发者ID:Nomad1,项目名称:sharpbox2d,代码行数:48,代码来源:PrismaticTest.cs

示例2: op

 public float op(Vec2 argVec)
 {
     argVec.set(MathUtils.randomFloat(-100, 100), MathUtils.randomFloat(-100, 100));
     argVec.mulLocal(3.2f);
     float s = argVec.length();
     argVec.normalize();
     return s;
 }
开发者ID:Nomad1,项目名称:sharpbox2d,代码行数:8,代码来源:StackTest.cs

示例3: PrismaticJoint

        internal PrismaticJoint(IWorldPool argWorld, PrismaticJointDef def)
            : base(argWorld, def)
        {
            m_localAnchorA = new Vec2(def.localAnchorA);
            m_localAnchorB = new Vec2(def.localAnchorB);
            m_localXAxisA = new Vec2(def.localAxisA);
            m_localXAxisA.normalize();
            m_localYAxisA = new Vec2();
            Vec2.crossToOutUnsafe(1f, m_localXAxisA, ref m_localYAxisA);
            m_referenceAngle = def.referenceAngle;

            m_impulse = new Vec3();
            m_motorMass = 0.0f;
            m_motorImpulse = 0.0f;

            m_lowerTranslation = def.lowerTranslation;
            m_upperTranslation = def.upperTranslation;
            m_maxMotorForce = def.maxMotorForce;
            m_motorSpeed = def.motorSpeed;
            m_enableLimit = def.enableLimit;
            m_enableMotor = def.enableMotor;
            m_limitState = LimitState.INACTIVE;

            m_K = new Mat33();
            m_axis = new Vec2();
            m_perp = new Vec2();
        }
开发者ID:Nomad1,项目名称:sharpbox2d,代码行数:27,代码来源:PrismaticJoint.cs

示例4: computeDistanceToOut

        public override float computeDistanceToOut(Transform xf, Vec2 p, int childIndex, Vec2 normalOut)
        {
            float xfqc = xf.q.c;
            float xfqs = xf.q.s;
            float tx = p.x - xf.p.x;
            float ty = p.y - xf.p.y;
            float pLocalx = xfqc*tx + xfqs*ty;
            float pLocaly = -xfqs*tx + xfqc*ty;

            float maxDistance = float.MinValue;
            float normalForMaxDistanceX = pLocalx;
            float normalForMaxDistanceY = pLocaly;

            for (int i = 0; i < m_count; ++i)
            {
                Vec2 vertex = m_vertices[i];
                Vec2 normal = m_normals[i];
                tx = pLocalx - vertex.x;
                ty = pLocaly - vertex.y;
                float dot = normal.x*tx + normal.y*ty;
                if (dot > maxDistance)
                {
                    maxDistance = dot;
                    normalForMaxDistanceX = normal.x;
                    normalForMaxDistanceY = normal.y;
                }
            }

            float distance;
            if (maxDistance > 0)
            {
                float minDistanceX = normalForMaxDistanceX;
                float minDistanceY = normalForMaxDistanceY;
                float minDistance2 = maxDistance*maxDistance;
                for (int i = 0; i < m_count; ++i)
                {
                    Vec2 vertex = m_vertices[i];
                    float distanceVecX = pLocalx - vertex.x;
                    float distanceVecY = pLocaly - vertex.y;
                    float distance2 = (distanceVecX*distanceVecX + distanceVecY*distanceVecY);
                    if (minDistance2 > distance2)
                    {
                        minDistanceX = distanceVecX;
                        minDistanceY = distanceVecY;
                        minDistance2 = distance2;
                    }
                }
                distance = MathUtils.sqrt(minDistance2);
                normalOut.x = xfqc*minDistanceX - xfqs*minDistanceY;
                normalOut.y = xfqs*minDistanceX + xfqc*minDistanceY;
                normalOut.normalize();
            }
            else
            {
                distance = maxDistance;
                normalOut.x = xfqc*normalForMaxDistanceX - xfqs*normalForMaxDistanceY;
                normalOut.y = xfqs*normalForMaxDistanceX + xfqc*normalForMaxDistanceY;
            }

            return distance;
        }
开发者ID:Nomad1,项目名称:sharpbox2d,代码行数:61,代码来源:PolygonShape.cs


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