コード例 #1
0
ファイル: Globals.cs プロジェクト: pixeltasim/Conform
        public static void CollidePolygonAndCircle(out Manifold manifold, PolygonShape polygon, Transform xf1, CircleShape circle, Transform xf2)
        {
            var polyLock = polygon.Lock();
            var circleLock = circle.Lock();

            NativeMethods.cb2_collidepolygonandcircle(out manifold, polyLock, xf1, circleLock, xf2);

            polygon.Unlock();
            circle.Unlock();
        }
コード例 #2
0
ファイル: Globals.cs プロジェクト: pixeltasim/Conform
        public static void CollidePolygons(out Manifold manifold, PolygonShape poly1, Transform xf1, PolygonShape poly2, Transform xf2)
        {
            var poly1Lock = poly1.Lock();
            var poly2Lock = poly2.Lock();

            NativeMethods.cb2_collidepolygons(out manifold, poly1Lock, xf1, poly2Lock, xf2);

            poly1.Unlock();
            poly2.Unlock();
        }
コード例 #3
0
ファイル: Globals.cs プロジェクト: pixeltasim/Conform
        public static void CollideCircles(out Manifold manifold, CircleShape circle1, Transform xf1, CircleShape circle2, Transform xf2)
        {
            var circle1Lock = circle1.Lock();
            var circle2Lock = circle2.Lock();

            NativeMethods.cb2_collidecircles(out manifold, circle1Lock, xf1, circle2Lock, xf2);

            circle1.Unlock();
            circle2.Unlock();
        }
コード例 #4
0
ファイル: Globals.cs プロジェクト: pixeltasim/Conform
        public static bool TestOverlap(Shape shapeA, Shape shapeB, Transform xfA, Transform xfB)
        {
            var sh1Lock = shapeA.Lock();
            var sh2Lock = shapeB.Lock();

            bool rV = NativeMethods.cb2_testoverlap(sh1Lock, sh2Lock, xfA, xfB);

            shapeA.Unlock();
            shapeB.Unlock();

            return rV;
        }
コード例 #5
0
ファイル: ApplyForce.cs プロジェクト: RubisetCie/box2c
        public ApplyForce()
        {
            m_world.Gravity = new Vec2(0.0f, 0.0f);

            const float k_restitution = 0.4f;

            Body ground;
            {
                BodyDef bd = new BodyDef();
                bd.Position = new Vec2(0.0f, 20.0f);
                ground = m_world.CreateBody(bd);

                PolygonShape shape = new PolygonShape();

                FixtureDef sd = new FixtureDef();
                sd.Shape = shape;
                sd.Density = 0.0f;
                sd.Restitution = k_restitution;

                // Left vertical
                shape.SetAsEdge(new Vec2(-20.0f, -20.0f), new Vec2(-20.0f, 20.0f));
                ground.CreateFixture(sd);

                // Right vertical
                shape.SetAsEdge(new Vec2(20.0f, -20.0f), new Vec2(20.0f, 20.0f));
                ground.CreateFixture(sd);

                // Top horizontal
                shape.SetAsEdge(new Vec2(-20.0f, 20.0f), new Vec2(20.0f, 20.0f));
                ground.CreateFixture(sd);

                // Bottom horizontal
                shape.SetAsEdge(new Vec2(-20.0f, -20.0f), new Vec2(20.0f, -20.0f));
                ground.CreateFixture(sd);
            }

            {
                Transform xf1 = new Transform();
                xf1.R = new Mat22(0.3524f * (float)Math.PI);
                xf1.Position = (xf1.R * new Vec2(1.0f, 0.0f));

                Vec2[] vertices = new Vec2[3]
                {
                    (xf1 * new Vec2(-1.0f, 0.0f)),
                    (xf1 * new Vec2(1.0f, 0.0f)),
                    (xf1 * new Vec2(0.0f, 0.5f))
                };

                PolygonShape poly1 = new PolygonShape(vertices);

                FixtureDef sd1 = new FixtureDef();
                sd1.Shape = poly1;
                sd1.Density = 4.0f;

                Transform xf2 = new Transform();
                xf2.R = new Mat22(-0.3524f * (float)Math.PI);
                xf2.Position = (xf2.R * new Vec2(-1.0f, 0.0f));

                vertices = new Vec2[]
                {
                    (xf2 * new Vec2(-1.0f, 0.0f)),
                    (xf2 * new Vec2(1.0f, 0.0f)),
                    (xf2 * new Vec2(0.0f, 0.5f))
                };

                PolygonShape poly2 = new PolygonShape(vertices);

                FixtureDef sd2 = new FixtureDef();
                sd2.Shape = poly2;
                sd2.Density = 2.0f;

                BodyDef bd = new BodyDef();
                bd.BodyType = BodyType.Dynamic;
                bd.AngularDamping = 5.0f;
                bd.LinearDamping = 0.1f;

                bd.Position = new Vec2(0.0f, 2.0f);
                bd.Angle = (float)Math.PI;
                bd.AllowSleep = false;
                m_body = m_world.CreateBody(bd);
                m_body.CreateFixture(sd1);
                m_body.CreateFixture(sd2);
            }

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

                FixtureDef fd = new FixtureDef();
                fd.Shape = shape;
                fd.Density = 1.0f;
                fd.Friction = 0.3f;

                for (int i = 0; i < 10; ++i)
                {
                    BodyDef bd = new BodyDef();
                    bd.BodyType = BodyType.Dynamic;

                    bd.Position = new Vec2(0.0f, 5.0f + 1.54f * i);
                    Body body = m_world.CreateBody(bd);

                    body.CreateFixture(fd);

                    float gravity = 10.0f;
                    float I = body.Inertia;
                    float mass = body.Mass;

                    // For a circle: I = 0.5 * m * r * r ==> r = sqrt(2 * I / m)
                    float radius = (float)Math.Sqrt(2.0f * I / mass);

                    FrictionJointDef jd = new FrictionJointDef();
                    jd.LocalAnchorA = jd.LocalAnchorB = Vec2.Empty;
                    jd.BodyA = ground;
                    jd.BodyB = body;
                    jd.CollideConnected = true;
                    jd.MaxForce = mass * gravity;
                    jd.MaxTorque = mass * radius * gravity;

                    m_world.CreateJoint(jd);
                }
            }
        }
