
First of all, demo code that reproduces the bug (should compile as-is, it's console-based):
- Code: Select all
#include <cstddef>
#include <iostream>
#include <Newton.h>
int main()
{
std::cout.setf(std::ios::floatfield, std::ios::fixed);
std::cout.precision(2);
NewtonWorld *world = NewtonCreate();
float boxCloud[8][3] = // 1x1x1 diameter box
{
{ -0.5f, 0.5f, 0.5f }, // top left front
{ -0.5f, 0.5f, -0.5f }, // top left back
{ 0.5f, 0.5f, 0.5f }, // top right front
{ 0.5f, 0.5f, -0.5f }, // top right back
{ -0.5f, -0.5f, 0.5f }, // bottom left front
{ -0.5f, -0.5f, -0.5f }, // bottom left back
{ 0.5f, -0.5f, 0.5f }, // bottom right front
{ 0.5f, -0.5f, -0.5f } // bottom right back
};
NewtonCollision *boxCol = NewtonCreateConvexHull(world, 8, &boxCloud[0][0], sizeof(float) * 3, 0.01f, 0, NULL);
NewtonCollision *boxMod = NewtonCreateConvexHullModifier(world, boxCol, 0);
float scale2[] =
{
2.0f, 0.0f, 0.0f, 0.0f,
0.0f, 2.0f, 0.0f, 0.0f,
0.0f, 0.0f, 2.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
// CASE 1: IF WE SET THE SCALE HERE, THE CALCULATED AABB IS CORRECT
//NewtonConvexHullModifierSetMatrix(boxMod, scale2);
// create compound collision out of the convex hull modifier
NewtonCollision *boxCompound = NewtonCreateCompoundCollision(world, 1, &boxMod, 0);
// CASE 2: IF WE INSTEAD SET THE SCALE HERE, THE CALCULATED AABB IS INCORRECT (as if no scale set)
NewtonConvexHullModifierSetMatrix(boxMod, scale2);
float identity[] =
{
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
float aabb[2][3];
NewtonCollisionCalculateAABB(boxCompound, identity, &aabb[0][0], &aabb[1][0]);
// output should be about (-1, -1, -1) for min and (1, 1, 1) for max, +/- newton's padding factor
std::cout << "aabb min : (" << aabb[0][0] << ", " << aabb[0][1] << ", " << aabb[0][2] << ")" << std::endl;
std::cout << "aabb max : (" << aabb[1][0] << ", " << aabb[1][1] << ", " << aabb[1][2] << ")" << std::endl;
NewtonDestroy(world);
}
Please take a look at the two comments labeled "CASE 1:" and "CASE 2:"
The bug is as follows:
- create a convex hull (I do not know if this bug also applies to primitives)
- create a convex hull modifier out of the convex hull
- create a compound collision out of the convex hull modifier
- scale the compound collision by scaling it's contained convex hull modifier (obviously this is more useful when there are several pieces instead of just one)
- now, the AABB will be incorrect, it will not take into account the scale
HOWEVER! If we set the scale of the convex hull modifier BEFORE we add it to the compound collision, then the AABB is correct - unless we rescale the modifier again, then it would just report the old AABB.
Only the AABB seems to be incorrect - actual collisions, as well as ray casting, work fine either way.
Thanks for your time
