예제 #1
0
 /// Construct this matrix using scalars.
 public b2Mat22(float a11, float a12, float a21, float a22)
 {
     ex = b2Vec2.Zero;
     ey = b2Vec2.Zero;
     ex.x = a11; ex.y = a21;
     ey.x = a12; ey.y = a22;
 }
예제 #2
0
파일: Rope.cs 프로젝트: Ratel13/cocos2d-xna
        public Rope()
        {
            const int N = 40;
            b2Vec2[] vertices = new b2Vec2[N];
            float[] masses = new float[N];

            for (int i = 0; i < N; ++i)
            {
                vertices[i].Set(0.0f, 20.0f - 0.25f * i);
                masses[i] = 1.0f;
            }
            masses[0] = 0.0f;
            masses[1] = 0.0f;

            b2RopeDef def = new b2RopeDef();
            def.vertices = vertices;
            def.count = N;
            def.gravity.Set(0.0f, -10.0f);
            def.masses = masses;
            def.damping = 0.1f;
            def.k2 = 1.0f;
            def.k3 = 0.5f;

            m_rope.Initialize(def);

            m_angle = 0.0f;
            m_rope.SetAngle(m_angle);
        }
예제 #3
0
 public virtual void Set(b2Vec2 v1, b2Vec2 v2)
 {
     Vertex1 = v1;
     Vertex2 = v2;
     HasVertex0 = false;
     HasVertex3 = false;
 }
예제 #4
0
 /// Construct this matrix using scalars.
 public b2Mat22(float a11, float a12, float a21, float a22)
 {
     _ex = new b2Vec2();
     _ey = new b2Vec2();
     _ex.x = a11; _ex.y = a21;
     _ey.x = a12; _ey.y = a22;
 }
예제 #5
0
        void InitPhysics()
        {
            var gravity = new b2Vec2(0.0f, -10.0f);
            world = new b2World(gravity);

            world.SetAllowSleeping(true);
            world.SetContinuousPhysics(true);

            var def = new b2BodyDef();
            def.allowSleep = true;
            def.position = b2Vec2.Zero;
            def.type = b2BodyType.b2_staticBody;

            b2Body groundBody = world.CreateBody(def);
            groundBody.SetActive(true);

            b2EdgeShape groundBox = new b2EdgeShape();
            groundBox.Set(b2Vec2.Zero, new b2Vec2(900, 100));

            b2FixtureDef fd = new b2FixtureDef();
            fd.friction = 0.3f;
            fd.restitution = 0.1f;
            fd.shape = groundBox;

            groundBody.CreateFixture(fd);
        }
예제 #6
0
 public void Initialize(b2Body bA, b2Body bB, b2Vec2 anchor)
 {
     BodyA = bA;
     BodyB = bB;
     localAnchorA = BodyA.GetLocalPoint(anchor);
     localAnchorB = BodyB.GetLocalPoint(anchor);
 }
예제 #7
0
        public JumpPad(b2Vec2 JumpImpuls, CCPoint Position, b2World gameWorld)
        {
            this.Texture = new CCTexture2D ("jumppad");
            this.Scale = SpriteScale;
            this.Position = Position;
            this.IsAntialiased = false;

            jumpImpuls = JumpImpuls;
            totalJumps = 0;

            //box2d
            b2BodyDef jumpPadDef = new b2BodyDef ();
            jumpPadDef.type = b2BodyType.b2_kinematicBody;
            jumpPadDef.position = new b2Vec2 ((Position.X + this.ScaledContentSize.Width/2)/PhysicsHandler.pixelPerMeter, (Position.Y + this.ScaledContentSize.Height/4) / PhysicsHandler.pixelPerMeter);
            JumpPadBody = gameWorld.CreateBody (jumpPadDef);

            b2PolygonShape jumpPadShape = new b2PolygonShape ();
            jumpPadShape.SetAsBox ((float)this.ScaledContentSize.Width / PhysicsHandler.pixelPerMeter / 2, (float)this.ScaledContentSize.Height / PhysicsHandler.pixelPerMeter / 4);// /4 weil die hitbox nur die hälfte der textur ist

            b2FixtureDef jumpPadFixture = new b2FixtureDef ();
            jumpPadFixture.shape = jumpPadShape;
            jumpPadFixture.density = 0.0f; //Dichte
            jumpPadFixture.restitution = 0f; //Rückprall
            jumpPadFixture.friction = 0f;
            jumpPadFixture.userData = WorldFixtureData.jumppad;
            JumpPadBody.CreateFixture (jumpPadFixture);
            //
        }
