• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Common.b2Transform类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Box2D.Common.b2Transform的典型用法代码示例。如果您正苦于以下问题:C# b2Transform类的具体用法?C# b2Transform怎么用?C# b2Transform使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



b2Transform类属于Box2D.Common命名空间,在下文中一共展示了b2Transform类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Create

 public static b2Transform Create()
 {
     var transform = new b2Transform();
     transform.p = b2Vec2.Zero;
     transform.q = b2Rot.Create();
     return transform;
 }
开发者ID:HarkDev,项目名称:cocos2d-xna,代码行数:7,代码来源:b2Transform.cs


示例2: Evaluate

 public override void Evaluate(ref b2Manifold manifold, ref b2Transform xfA, ref b2Transform xfB)
 {
     b2ChainShape chain = (b2ChainShape)m_fixtureA.Shape;
     b2EdgeShape edge;
     edge = chain.GetChildEdge(m_indexA);
     b2Collision.b2CollideEdgeAndCircle(ref manifold, edge, ref xfA,
                             (b2CircleShape)m_fixtureB.Shape, ref xfB);
 }
开发者ID:homocury,项目名称:cocos2d-xna,代码行数:8,代码来源:b2ChainAndCircleContact.cs


示例3: ComputeAABB

 public override b2AABB ComputeAABB(b2Transform transform, int childIndex)
 {
     b2Vec2 p = transform.p + b2Math.b2Mul(transform.q, m_p);
     b2AABB aabb = new b2AABB();
     aabb.lowerBound.Set(p.x - m_radius, p.y - m_radius);
     aabb.upperBound.Set(p.x + m_radius, p.y + m_radius);
     return (aabb);
 }
开发者ID:homocury,项目名称:cocos2d-xna,代码行数:8,代码来源:b2CircleShape.cs


示例4: b2Vec2

        /*public b2Sweep()
        {
            localCenter = new b2Vec2();
            c0 = new b2Vec2();
            c = new b2Vec2();
            a0 = 0f;
            a = 0f;
            alpha0 = 0f;
        }*/
        /// Get the interpolated transform at a specific time.
        /// @param beta is a factor in [0,1], where 0 indicates alpha0.
        public void GetTransform(b2Transform xfb, float beta)
        {
            xfb.p = (1.0f - beta) * c0 + beta * c;
            float angle = (1.0f - beta) * a0 + beta * a;
            xfb.q.Set(angle);

            // Shift to origin
            xfb.p -= b2Math.b2Mul(xfb.q, localCenter);
        }
开发者ID:Ratel13,项目名称:cocos2d-x-for-xna,代码行数:20,代码来源:b2Sweep.cs


示例5: TestPoint

        public override bool TestPoint(ref b2Transform transform, b2Vec2 p)
        {
            b2Vec2 tx = b2Math.b2Mul(ref transform.q, ref Position);
            b2Vec2 center;
            center.x = transform.p.x + tx.x;
            center.y = transform.p.y + tx.y;
//            b2Vec2 center = transform.p + tx;
            b2Vec2 d; // = p - center;
            d.x = p.x - center.x;
            d.y = p.y - center.y;
            return d.LengthSquared <= Radius * Radius;
        }
开发者ID:h7ing,项目名称:CocosSharp,代码行数:12,代码来源:b2CircleShape.cs


示例6: TestPoint

        public override bool TestPoint(b2Transform transform, b2Vec2 p)
        {
            b2Vec2 tx = b2Math.b2Mul(transform.q, m_p);
            b2Vec2 center;
            center.x = transform.p.x + tx.x;
            center.y = transform.p.y + tx.y;
//            b2Vec2 center = transform.p + tx;
            b2Vec2 d; // = p - center;
            d.x = p.x - center.x;
            d.y = p.y - center.y;
            return d.LengthSquared <= m_radius * m_radius;
        }
开发者ID:p07r0457,项目名称:cocos2d-xna,代码行数:12,代码来源:b2CircleShape.cs


示例7: DrawTransform

        public override void DrawTransform(b2Transform xf)
        {
            float axisScale = 0.4f;
            b2Vec2 p1 = xf.p;

            b2Vec2 col1 = new b2Vec2(xf.q.c, xf.q.s);
            b2Vec2 col2 = new b2Vec2(-xf.q.s, xf.q.c);

            b2Vec2 p2 = p1 + axisScale * col1;
            DrawSegment(p1, p2, new b2Color(1f, 0f, 0f));

            p2 = p1 + axisScale * col2; 
            DrawSegment(p1, p2, new b2Color(0f, 0f, 1f));
        }
