Space_QuadtreeXY class
Raw space (no optimisation, no grid, no quadtree, no ...) every particles are check against every particles (inter Particles and intra Particles group) and check against every Segment
class Space_QuadtreeXY implements Space{ final QuadTreeXYAabb _grid; final Checker checker; final Resolver resolver; final Vector4 _scol = new Vector4.zero(); final _pool = new _ProviderStack<_SQE>() ..createE = _SQE.ctor ..resetE = _SQE.reset ; Space_QuadtreeXY(this.checker, this.resolver, {QuadTreeXYAabb grid}) : _grid = (grid == null)? new QuadTreeXYAabb(-500.0, -500.0, 1000.0, 1000.0, 10) : grid; void reset() { _grid.reset(); _pool.reset(); } /// return true if at least one [ps].collide != 0 (the Particles [ps] is included in the space) bool addParticles(Particles ps) { if (ps.length < 1) return false; var b = false; for(int i = ps.length - 1; i >= 0; --i) { b = b || ps.collide[i] != 0; } if (b) { for(int i = ps.length - 1; i >= 0; --i) { ps.collide[i] = 1; var e = _pool.provide(); e.ps = ps; e.i = i; extractAabbDisc(ps.position3d[i], ps.radius[i], e.aabb); _grid.insert(e.aabb, e); } } return b; } /// return true if [seg].collide != 0 (the Segment [seg] is include in the space) bool addSegment(Segment seg) { if (seg.collide != 0) { seg.collide = 1; var e = _pool.provide(); e.segment = seg; extractAabbDisc2(seg.ps.position3d[seg.i1], seg.ps.position3d[seg.i2], 0.0, e.aabb); _grid.insert(e.aabb, e); return true; } return false; } void handleCollision() { _grid.scan(_handle0); } _handle0(_SQE e1, _SQE e2) { if (e1.ps != null && e2.ps != null) _handlePP(e1, e2); else if (e1.ps != null && e2.segment.ps != null) _handlePS(e1, e2); else if (e2.ps != null && e1.segment.ps != null) _handlePS(e2, e1); else { // segment vs segment collision not managed } } _handlePP(_SQE e1, _SQE e2) { if (e1.ps != e2.ps || e1.ps.intraCollide) { if(checker.collideParticleParticle(e1.ps, e1.i, e2.ps, e2.i, _scol)){ resolver.notifyCollisionParticleParticle(e1.ps, e1.i, e2.ps, e2.i, _scol.w); } } } _handlePS(_SQE e1, _SQE e2) { if (e1.ps != e2.segment.ps || e1.ps.intraCollide) { if (checker.collideParticleSegment(e1.ps, e1.i, e2.segment, _scol)) { resolver.notifyCollisionParticleSegment(e1.ps, e1.i, e2.segment, _scol.w); } } } }
Implements
Constructors
new Space_QuadtreeXY(Checker checker, Resolver resolver, {QuadTreeXYAabb grid}) #
Creates a new Object instance.
Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.
docs inherited from Object
Space_QuadtreeXY(this.checker, this.resolver, {QuadTreeXYAabb grid}) : _grid = (grid == null)? new QuadTreeXYAabb(-500.0, -500.0, 1000.0, 1000.0, 10) : grid;
Properties
Methods
bool addParticles(Particles ps) #
return true if at least one ps.collide != 0 (the Particles ps is included in the space)
bool addParticles(Particles ps) { if (ps.length < 1) return false; var b = false; for(int i = ps.length - 1; i >= 0; --i) { b = b || ps.collide[i] != 0; } if (b) { for(int i = ps.length - 1; i >= 0; --i) { ps.collide[i] = 1; var e = _pool.provide(); e.ps = ps; e.i = i; extractAabbDisc(ps.position3d[i], ps.radius[i], e.aabb); _grid.insert(e.aabb, e); } } return b; }
bool addSegment(Segment seg) #
return true if seg.collide != 0 (the Segment seg is include in the space)
bool addSegment(Segment seg) { if (seg.collide != 0) { seg.collide = 1; var e = _pool.provide(); e.segment = seg; extractAabbDisc2(seg.ps.position3d[seg.i1], seg.ps.position3d[seg.i2], 0.0, e.aabb); _grid.insert(e.aabb, e); return true; } return false; }
void handleCollision() #
void handleCollision() { _grid.scan(_handle0); }
void reset() #
void reset() { _grid.reset(); _pool.reset(); }