-
Notifications
You must be signed in to change notification settings - Fork 1
Description
void DynamicShapeArray::Move(int index) {
float* speed = shapeArray[index].speed;
if (speed[0] || speed[1] || speed[2]) {
CheckCollision(index);
shapeArray[index].Model = glm::translate(glm::mat4{1.f}, glm::vec3(speed[0] * (speedUP * globalSpeed), speed[1] * (speedUP * globalSpeed), speed[2] * (speedUP * globalSpeed))) * shapeArray[index].Model;
shapeArray[index].center[0] += speed[0] * (speedUP * globalSpeed);
shapeArray[index].center[1] += speed[1] * (speedUP * globalSpeed);
shapeArray[index].center[2] += speed[2] * (speedUP * globalSpeed);
}
}in the current code, center x, y, z are directly updated after CheckCollision(index) call which directly affects results of other objects without giving them a chance to find their intended original solution. And because of the order of objects processed, it creates a bias towards one of the objects. For example, the last object to be computed can simply push other objects to make them collide each other again. So the last computed object has the highest bias.
If the collision system could be implemented using a temporary array without altering the original data, it would be able to parallelize the operation using vectorization, multithreading and more. The dependency chain created by the immediate updates makes parallelization a different behavior.
Another issue about collision is that each collision is updating both objects and both objects are calculated which results in duplicated work (object i goes from 0 to n, object j goes from 0 to n, but i,j is same as j,i).
Is the following index check intended for a special object?
if (... index < 2) {
return;
}Looks like index = 0 and index = 1 are special objects, perhaps player-controlled?