开发者ID:CartBlanche,项目名称:cocos2d-xna,代码行数:14,代码来源:CCDraw.cs


示例8: RayCast

        // Collision Detection in Interactive 3D Environments by Gino van den Bergen
        // From Section 3.1.2
        // x = s + a * r
        // norm(x) = radius
        public override bool RayCast(out b2RayCastOutput output, b2RayCastInput input,
                                    b2Transform transform, int childIndex)
        {
            output = b2RayCastOutput.Zero;

            b2Vec2 tx = b2Math.b2Mul(transform.q, m_p);
//            b2Vec2 position = transform.p + tx;
            b2Vec2 position;
            position.x = transform.p.x + tx.x;
            position.y = transform.p.y + tx.y;
//            b2Vec2 s = input.p1 - position;
            b2Vec2 s;
            s.x = input.p1.x - position.x;
            s.y = input.p1.y - position.y;
            float b = s.LengthSquared - m_radius * m_radius;

            // Solve quadratic equation.
            b2Vec2 r;
            r.x = input.p2.x - input.p1.x;
            r.y = input.p2.y - input.p1.y;
//            b2Vec2 r = input.p2 - input.p1;
            float c = s.x * r.x + s.y * r.y; // b2Math.b2Dot(ref s, ref r);
            float rr = r.LengthSquared; //  b2Math.b2Dot(r, r);
            float sigma = c * c - rr * b;

            // Check for negative discriminant and short segment.
            if (sigma < 0.0f || rr < b2Settings.b2_epsilon)
            {
                return false;
            }

            // Find the point of intersection of the line with the circle.
            float a = -(c + b2Math.b2Sqrt(sigma));

            // Is the intersection point on the segment?
            if (0.0f <= a && a <= input.maxFraction * rr)
            {
                a /= rr;
                output.fraction = a;
                output.normal.x = s.x + a * r.x;
                output.normal.y = s.y + a * r.y;
//                output.normal = s + a * r;
                output.normal.Normalize();
                return true;
            }

            return false;
        }
开发者ID:p07r0457,项目名称:cocos2d-xna,代码行数:52,代码来源:b2CircleShape.cs


示例9: GetTransform

        /// Get the interpolated transform at a specific time.
        /// @param beta is a factor in [0,1], where 0 indicates alpha0.
        public void GetTransform(out b2Transform xfb, float beta)
        {
            float x = (1.0f - beta) * c0.x + beta * c.x;
            float y = (1.0f - beta) * c0.y + beta * c.y;

            float angle = (1.0f - beta) * a0 + beta * a;

            float sin = (float)Math.Sin(angle);
            float cos = (float)Math.Cos(angle);

            // Shift to origin
            xfb.p.x = x - (cos * localCenter.x - sin * localCenter.y);
            xfb.p.y = y - (sin * localCenter.x + cos * localCenter.y);
            
            xfb.q.s = sin;
            xfb.q.c = cos;
        }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:19,代码来源:b2Sweep.cs


示例10: RayCast

        // Collision Detection in Interactive 3D Environments by Gino van den Bergen
        // From Section 3.1.2
        // x = s + a * r
        // norm(x) = radius
        public virtual bool RayCast(out b2RayCastOutput output, b2RayCastInput input,
                                    b2Transform transform, int childIndex)
        {
            output = b2RayCastOutput.Zero;

            b2Vec2 position = transform.p + b2Math.b2Mul(transform.q, m_p);
            b2Vec2 s = input.p1 - position;
            float b = b2Math.b2Dot(s, s) - m_radius * m_radius;

            // Solve quadratic equation.
            b2Vec2 r = input.p2 - input.p1;
            float c = b2Math.b2Dot(s, r);
            float rr = b2Math.b2Dot(r, r);
            float sigma = c * c - rr * b;

            // Check for negative discriminant and short segment.
            if (sigma < 0.0f || rr < b2Settings.b2_epsilon)
            {
                return false;
            }

            // Find the point of intersection of the line with the circle.
            float a = -(c + b2Math.b2Sqrt(sigma));

            // Is the intersection point on the segment?
            if (0.0f <= a && a <= input.maxFraction * rr)
            {
                a /= rr;
                output.fraction = a;
                output.normal = s + a * r;
                output.normal.Normalize();
                return true;
            }

            return false;
        }