コード例 #6
0
ファイル: Contact.cs プロジェクト: RubisetCie/box2c
 public static extern void b2contact_evaluate(IntPtr contact, out Manifold outManifold, Transform xfA, Transform xfB);
コード例 #7
0
ファイル: Contact.cs プロジェクト: RubisetCie/box2c
        public void Evaluate(out Manifold manifold, Transform xfA, Transform xfB)
        {
            manifold = new Manifold();

            NativeMethods.b2contact_evaluate(_contactPtr, out manifold, xfA, xfB);
        }
コード例 #8
0
ファイル: Render.cs プロジェクト: RubisetCie/box2c
        public void DrawJoint(Box2CS.Serialize.JointDefSerialized x, Vec2 p1, Vec2 p2, BodyDef bodyA, BodyDef bodyB)
        {
            Transform xf1 = new Transform(bodyA.Position, new Mat22(bodyA.Angle));
            Transform xf2 = new Transform(bodyB.Position, new Mat22(bodyB.Angle));
            Vec2 x1 = xf1.Position;
            Vec2 x2 = xf2.Position;

            p1 = xf1 * p1;
            p2 = xf2 * p2;

            ColorF color = new ColorF(0.5f, 0.8f, 0.8f);

            switch (x.Joint.JointType)
            {
            case JointType.Distance:
                DrawSegment(p1, p2, color);
                break;

            case JointType.Pulley:
                {
                    PulleyJointDef pulley = (PulleyJointDef)x.Joint;
                    Vec2 s1 = pulley.GroundAnchorA;
                    Vec2 s2 = pulley.GroundAnchorB;
                    DrawSegment(s1, p1, color);
                    DrawSegment(s2, p2, color);
                    DrawSegment(s1, s2, color);
                }
                break;

            case JointType.Revolute:
                {
                    RevoluteJointDef rjd = (RevoluteJointDef)x.Joint;

                    if (rjd.EnableLimit)
                    {
                        Vec2 startPos = p1;
                        Vec2 sinCos = new Vec2(-(float)Math.Cos((rjd.UpperAngle + rjd.ReferenceAngle) - (float)Math.PI / 2), -(float)Math.Sin((rjd.UpperAngle + rjd.ReferenceAngle) - (float)Math.PI / 2));

                        var end = startPos + (sinCos * 3);
                        DrawSegment(startPos, end, new ColorF(0, 0.65f, 0.65f));

                        sinCos = new Vec2(-(float)Math.Cos((rjd.LowerAngle + rjd.ReferenceAngle) - (float)Math.PI / 2), -(float)Math.Sin((rjd.LowerAngle + rjd.ReferenceAngle) - (float)Math.PI / 2));

                        end = startPos + (sinCos * 3);
                        DrawSegment(startPos, end, new ColorF(0, 0.65f, 0.65f));
                        DrawArc(startPos, 3, (-rjd.LowerAngle - rjd.ReferenceAngle), (-rjd.UpperAngle - rjd.ReferenceAngle));
                    }

                    DrawCircle(p1, 0.75f, new ColorF(0, 0.65f, 0.65f));

                    DrawSegment(x1, p1, color);
                    DrawSegment(p1, p2, color);
                    DrawSegment(x2, p2, color);
                }
                break;

            default:
            case JointType.Unknown:
                DrawSegment(x1, p1, color);
                DrawSegment(p1, p2, color);
                DrawSegment(x2, p2, color);
                break;
            }
        }
