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


C# SPoint.GetNormal方法代码示例

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


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

示例1: CheckAxis

    public bool CheckAxis( SPoint origin, float dir, SPoint[] plBox, SPoint[] aBox, int pNum, int aNum)
    {
        // helper function for the Separating Axis Theorem that takes an axis defined by origin and dir
        //re-conditioned to handle the parameters of the attack box
        bool isHit = true;
        float projMin, projMax, hitMin, hitMax, distSq, projVal, cVal;
        SPoint projVec, nVec, rVec, cVec;
        projVec = new SPoint();
        projMin = AXIS_LIMIT;
        projMax = -AXIS_LIMIT;
        hitMin = AXIS_LIMIT;
        hitMax = -AXIS_LIMIT;
        for(int i = 0; i < aNum; i++){
            projVec.x = aBox[i].x - origin.x;
            projVec.y = aBox[i].y - origin.y;

            distSq = projVec.x*projVec.x + projVec.y*projVec.y;
            nVec=projVec.GetNormal();

            cVec = new SPoint(Mathf.Cos(dir+Mathf.PI/2),Mathf.Sin(dir+Mathf.PI/2));

            cVal = -cVec.Dot(nVec);
            //projVal = sin(rAng)*abs(sin(rAng))*distSq;
            projVal = cVal*Mathf.Abs(cVal)*distSq;

            if(projVal < projMin)
                projMin = projVal;
            if(projVal > projMax)
                projMax = projVal;
        }
        for(int i = 0; i < pNum; i++){
            projVec.x = plBox[i].x - origin.x;
            projVec.y = plBox[i].y - origin.y;
            distSq = projVec.x*projVec.x + projVec.y*projVec.y;
            cVec = new SPoint(Mathf.Cos(dir+Mathf.PI/2),Mathf.Sin(dir+Mathf.PI/2));
            nVec = projVec.GetNormal();
            cVal = -cVec.Dot(nVec);
            //projVal = sin(rAng)*abs(sin(rAng))*distSq;
            projVal = cVal*Mathf.Abs(cVal)*distSq;
            if(projVal < hitMin)
                hitMin = projVal;
            if(projVal > hitMax)
                hitMax = projVal;
        }
        if((hitMax <= projMin)||(projMax <= hitMin))
            isHit=false;
        if((Mathf.Abs(projMax - hitMin)< EPS)||(Mathf.Abs(hitMax - projMin)< EPS))
            isHit=false;
        return isHit;
    }
开发者ID:cWalters2,项目名称:ShSoul,代码行数:50,代码来源:Fighter.cs

示例2: CheckAxis

    public bool CheckAxis(SPoint origin, float dir, SPoint pCen, SPoint[] aBox, int aNum)
    {
        // helper function for the Separating Axis Theorem that takes an axis defined by origin and dir
        //re-conditioned to handle the parameters of the attack box
        bool isHit = true;
        float projMin, projMax, hitMin, hitMax, distSq, projVal, cVal;
        SPoint projVec, nVec, rVec, cVec;
        projVec = new SPoint();
        projMin = 100;
        projMax = -100;
        hitMin = 100;
        hitMax = -100;
          int   pNum = 1;//remove from param list!
        for (int i = 0; i < aNum; i++)
        {
            projVec.x = aBox[i].x - origin.x;
            projVec.y = aBox[i].y - origin.y;

            distSq = projVec.x * projVec.x + projVec.y * projVec.y;
            nVec = projVec.GetNormal();

            cVec = new SPoint(Mathf.Cos(dir + Mathf.PI / 2), Mathf.Sin(dir + Mathf.PI / 2));

            cVal = -cVec.Dot(nVec);
            //projVal = sin(rAng)*abs(sin(rAng))*distSq;
            projVal = cVal * Mathf.Abs(cVal) * distSq;

            if (projVal < projMin)
                projMin = projVal;
            if (projVal > projMax)
                projMax = projVal;
        }
        float eps = 0.00001f;

            projVec.x = pCen.x - origin.x;
            projVec.y = pCen.y - origin.y;
            distSq = projVec.x * projVec.x + projVec.y * projVec.y;
            cVec = new SPoint(Mathf.Cos(dir + Mathf.PI / 2), Mathf.Sin(dir + Mathf.PI / 2));
            nVec = projVec.GetNormal();
            cVal = -cVec.Dot(nVec);
            //projVal = sin(rAng)*abs(sin(rAng))*distSq;
            projVal = cVal * Mathf.Abs(cVal) * distSq;
            if (projVal < hitMin)
                hitMin = projVal;
            if (projVal > hitMax)
                hitMax = projVal;

        if ((projVal >= projMin) && (projVal <= projMax))
            isHit = true;
        else
            isHit = false;
        return isHit;
    }
开发者ID:cWalters2,项目名称:NeonNinja,代码行数:53,代码来源:Projectile.cs