开发者ID:Ratel13,项目名称:cocos2d-x-for-xna,代码行数:40,代码来源:b2CircleShape.cs


示例11: TestPoint

 public override bool TestPoint(b2Transform xf, b2Vec2 p)
 {
     return false;
 }
开发者ID:homocury,项目名称:cocos2d-xna,代码行数:4,代码来源:b2ChainShape.cs


示例12: RayCast

        public override bool RayCast(out b2RayCastOutput output, b2RayCastInput input,
                                    b2Transform xf, int childIndex)
        {
            b2EdgeShape edgeShape = new b2EdgeShape();
            output = b2RayCastOutput.Zero;

            int i1 = childIndex;
            int i2 = childIndex + 1;
            if (i2 == m_count)
            {
                i2 = 0;
            }

            edgeShape.Vertex1 = m_vertices[i1];
            edgeShape.Vertex2 = m_vertices[i2];

            b2RayCastOutput co = b2RayCastOutput.Zero;
            bool b = edgeShape.RayCast(out co, input, xf, 0);
            output = co;
            return (b);
        }
开发者ID:homocury,项目名称:cocos2d-xna,代码行数:21,代码来源:b2ChainShape.cs


示例13: ComputeAABB

        public override b2AABB ComputeAABB(b2Transform xf, int childIndex)
        {
            int i1 = childIndex;
            int i2 = childIndex + 1;
            if (i2 == m_count)
            {
                i2 = 0;
            }

            b2Vec2 v1 = b2Math.b2Mul(xf, m_vertices[i1]);
            b2Vec2 v2 = b2Math.b2Mul(xf, m_vertices[i2]);

            b2AABB aabb = b2AABB.Default;
            aabb.Set(b2Math.b2Min(v1, v2),b2Math.b2Max(v1, v2));
            return (aabb);
        }
开发者ID:huaqiangs,项目名称:cocos2d-xna,代码行数:16,代码来源:b2ChainShape.cs


示例14: b2FindIncidentEdge

        public static void b2FindIncidentEdge(b2ClipVertex[] c,
                                     b2PolygonShape poly1, b2Transform xf1, int edge1,
                                     b2PolygonShape poly2, b2Transform xf2)
        {
            b2Vec2[] normals1 = poly1.Normals;

            int count2 = poly2.VertexCount;
            b2Vec2[] vertices2 = poly2.Vertices;
            b2Vec2[] normals2 = poly2.Normals;

            // Get the normal of the reference edge in poly2's frame.
            b2Vec2 normal1 = b2Math.b2MulT(xf2.q, b2Math.b2Mul(xf1.q, normals1[edge1]));

            // Find the incident edge on poly2.
            int index = 0;
            float minDot = b2Settings.b2_maxFloat;
            for (int i = 0; i < count2; ++i)
            {
                float dot = b2Math.b2Dot(normal1, normals2[i]);
                if (dot < minDot)
                {
                    minDot = dot;
                    index = i;
                }
            }

            // Build the clip vertices for the incident edge.
            int i1 = index;
            int i2 = i1 + 1 < count2 ? i1 + 1 : 0;

            c[0].v = b2Math.b2Mul(xf2, vertices2[i1]);
            c[0].id.indexA = (byte)edge1;
            c[0].id.indexB = (byte)i1;
            c[0].id.typeA = b2ContactFeatureType.e_face;
            c[0].id.typeB = b2ContactFeatureType.e_vertex;

            c[1].v = b2Math.b2Mul(xf2, vertices2[i2]);
            c[1].id.indexA = (byte)edge1;
            c[1].id.indexB = (byte)i2;
            c[1].id.typeA = b2ContactFeatureType.e_face;
            c[1].id.typeB = b2ContactFeatureType.e_vertex;
        }
开发者ID:CartBlanche,项目名称:cocos2d-xna,代码行数:42,代码来源:b2Collision.cs