예제 #8
0
        public void DrawFixture(b2Fixture fixture)
        {
            b2Color color = new b2Color(0.95f, 0.95f, 0.6f);
            b2Transform xf = fixture.Body.Transform;

            switch (fixture.ShapeType)
            {
                case b2ShapeType.e_circle:
                    {
                        b2CircleShape circle = (b2CircleShape) fixture.Shape;

                        b2Vec2 center = b2Math.b2Mul(xf, circle.Position);
                        float radius = circle.Radius;

                        m_debugDraw.DrawCircle(center, radius, color);
                    }
                    break;

                case b2ShapeType.e_polygon:
                    {
                        b2PolygonShape poly = (b2PolygonShape) fixture.Shape;
                        int vertexCount = poly.VertexCount;
                        Debug.Assert(vertexCount <= b2Settings.b2_maxPolygonVertices);
                        b2Vec2[] vertices = new b2Vec2[b2Settings.b2_maxPolygonVertices];

                        for (int i = 0; i < vertexCount; ++i)
                        {
                            vertices[i] = b2Math.b2Mul(xf, poly.Vertices[i]);
                        }

                        m_debugDraw.DrawPolygon(vertices, vertexCount, color);
                    }
                    break;
            }
        }
예제 #9
0
 public virtual void Set(b2Vec2 v1, b2Vec2 v2)
 {
     m_vertex1 = v1;
     m_vertex2 = v2;
     m_hasVertex0 = false;
     m_hasVertex3 = false;
 }
예제 #10
0
        /// Clipping for contact manifolds.
        public static int b2ClipSegmentToLine(b2ClipVertex[] vOut, b2ClipVertex[] vIn,
                                     b2Vec2 normal, float offset, byte vertexIndexA)
        {
            // Start with no output points
            int numOut = 0;

            // Calculate the distance of end points to the line
            float distance0 = b2Math.b2Dot(normal, vIn[0].v) - offset;
            float distance1 = b2Math.b2Dot(normal, vIn[1].v) - offset;

            // If the points are behind the plane
            if (distance0 <= 0.0f) vOut[numOut++] = vIn[0];
            if (distance1 <= 0.0f) vOut[numOut++] = vIn[1];

            // If the points are on different sides of the plane
            if (distance0 * distance1 < 0.0f)
            {
                // Find intersection point of edge and plane
                float interp = distance0 / (distance0 - distance1);
                vOut[numOut].v = vIn[0].v + interp * (vIn[1].v - vIn[0].v);

                // VertexA is hitting edgeB.
                vOut[numOut].id.indexA = vertexIndexA;
                vOut[numOut].id.indexB = vIn[0].id.indexB;
                vOut[numOut].id.typeA = b2ContactFeatureType.e_vertex;
                vOut[numOut].id.typeB = b2ContactFeatureType.e_face;
                ++numOut;
            }

            return numOut;
        }
예제 #11
0
        protected override void Draw(Settings settings)
        {
            base.Draw(settings);

            b2Manifold manifold = new b2Manifold();
            b2Collision.b2CollidePolygons(manifold, m_polygonA, ref m_transformA, m_polygonB, ref m_transformB);

            b2WorldManifold worldManifold = new b2WorldManifold();
            worldManifold.Initialize(manifold, ref m_transformA, m_polygonA.Radius, ref m_transformB, m_polygonB.Radius);

            m_debugDraw.DrawString(5, m_textLine, "point count = {0}", manifold.pointCount);
            m_textLine += 15;

            {
                b2Color color = new b2Color(0.9f, 0.9f, 0.9f);
                b2Vec2[] v = new b2Vec2[b2Settings.b2_maxPolygonVertices];
                for (int i = 0; i < m_polygonA.VertexCount; ++i)
                {
                    v[i] = b2Math.b2Mul(m_transformA, m_polygonA.Vertices[i]);
                }
                m_debugDraw.DrawPolygon(v, m_polygonA.VertexCount, color);

                for (int i = 0; i < m_polygonB.VertexCount; ++i)
                {
                    v[i] = b2Math.b2Mul(m_transformB, m_polygonB.Vertices[i]);
                }
                m_debugDraw.DrawPolygon(v, m_polygonB.VertexCount, color);
            }

            for (int i = 0; i < manifold.pointCount; ++i)
            {
                m_debugDraw.DrawPoint(worldManifold.points[i], 4.0f, new b2Color(0.9f, 0.3f, 0.3f));
            }
        }
