i'm trying to scale my models (with a program on my pc)
what do i do?
i grab all my data... find out MIN and MAX values of ALL coordinates
i calculate height with and depth of my meshes
take the maximum extension and keep it
i normalize the dimensions of the mesh to 1 and then scale it up to what was passed to my program...
so this is my code... but somehow it does not scale to eg... 20
some values are larger in my result...
Code: Select all
minX = lmesh.verticesV3[0].x; // init...
minY = lmesh.verticesV3[0].y;
minZ = lmesh.verticesV3[0].z;
maxX = lmesh.verticesV3[0].x;
maxY = lmesh.verticesV3[0].y;
maxZ = lmesh.verticesV3[0].z;
for( unsigned long idx = 1; idx<lmesh.vertexCount; idx++ )
{
minX = min(minX, lmesh.verticesV3[idx].x);
minY = min(minY, lmesh.verticesV3[idx].y);
minZ = min(minZ, lmesh.verticesV3[idx].z);
maxX = max(maxX, lmesh.verticesV3[idx].x);
maxY = max(maxY, lmesh.verticesV3[idx].y);
maxZ = max(maxZ, lmesh.verticesV3[idx].z);
}
// resize values
sizeX = (maxX - minX)/2;
sizeY = (maxY - minY)/2;
sizeZ = (maxZ - minZ)/2;
float fSizemax=max(max(sizeX,sizeY),sizeZ);
printf("fSizemax = %f\n" ,fSizemax);
printf("sizeX = %f\n" ,sizeX);
printf("sizeY = %f\n" ,sizeY);
printf("sizeZ = %f\n" ,sizeZ);
// write new values
for (unsigned int i=0;i<lmesh.vertexCount;i++)
{
lmesh.verticesV3[i].x /= fSizemax;
lmesh.verticesV3[i].x *= scale;
lmesh.verticesV3[i].y /= fSizemax;
lmesh.verticesV3[i].y *= scale;
lmesh.verticesV3[i].z /= fSizemax;
lmesh.verticesV3[i].z *= scale;
}
for( unsigned long i = 0; i<lmesh.vertexCount; i++ )
{
printf("%f %f %f 0x%X %f %f %f\n", lmesh.verticesV3[i].nx, lmesh.verticesV3[i].ny, lmesh.verticesV3[i].nz,
lmesh.verticesV3[i].color, lmesh.verticesV3[i].x, lmesh.verticesV3[i].y, lmesh.verticesV3[i].z);
}
break;
this seems to be one of my last 2 bugs! (centering works on 9/10 meshes)
thanks in advance
lumo
PS: on 13th June i have to publish my work in university, do an presentation and so on; when this is done sourcecode will go public! so guys, possibly one of you will use my code soon ;)