示例15: b2FindMaxSeparation

        // Find the max separation between poly1 and poly2 using edge normals from poly1.
        public static float b2FindMaxSeparation(out int edgeIndex,
                                         b2PolygonShape poly1, ref b2Transform xf1,
                                         b2PolygonShape poly2, ref b2Transform xf2)
        {
            int count1 = poly1.VertexCount;
            b2Vec2[] normals1 = poly1.Normals;

            // Vector pointing from the centroid of poly1 to the centroid of poly2.
            b2Vec2 d = b2Math.b2Mul(xf2, poly2.Centroid) - b2Math.b2Mul(xf1, poly1.Centroid);
            b2Vec2 dLocal1 = b2Math.b2MulT(xf1.q, d);

            // Find edge normal on poly1 that has the largest projection onto d.
            int edge = 0;
            float maxDot = -b2Settings.b2_maxFloat;
            for (int i = 0; i < count1; ++i)
            {
                float dot = b2Math.b2Dot(normals1[i], dLocal1);
                if (dot > maxDot)
                {
                    maxDot = dot;
                    edge = i;
                }
            }

            // Get the separation for the edge normal.
            float s = b2EdgeSeparation(poly1, xf1, edge, poly2, xf2);

            // Check the separation for the previous edge normal.
            int prevEdge = edge - 1 >= 0 ? edge - 1 : count1 - 1;
            float sPrev = b2EdgeSeparation(poly1, xf1, prevEdge, poly2, xf2);

            // Check the separation for the next edge normal.
            int nextEdge = edge + 1 < count1 ? edge + 1 : 0;
            float sNext = b2EdgeSeparation(poly1, xf1, nextEdge, poly2, xf2);

            // Find the best edge and the search direction.
            int bestEdge;
            float bestSeparation;
            int increment;
            if (sPrev > s && sPrev > sNext)
            {
                increment = -1;
                bestEdge = prevEdge;
                bestSeparation = sPrev;
            }
            else if (sNext > s)
            {
                increment = 1;
                bestEdge = nextEdge;
                bestSeparation = sNext;
            }
            else
            {
                edgeIndex = edge;
                return s;
            }

            // Perform a local search for the best edge normal.
            for (; ; )
            {
                if (increment == -1)
                    edge = bestEdge - 1 >= 0 ? bestEdge - 1 : count1 - 1;
                else
                    edge = bestEdge + 1 < count1 ? bestEdge + 1 : 0;

                s = b2EdgeSeparation(poly1, xf1, edge, poly2, xf2);

                if (s > bestSeparation)
                {
                    bestEdge = edge;
                    bestSeparation = s;
                }
                else
                {
                    break;
                }
            }

            edgeIndex = bestEdge;
            return bestSeparation;
        }
开发者ID:CartBlanche,项目名称:cocos2d-xna,代码行数:82,代码来源:b2Collision.cs


示例16: b2TestOverlap

        /// Determine if two generic shapes overlap.
        public static bool b2TestOverlap(b2Shape shapeA, int indexA,
                             b2Shape shapeB, int indexB,
                            ref b2Transform xfA, ref b2Transform xfB)
        {
            b2DistanceInput input = b2DistanceInput.Create();
            input.proxyA = b2DistanceProxy.Create(shapeA, indexA);
            input.proxyB = b2DistanceProxy.Create(shapeB, indexB);
            input.transformA = xfA;
            input.transformB = xfB;
            input.useRadii = true;

            b2SimplexCache cache = b2SimplexCache.Create();

            b2DistanceOutput output = new b2DistanceOutput();

            b2Simplex.b2Distance(ref output, ref cache, ref input);

//            Console.WriteLine("{2} vs {3}: distance={0} after {1} iters", output.distance, output.iterations, shapeA.ShapeType, shapeB.ShapeType);

            return output.distance < 10.0f * b2Settings.b2_epsilon;
        }
开发者ID:CartBlanche,项目名称:cocos2d-xna,代码行数:22,代码来源:b2Collision.cs


示例17: ComputeAABB

        public override b2AABB ComputeAABB(b2Transform xf, int childIndex)
        {
            b2Vec2 v1 = b2Math.b2Mul(xf, m_vertex1);
            b2Vec2 v2 = b2Math.b2Mul(xf, m_vertex2);

            b2Vec2 lower = b2Math.b2Min(v1, v2);
            b2Vec2 upper = b2Math.b2Max(v1, v2);

            b2Vec2 r = new b2Vec2(m_radius, m_radius);
            b2AABB aabb = new b2AABB();
            aabb.lowerBound = lower - r;
            aabb.upperBound = upper + r;
            return(aabb);
        }
开发者ID:homocury,项目名称:cocos2d-xna,代码行数:14,代码来源:b2EdgeShape.cs