示例3: ExitDistN

    public SPoint ExitDistN(int iInd, SPoint origin, float dir, Ninja plr, int ifGrab)
    {
        // helper function for the Separating Axis Theorem that takes an axis defined by origin and dir
        //re-conditioned to handle the parameters of the attack box
        bool isHit = true;
        float projMin, projMax, hitMin, hitMax, distSq, projVal, cVal;
        float dHitMinSq = 1000;
        float dHitMaxSq = 0;
        float dPrMinSq = 1000;
        float dPrMaxSq = 0;
        SPoint projVec, nVec, rVec, cVec;
        projVec = new SPoint();
        SPoint moveVec = new SPoint();
        projMin = STAGE_LIMIT;
        projMax = -STAGE_LIMIT;
        hitMin = STAGE_LIMIT;
        hitMax = -STAGE_LIMIT;
        moveVec.x = plr.GetPos().x - plr.GetLastPos().x;
        moveVec.y = plr.GetPos().y - plr.GetLastPos().y;
        SPoint[] plBox;
        int hbLen = 4;
        if (ifGrab < 0)
        {//implies groundCheck
            plBox = plr.GetHitBox();
            hbLen = 4;
        }
        else
        {
            plBox = plr.GetCurrentColBox();
            hbLen = 6;
        }

        for (int i = 0; i < tBox.GetJlength(iInd); i++)
        {
            projVec.x = tBox.GetSPoint(iInd, i).x - origin.x;
            projVec.y = tBox.GetSPoint(iInd, i).y - origin.y;

            distSq = projVec.x * projVec.x + projVec.y * projVec.y;
            nVec = projVec.GetNormal();

            cVec = new SPoint(Mathf.Cos(dir + Mathf.PI / 2), Mathf.Sin(dir + Mathf.PI / 2));

            cVal = -cVec.Dot(nVec);
            //projVal = sin(rAng)*abs(sin(rAng))*distSq;
            projVal = cVal * Mathf.Abs(cVal) * distSq;

            if (projVal < projMin){
                projMin = projVal;
                dPrMinSq = distSq;
            }
            if (projVal > projMax) {
                projMax = projVal;
                dPrMaxSq = distSq;
            }
        }
        if (dPrMinSq != 0)
            projMin = projMin / Mathf.Sqrt(dPrMinSq);
        if (dPrMaxSq != 0)
            projMax = projMax / Mathf.Sqrt(dPrMaxSq);
        if (dHitMinSq != 0)
            hitMin = hitMin / Mathf.Sqrt(dHitMinSq);
        if (dHitMaxSq != 0)
            hitMax = hitMax / Mathf.Sqrt(dHitMaxSq);
        for (int i = 0; i < hbLen; i++)
        {
            projVec.x = plBox[i].x - origin.x;
            projVec.y = plBox[i].y - origin.y;
            distSq = projVec.x * projVec.x + projVec.y * projVec.y;
            cVec = new SPoint(Mathf.Cos(dir + Mathf.PI / 2), Mathf.Sin(dir + Mathf.PI / 2));
            nVec = projVec.GetNormal();
            cVal = -cVec.Dot(nVec);
            //projVal = sin(rAng)*abs(sin(rAng))*distSq;
            projVal = cVal * Mathf.Abs(cVal) * distSq;
            if (projVal < hitMin){
                hitMin = projVal;
                dHitMinSq = distSq;
            }if (projVal > hitMax){
                hitMax = projVal;
                dHitMaxSq = distSq;
            }
        }
        if ((hitMax <= projMin) || (projMax <= hitMin))
            isHit = false;
        if ((Mathf.Abs(projMax - hitMin) < EPS) || (Mathf.Abs(hitMax - projMin) < EPS))
            isHit = false;

        //determine exit vector here
        float moveAng = Mathf.Atan2(moveVec.y, moveVec.x);
        float angDiff = Mathf.Abs(moveAng - (dir - Mathf.PI/2)) ;
        if(angDiff > Mathf.PI)
            angDiff = Mathf.Abs(angDiff - Mathf.PI*2);
        float moveDist=0;
        if(isHit){
            if(angDiff < Mathf.PI/2) //moveVector in direction of exit vector
                moveDist = -Mathf.Abs(hitMax - projMin)/2;
            else
                moveDist = Mathf.Abs(projMax - hitMin)/2;
        }
        moveVec.x = moveDist*Mathf.Cos(dir - Mathf.PI/2);
        moveVec.y = moveDist*Mathf.Sin(dir - Mathf.PI/2);
//.........这里部分代码省略.........
开发者ID:cWalters2,项目名称:NeonNinja,代码行数:101,代码来源:Stage.cs

示例4: Fire

    public virtual bool Fire(SPoint o, SPoint s)
    {
        //dir is the vector to travel in per second
        transform.position = new Vector3(o.x, o.y+1, 0);
        pos=o;

        vel = new SPoint(-s.GetNormal().x * speed, s.GetNormal().y * speed);

        //ttl.SetTimer(2);

        return true;
    }
开发者ID:cWalters2,项目名称:NeonNinja,代码行数:12,代码来源:Projectile.cs


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