예제 #12
0
 public b2PolygonShape(b2PolygonShape copy)
     : base((b2Shape)copy)
 {
     Centroid = copy.Centroid;
     Array.Copy(copy.Vertices, Vertices, copy.Vertices.Length);
     Array.Copy(copy.Normals, Normals, copy.Normals.Length);
     m_vertexCount = copy.m_vertexCount;
 }
예제 #13
0
        public void DrawPoint(b2Vec2 aP, float aSize, b2Color aColor)
        {
            CCDrawingPrimitives.Begin();

            CCDrawingPrimitives.DrawPoint(new CCPoint(mRatio * aP.x, mRatio * aP.y), 1, new CCColor4B(aColor.r, aColor.g, aColor.b, 1));

            CCDrawingPrimitives.End();
        }
예제 #14
0
 /// Initialize the bodies, anchors, and reference angle using a world
 /// anchor point.
 public void Initialize(b2Body bA, b2Body bB, b2Vec2 anchor)
 {
     BodyA = bA;
     BodyB = bB;
     localAnchorA = BodyA.GetLocalPoint(anchor);
     localAnchorB = BodyB.GetLocalPoint(anchor);
     referenceAngle = BodyB.Angle - BodyA.Angle;
 }
예제 #15
0
 public virtual void CreateChain(b2Vec2[] vertices, int count)
 {
     Count = count;
     Vertices = new b2Vec2[count];
     Array.Copy(vertices, Vertices, count);
     HasPrevVertex = false;
     HasNextVertex = false;
 }
예제 #16
0
 public virtual void CreateChain(b2Vec2[] vertices, int count)
 {
     m_count = count;
     m_vertices = new b2Vec2[count];
     Array.Copy(m_vertices, vertices, count);
     m_hasPrevVertex = false;
     m_hasNextVertex = false;
 }
예제 #17
0
 /// Advance the sweep forward, yielding a new initial state.
 /// @param alpha the new initial time.
 public void Advance(float alpha)
 {
     Debug.Assert(alpha0 < 1.0f);
     float beta = (alpha - alpha0) / (1.0f - alpha0);
     c0 = (1.0f - beta) * c0 + beta * c;
     a0 = (1.0f - beta) * a0 + beta * a;
     alpha0 = alpha;
 }
예제 #18
0
 public static CCPoint WorldToScreen(b2Vec2 worldPos, CCPoint actualPosition, float actualScale, CCSize wSize)
 {
     worldPos *= actualScale;
     CCPoint layerOffset = actualPosition;
     CCPoint p = new CCPoint(worldPos.x + layerOffset.X, worldPos.y + layerOffset.Y);
     p.Y = wSize.Height - p.Y;
     return p;
 }
예제 #19
0
 public virtual void SetTarget(b2Vec2 target)
 {
     if (m_bodyB.IsAwake() == false)
     {
         m_bodyB.SetAwake(true);
     }
     m_targetA = target;
 }
예제 #20
0
 public void Defaults()
 {
     localCenter = new b2Vec2();
     c0 = new b2Vec2();
     c = new b2Vec2();
     a0 = 0f;
     a = 0f;
     alpha0 = 0f;
 }
예제 #21
0
 public override void DrawPolygon(b2Vec2[] vertices, int vertexCount, b2Color color)
 {
     b2Vec2[] alt = new b2Vec2[vertexCount];
     for (int i = 0; i < vertexCount; i++)
     {
         alt[i] = vertices[i] * PTMRatio + _Center;
     }
     CCDrawingPrimitives.DrawPoly(alt, vertexCount, true, color);
 }
예제 #22
0
 public b2ChainShape(b2ChainShape clone)
     : base((b2Shape)clone)
 {
     CreateChain(clone.Vertices, clone.Count);
     PrevVertex = clone.PrevVertex;
     NextVertex = clone.NextVertex;
     HasPrevVertex = clone.HasPrevVertex;
     HasNextVertex = clone.HasNextVertex;
 }
