Пример #1
0
        public ShapeNode(Box2CS.Shape shape)
            : base(shape.ShapeType.ToString())
        {
            Shape = shape;

            if (Shape is CircleShape)
                ImageIndex = SelectedImageIndex = 1;
            else if (Shape is PolygonShape)
                ImageIndex = SelectedImageIndex = 2;
        }
Пример #2
0
        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;
            }
        }