我正在将Box2d或plank.js的javascript版本与我自己的库(空间坐标)集成在一起。我有一个列表/数组,在调用 world.step 之前,每个循环都会不断更改。 (之所以需要限制world.step中更新的内容,是因为世界需要无限远)
我尝试在 world.step 函数中传递该主体数组,但是没有入口点。
我还考虑过尝试更改某些变量,例如this.m_bodyList或b.getNext(),但我认为这些无效。
我什至考虑过添加主体,然后调用world.step然后删除这些主体。
world.step 函数如下所示:
World.prototype.step = function(timeStep, velocityIterations, positionIterations) {
if ((velocityIterations | 0) !== velocityIterations) {
// TODO: remove this in future
velocityIterations = 0;
}
velocityIterations = velocityIterations || this.m_velocityIterations;
positionIterations = positionIterations || this.m_positionIterations;
// TODO: move this to testbed
this.m_stepCount++;
// If new fixtures were added, we need to find the new contacts.
if (this.m_newFixture) {
this.findNewContacts();
this.m_newFixture = false;
}
this.m_locked = true;
s_step.reset(timeStep);
s_step.velocityIterations = velocityIterations;
s_step.positionIterations = positionIterations;
s_step.warmStarting = this.m_warmStarting;
s_step.blockSolve = this.m_blockSolve;
// Update contacts. This is where some contacts are destroyed.
this.updateContacts();
// Integrate velocities, solve velocity constraints, and integrate positions.
if (this.m_stepComplete && timeStep > 0) {
this.m_solver.solveWorld(s_step);
// Synchronize fixtures, check for out of range bodies.
for (var b = this.m_bodyList; b; b = b.getNext()) {
// If a body was not in an island then it did not move.
if (b.m_islandFlag == false) {
continue;
}
if (b.isStatic()) {
continue;
}
// Update fixtures (for broad-phase).
b.synchronizeFixtures();
}
// Look for new contacts.
this.findNewContacts();
}
// Handle TOI events.
if (this.m_continuousPhysics && timeStep > 0) {
this.m_solver.solveWorldTOI(s_step);
}
if (this.m_clearForces) {
this.clearForces();
}
this.m_locked = false;
};
我只需要world.step来仅处理库中摄像机可以看到的当前物体列表上的物体/碰撞。
编辑:
有没有办法使自定义功能仅更新一个主体?