public abstract ComputeAABB ( |
||
aabb | Returns the axis aligned box. | |
xf | Box2DX.Common.Transform | The world Transform of the shape. |
return | void |
// We need separation create/destroy functions from the constructor/destructor because // the destructor cannot access the allocator or broad-phase (no destructor arguments allowed by C++). public void Create(BroadPhase broadPhase, Body body, Transform xf, FixtureDef def) { UserData = def.UserData; Friction = def.Friction; Restitution = def.Restitution; Body = body; _next = null; Filter = def.Filter; IsSensor = def.IsSensor; Shape = def.Shape.Clone(); Shape.ComputeMass(out _massData, def.Density); // Create proxy in the broad-phase. Shape.ComputeAABB(out Aabb, ref xf); ProxyId = broadPhase.CreateProxy(Aabb, this); }
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; } }