Then, i modify it for expanding the cube on the 3 axes ("scale" factor in the function's parameters).
But the bounding box is still a cube (i can see it in debug mode, when you see bound box in wireframes).
I don't understand, as the code seemed "dynamic" to me (the bounding box should follow the shape modification of the mesh).
So i tried and force modification of the bouding box, but whatever i try, the bounding box remains a cube.
Here's the code i borrowed and modified:
Code: Select all
irr::scene::SMesh * create_mesh(float scale_x,float scale_y,float scale_z)
{
irr::scene::SMesh *mesh; //the mesh
irr::scene::SMeshBuffer *mesh_buffer; //its buffer
mesh = new irr::scene::SMesh();
mesh_buffer = new irr::scene::SMeshBuffer();
irr::f32 cubeSize = 5.f;
irr::video::SColor cubeColour(255,255,255,255);
irr::u16 u[36] = { 0,2,1, 0,3,2, 1,5,4, 1,2,5, 4,6,7, 4,5,6,
7,3,0, 7,6,3, 9,5,2, 9,8,5, 0,11,10, 0,10,7};
mesh_buffer->Indices.set_used(36);
for (irr::s32 i=0; i<36; ++i) mesh_buffer->Indices[i] = u[i];
mesh_buffer->Vertices.set_used(12);
mesh_buffer->Vertices[0] = irr::video::S3DVertex(0,0,0, -1,-1,-1, cubeColour, 0, 1);
mesh_buffer->Vertices[1] = irr::video::S3DVertex(1*scale_x,0,0, 1,-1,-1, cubeColour, 1, 1);
mesh_buffer->Vertices[2] = irr::video::S3DVertex(1*scale_x,1*scale_y,0, 1, 1,-1, cubeColour, 1, 0);
mesh_buffer->Vertices[3] = irr::video::S3DVertex(0,1*scale_y,0, -1, 1,-1, cubeColour, 0, 0);
mesh_buffer->Vertices[4] = irr::video::S3DVertex(1*scale_x,0,1*scale_z, 1,-1, 1, cubeColour, 0, 1);
mesh_buffer->Vertices[5] = irr::video::S3DVertex(1*scale_x,1*scale_y,1*scale_z, 1, 1, 1, cubeColour, 0, 0);
mesh_buffer->Vertices[6] = irr::video::S3DVertex(0,1*scale_y,1*scale_z, -1, 1, 1, cubeColour, 1, 0);
mesh_buffer->Vertices[7] = irr::video::S3DVertex(0,0,1*scale_z, -1,-1, 1, cubeColour, 1, 1);
mesh_buffer->Vertices[8] = irr::video::S3DVertex(0,1*scale_y,1*scale_z, -1, 1, 1, cubeColour, 0, 1);
mesh_buffer->Vertices[9] = irr::video::S3DVertex(0,1*scale_y,0, -1, 1,-1, cubeColour, 1, 1);
mesh_buffer->Vertices[10] = irr::video::S3DVertex(1*scale_x,0,1*scale_z, 1,-1, 1, cubeColour, 1, 0);
mesh_buffer->Vertices[11] = irr::video::S3DVertex(1*scale_x,0,0, 1,-1,-1, cubeColour, 0, 0);
for (int i=0; i<12; ++i)
{
mesh_buffer->Vertices[i].Pos -= irr::core::vector3df(0.5f, 0.5f, -1.0f);
mesh_buffer->Vertices[i].Pos *= cubeSize;
//I think the problem is here: (but it should work)
mesh_buffer->BoundingBox.addInternalPoint(mesh_buffer->Vertices[i].Pos);
}
// i also tried this, just for seeing if bounding box would be modified, but nothing happened (bbox is still a cube):
// irr::core::aabbox3df bbox(.0,.0,.0,.5,1.,1.);
// mesh_buffer->setBoundingBox(bbox);
mesh->addMeshBuffer(mesh_buffer);
return mesh;
}