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


C# CCVector2.LengthSquared方法代码示例

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


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

示例1: ComputeBevel

        //internal InsetOutsetCount ComputeBevel (CCVector2 a, CCVector2 b, CCVector2 c, PenWorkspace ws)
        internal InsetOutsetCount ComputeBevel (ref JoinSample js, PenWorkspace ws)
        {
            CCVector2 a = js.PointA;
            CCVector2 b = js.PointB;
            CCVector2 c = js.PointC;

            CCVector2 edgeBA = new CCVector2(a.X - b.X, a.Y - b.Y);
            CCVector2 edgeBC = new CCVector2(c.X - b.X, c.Y - b.Y);
            double dot = CCVector2.Dot(edgeBA, edgeBC);
            if (dot < 0) {
                double den = edgeBA.LengthSquared() * edgeBC.LengthSquared();
                double cos2 = (dot * dot) / den;

                if (cos2 > _joinLimitCos2)
                    return ComputeMiter(ref js, ws);
            }

            CCVector2 edgeAB = new CCVector2(b.X - a.X, b.Y - a.Y);
            edgeAB.Normalize();
            CCVector2 edgeABt = new CCVector2(-edgeAB.Y, edgeAB.X);

            edgeBC.Normalize();
            CCVector2 edgeBCt = new CCVector2(-edgeBC.Y, edgeBC.X);

            CCVector2 pointA = a;
            CCVector2 pointC = c;

            short vertexCount = 0;

            if (Cross2D(edgeAB, edgeBC) > 0) {
                switch (Alignment) {
                    case PenAlignment.Center:
                        float w2 = Width / 2;
                        pointA = new CCVector2(a.X - w2 * edgeABt.X, a.Y - w2 * edgeABt.Y);
                        pointC = new CCVector2(c.X - w2 * edgeBCt.X, c.Y - w2 * edgeBCt.Y);

                        ws.XYInsetBuffer[0] = new CCVector2(b.X + w2 * edgeABt.X, b.Y + w2 * edgeABt.Y);
                        ws.XYInsetBuffer[1] = new CCVector2(b.X + w2 * edgeBCt.X, b.Y + w2 * edgeBCt.Y);

                        vertexCount = 2;
                        break;

                    case PenAlignment.Inset:
                        ws.XYInsetBuffer[0] = new CCVector2(b.X + Width * edgeABt.X, b.Y + Width * edgeABt.Y);
                        ws.XYInsetBuffer[1] = new CCVector2(b.X + Width * edgeBCt.X, b.Y + Width * edgeBCt.Y);

                        vertexCount = 2;
                        break;

                    case PenAlignment.Outset:
                        pointA = new CCVector2(a.X - Width * edgeABt.X, a.Y - Width * edgeABt.Y);
                        pointC = new CCVector2(c.X - Width * edgeBCt.X, c.Y - Width * edgeBCt.Y);

                        ws.XYInsetBuffer[0] = b;

                        vertexCount = 1;
                        break;
                }

                CCVector2 point5;

                float tdiv = CCVector2.Dot(edgeBCt, edgeAB);
                if (Math.Abs(tdiv) < 0.0005f) {
                    point5 = new CCVector2((pointA.X + pointC.X) / 2, (pointA.Y + pointC.Y) / 2);
                }
                else {
                    float offset35 = CCVector2.Dot(edgeBCt, pointC);
                    float t5 = (offset35 - CCVector2.Dot(edgeBCt, pointA)) / tdiv;

                    point5 = new CCVector2(pointA.X + t5 * edgeAB.X, pointA.Y + t5 * edgeAB.Y);
                }

                ws.XYOutsetBuffer[0] = point5;

                ws.UVOutsetBuffer[0] = new CCVector2(1, js.LengthB);
                for (int i = 0; i < vertexCount; i++)
                    ws.UVInsetBuffer[i] = new CCVector2(0, js.LengthB);

                return new InsetOutsetCount(vertexCount, 1, false);
            }
            else {
                switch (Alignment) {
                    case PenAlignment.Center:
                        float w2 = Width / 2;
                        pointA = new CCVector2(a.X + w2 * edgeABt.X, a.Y + w2 * edgeABt.Y);
                        pointC = new CCVector2(c.X + w2 * edgeBCt.X, c.Y + w2 * edgeBCt.Y);

                        ws.XYOutsetBuffer[0] = new CCVector2(b.X - w2 * edgeABt.X, b.Y - w2 * edgeABt.Y);
                        ws.XYOutsetBuffer[1] = new CCVector2(b.X - w2 * edgeBCt.X, b.Y - w2 * edgeBCt.Y);

                        vertexCount = 2;
                        break;

                    case PenAlignment.Inset:
                        pointA = new CCVector2(a.X + Width * edgeABt.X, a.Y + Width * edgeABt.Y);
                        pointC = new CCVector2(c.X + Width * edgeBCt.X, c.Y + Width * edgeBCt.Y);

                        ws.XYOutsetBuffer[0] = b;

//.........这里部分代码省略.........
开发者ID:460189852,项目名称:cocos-sharp-samples,代码行数:101,代码来源:Pen.cs


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