예제 #23
0
 public b2EdgeShape(b2EdgeShape e)
     : base((b2Shape)e)
 {
     m_vertex1 = e.m_vertex1;
     m_vertex2 = e.m_vertex2;
     m_vertex3 = e.m_vertex3;
     m_vertex0 = e.m_vertex0;
     m_hasVertex0 = e.m_hasVertex0;
     m_hasVertex3 = e.m_hasVertex3;
 }
예제 #24
0
 public override void DrawSolidPolygon(b2Vec2[] vertices, int vertexCount, b2Color color)
 {
     _list.Count = vertexCount;
     var alt = _list.Elements;
     for (int i = 0; i < vertexCount; i++)
     {
         alt[i] = vertices[i] * PTMRatio + _Center;
     }
     CCDrawingPrimitives.DrawSolidPoly(alt, vertexCount, color);
 }
예제 #25
0
        public override void DrawCircle(b2Vec2 aCenter, float aRadius, b2Color aColor)
        {
            CCDrawingPrimitives.Begin();

            CCDrawingPrimitives.DrawCircle(new CCPoint(mRatio * aCenter.x, mRatio * aCenter.y),
                aRadius, 0, DEBUG_DRAW_CIRCLE_SEGMENTS, false,
                new CCColor4B(aColor.r, aColor.g, aColor.b, 1));

            CCDrawingPrimitives.End();
        }
예제 #26
0
 public void Initialize(b2Body b1, b2Body b2,
                             b2Vec2 anchor1, b2Vec2 anchor2)
 {
     BodyA = b1;
     BodyB = b2;
     localAnchorA = BodyA.GetLocalPoint(anchor1);
     localAnchorB = BodyB.GetLocalPoint(anchor2);
     b2Vec2 d = anchor2 - anchor1;
     length = d.Length;
 }
예제 #27
0
 public b2EdgeShape(b2EdgeShape e)
     : base((b2Shape)e)
 {
     Vertex1 = e.Vertex1;
     Vertex2 = e.Vertex2;
     Vertex3 = e.Vertex3;
     Vertex0 = e.Vertex0;
     HasVertex0 = e.HasVertex0;
     HasVertex3 = e.HasVertex3;
 }
예제 #28
0
        public b2WeldJoint(b2WeldJointDef def)
            : base(def)
        {
            m_localAnchorA = def.localAnchorA;
            m_localAnchorB = def.localAnchorB;
            m_referenceAngle = def.referenceAngle;
            m_frequencyHz = def.frequencyHz;
            m_dampingRatio = def.dampingRatio;

            m_impulse.SetZero();
        }
예제 #29
0
 public virtual void CreateLoop(b2Vec2[] vertices, int count)
 {
     m_count = count + 1;
     m_vertices = new b2Vec2[m_count];
     Array.Copy(vertices, m_vertices, count);
     m_vertices[count] = m_vertices[0];
     PrevVertex = m_vertices[m_count - 2];
     NextVertex = m_vertices[1];
     m_hasPrevVertex = true;
     m_hasNextVertex = true;
 }
예제 #30
0
 public virtual void CreateLoop(b2Vec2[] vertices, int count)
 {
     Count = count + 1;
     Vertices = new b2Vec2[Count];
     Array.Copy(vertices, Vertices, count);
     Vertices[count] = Vertices[0];
     PrevVertex = Vertices[Count - 2];
     NextVertex = Vertices[1];
     HasPrevVertex = true;
     HasNextVertex = true;
 }
예제 #31
0
 public static float b2Cross(b2Vec2 a, b2Vec2 b)
 {
     return(a.x * b.y - a.y * b.x);
 }
예제 #32
0
 public static void b2Max(ref b2Vec2 a, ref b2Vec2 b, out b2Vec2 output)
 {
     output.x = Math.Max(a.x, b.x);
     output.y = Math.Max(a.y, b.y);
 }
예제 #33
0
 public static b2Vec2 b2Clamp(b2Vec2 a, b2Vec2 low, b2Vec2 high)
 {
     return(b2Max(low, b2Min(a, high)));
 }
예제 #34
0
 public static float b2Dot(ref b2Vec2 a, ref b2Vec2 b)
 {
     return(a.x * b.x + a.y * b.y);
 }
예제 #35
0
        public static float b2Distance(b2Vec2 a, b2Vec2 b)
        {
            b2Vec2 c = a - b;

            return(c.Length);
        }