Box2DX.Collision.EdgeShape.Set C# (CSharp) Method

Set() public method

public Set ( System.Vector2 v1, System.Vector2 v2 ) : void
v1 System.Vector2
v2 System.Vector2
return void
        public void Set(Vector2 v1, Vector2 v2)
        {
            _v1 = v1;
            _v2 = v2;

            _direction = _v2 - _v1;
            _length = _direction.magnitude;
            _direction.Normalize();
            _normal = _direction.CrossScalarPostMultiply(1.0f);

            _cornerDir1 = _normal;
            _cornerDir2 = -1.0f * _normal;
        }

Usage Example

Example #1
0
        public void Create(BroadPhase broadPhase, Body body, XForm xf, FixtureDef def)
        {
            UserData = def.UserData;
            Friction = def.Friction;
            Restitution = def.Restitution;
            Density = def.Density;

            _body = body;
            _next = null;

            Filter = def.Filter;

            _isSensor = def.IsSensor;

            _type = def.Type;

            // Allocate and initialize the child shape.
            switch (_type)
            {
                case ShapeType.CircleShape:
                    {
                        CircleShape circle = new CircleShape();
                        CircleDef circleDef = (CircleDef)def;
                        circle._position = circleDef.LocalPosition;
                        circle._radius = circleDef.Radius;
                        _shape = circle;
                    }
                    break;

                case ShapeType.PolygonShape:
                    {
                        PolygonShape polygon = new PolygonShape();
                        PolygonDef polygonDef = (PolygonDef)def;
                        polygon.Set(polygonDef.Vertices, polygonDef.VertexCount);
                        _shape = polygon;
                    }
                    break;

                case ShapeType.EdgeShape:
                    {
                        EdgeShape edge = new EdgeShape();
                        EdgeDef edgeDef = (EdgeDef)def;
                        edge.Set(edgeDef.Vertex1, edgeDef.Vertex2);
                        _shape = edge;
                    }
                    break;

                default:
                    Box2DXDebug.Assert(false);
                    break;
            }

            // Create proxy in the broad-phase.
            AABB aabb;
            _shape.ComputeAABB(out aabb, xf);

            bool inRange = broadPhase.InRange(aabb);

            // You are creating a shape outside the world box.
            Box2DXDebug.Assert(inRange);

            if (inRange)
            {
                _proxyId = broadPhase.CreateProxy(aabb, this);
            }
            else
            {
                _proxyId = PairManager.NullProxy;
            }
        }