コード例 #9
0
ファイル: Render.cs プロジェクト: RubisetCie/box2c
        public override void DrawTransform(Transform xf)
        {
            Vec2 p1 = xf.Position, p2;
            const float k_axisScale = 0.4f;
            Gl.glBegin(Gl.GL_LINES);

            Gl.glColor3f(1.0f, 0.0f, 0.0f);
            Gl.glVertex2f(p1.X, p1.Y);
            p2 = p1 + k_axisScale * xf.R.Col1;
            Gl.glVertex2f(p2.X, p2.Y);

            Gl.glColor3f(0.0f, 1.0f, 0.0f);
            Gl.glVertex2f(p1.X, p1.Y);
            p2 = p1 + k_axisScale * xf.R.Col2;
            Gl.glVertex2f(p2.X, p2.Y);

            Gl.glEnd();
        }
コード例 #10
0
ファイル: Render.cs プロジェクト: RubisetCie/box2c
        public void DrawShape(FixtureDef fixture, Transform xf, ColorF color)
        {
            switch (fixture.Shape.ShapeType)
            {
            case ShapeType.Circle:
                {
                    CircleShape circle = (CircleShape)fixture.Shape;

                    Vec2 center = (xf * circle.Position);
                    float radius = circle.Radius;
                    Vec2 axis = xf.R.Col1;

                    DrawSolidCircle(center, radius, axis, color);
                }
                break;

            case ShapeType.Polygon:
                {
                    PolygonShape poly = (PolygonShape)fixture.Shape;
                    int vertexCount = poly.VertexCount;
                    //b2Assert(vertexCount <= b2_maxPolygonVertices);
                    for (int i = 0; i < vertexCount; ++i)
                        drawVertices[i] = (xf * poly.Vertices[i]);

                    DrawSolidPolygon(drawVertices, vertexCount, color);
                }
                break;
            }
        }
コード例 #11
0
ファイル: Globals.cs プロジェクト: pixeltasim/Conform
 public static extern bool cb2_testoverlap(IntPtr shapeA, IntPtr shapeB, Transform xfA, Transform xfB);
コード例 #12
0
ファイル: Globals.cs プロジェクト: pixeltasim/Conform
 public static extern void cb2_collidepolygons(out Manifold manifold, IntPtr polygon1, Transform xf1, IntPtr polygon2, Transform xf2);
コード例 #13
0
ファイル: Globals.cs プロジェクト: pixeltasim/Conform
 public static extern void cb2_collidepolygonandcircle(out Manifold manifold, IntPtr polygon, Transform xf1, IntPtr circle, Transform xf2);
コード例 #14
0
ファイル: Globals.cs プロジェクト: pixeltasim/Conform
 public static extern void cb2_collidecircles(out Manifold manifold, IntPtr circle1, Transform xf1, IntPtr circle2, Transform xf2);
コード例 #15
0
ファイル: DebugDraw.cs プロジェクト: pixeltasim/Conform
 public abstract void DrawTransform(Transform xf);
コード例 #16
0
ファイル: Body.cs プロジェクト: pixeltasim/Conform
 public static extern void b2body_gettransform(IntPtr body, out Transform transform);