示例18: b2CollideEdgeAndCircle

        /// Compute the collision manifold between an edge and a circle.
        public static void b2CollideEdgeAndCircle(ref b2Manifold manifold,
                                        b2EdgeShape edgeA, ref b2Transform xfA,
                                        b2CircleShape circleB, ref b2Transform xfB)
        {
            manifold.pointCount = 0;

            // Compute circle in frame of edge
            b2Vec2 Q = b2Math.b2MulT(xfA, b2Math.b2Mul(xfB, circleB.Position));

            b2Vec2 A = edgeA.Vertex1, B = edgeA.Vertex2;
            b2Vec2 e = B - A;
            b2Vec2 diff;

            // Barycentric coordinates
            diff = B - Q;
            float u = b2Math.b2Dot(ref e, ref diff); // B - Q);
            diff = Q - A;
            float v = b2Math.b2Dot(ref e, ref diff); // Q - A);

            float radius = edgeA.Radius + circleB.Radius;

            b2ContactFeature cf = b2ContactFeature.Zero;
            cf.indexB = 0;
            cf.typeB = b2ContactFeatureType.e_vertex;

            // Region A
            if (v <= 0.0f)
            {
                b2Vec2 P = A;
                b2Vec2 d = Q - P;
                float dd = d.LengthSquared; //  b2Math.b2Dot(d, d);
                if (dd > radius * radius)
                {
                    return;
                }

                // Is there an edge connected to A?
                if (edgeA.HasVertex0)
                {
                    b2Vec2 A1 = edgeA.Vertex0;
                    b2Vec2 B1 = A;
                    b2Vec2 e1 = B1 - A1;
                    diff = B1 - Q;
                    float u1 = b2Math.b2Dot(ref e1, ref diff);

                    // Is the circle in Region AB of the previous edge?
                    if (u1 > 0.0f)
                    {
                        return;
                    }
                }

                cf.indexA = 0;
                cf.typeA = b2ContactFeatureType.e_vertex;
                manifold.pointCount = 1;
                manifold.type = b2ManifoldType.e_circles;
                manifold.localNormal.SetZero();
                manifold.localPoint = P;
                manifold.points[0].id.key = 0;
                manifold.points[0].id.Set(cf);
                manifold.points[0].localPoint = circleB.Position;
                return;
            }

            // Region B
            if (u <= 0.0f)
            {
                b2Vec2 P = B;
                b2Vec2 d = Q - P;
                float dd = d.LengthSquared; //  b2Math.b2Dot(d, d);
                if (dd > radius * radius)
                {
                    return;
                }

                // Is there an edge connected to B?
                if (edgeA.HasVertex3)
                {
                    b2Vec2 B2 = edgeA.Vertex3;
                    b2Vec2 A2 = B;
                    b2Vec2 e2 = B2 - A2;
                    diff = Q - A2;
                    float v2 = b2Math.b2Dot(ref e2, ref diff);

                    // Is the circle in Region AB of the next edge?
                    if (v2 > 0.0f)
                    {
                        return;
                    }
                }

                cf.indexA = 1;
                cf.typeA = b2ContactFeatureType.e_vertex;
                manifold.pointCount = 1;
                manifold.type = b2ManifoldType.e_circles;
                manifold.localNormal.SetZero();
                manifold.localPoint = P;
                manifold.points[0].id.key = 0;
                manifold.points[0].id.Set(cf);
//.........这里部分代码省略.........
开发者ID:CartBlanche,项目名称:cocos2d-xna,代码行数:101,代码来源:b2Collision.cs


示例19: ComputeAABB

 /// Given a transform, compute the associated axis aligned bounding box for a child shape.
 /// @param aabb returns the axis aligned box.
 /// @param xf the world transform of the shape.
 /// @param childIndex the child shape
 public abstract b2AABB ComputeAABB(b2Transform xf, int childIndex);
开发者ID:homocury,项目名称:cocos2d-xna,代码行数:5,代码来源:b2Shape.cs


示例20: RayCast

 /// Cast a ray against a child shape.
 /// @param output the ray-cast results.
 /// @param input the ray-cast input parameters.
 /// @param transform the transform to be applied to the shape.
 /// @param childIndex the child shape index
 public abstract bool RayCast(out b2RayCastOutput output, b2RayCastInput input,
                     b2Transform transform, int childIndex);
开发者ID:homocury,项目名称:cocos2d-xna,代码行数:7,代码来源:b2Shape.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Common.b2Vec2类代码示例发布时间:2022-05-24
下一篇:
C# Common.b2Color类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap