   Scaling Issue
  I'm having problems with applying my scaling factor before calculating the bounding sphere on my mesh.When I have a scale of 1.0f everything works fine, but reducing that scale to 0.1f (the intended scale) makes the bounding sphere's radius much smaller than the mesh's actual radius (so that my mouse picking code only works when I zoom right in on the mesh and click the dead centre)Below is my code, with the two different scaling methods I've tried using commented out:[source=c++]void modelX::calculateBoundingSphere(){void * vPtr_vertices;HRESULT hr;hr = mesh->LockVertexBuffer( D3DLOCK_READONLY, (void**)&vPtr_vertices );D3DXVECTOR3 * vertices = (D3DXVECTOR3*)vPtr_vertices;DWORD bytespervertex = mesh->GetNumBytesPerVertex();DWORD numvertices = mesh->GetNumVertices();/*for(int j = 0;j<numvertices;j++){vertices[j].x *= scalingfactor;vertices[j].y *= scalingfactor;vertices[j].z *= scalingfactor;}*/hr = D3DXComputeBoundingSphere(vertices,numvertices,bytespervertex,&centre,&radius);//radius *= scalingfactor;hr = mesh->UnlockVertexBuffer();}
  If the code that's commented out was all un-commented, then it looks like you were effectively scaling the sphere down twice: once implicitly, when the sphere is computed from the scaled mesh, and then once explicitly, when the radius is scaled.I'd try uncommenting the first block of code but leaving the last line (the one that scales the radius) commented out, and see if that fixes the problem.   ;  Sorry for the confusion, I wasn't actually using both commented sections at the same time (instead using either one or the other).In any case, when I use the for-loop, it doesn't actually change the radius output of D3DXComputeBoundingSphere.and when I just multiply the resultant radius by the scaling factor it ends up too small.;  Is your mesh, in fact, comprised only of positions? No normals, texcoords, etc.?Your for-loop assumes the entire vertex buffer is only positions ( i.e., you cast the buffer to an array of D3DXVECTOR3 ).If you don't know the format, you can assume that the position occurs first in each vertex. You might try locking the buffer pointer to "BYTE* vb," for instance, and change your for-loop to something like:D3DXVECTOR3 v = *((D3DXVECTOR3*)(vb + j*bytespervertex));v *= scale;*((D3DXVECTOR3*)(vb + j*bytespervertex) = v;If you do know the format, lock the vertex buffer to a pointer to the vertex structure.MyVertexStructure *vb;mesh->LockVertexBuffer(D3DLOCK_READONLY,(void**)&vb);for(....) vb[j].position *= scale; // use the D3DXVECTOR3 overloaded multiplication operator;  I don't know if this will help but you may need to square your scaler.vertices[j].x *= scalingfactor * scalingfactor;When getting the length of a point you need to use sqrt().example: float length = sqrt( getLength( point ) );Now you can use your scaler as expected.example: float scaled = length *= scalingfactor;Without using sqrt() you just do the below.example: float length = getLength( point );example: float scaled = length *= scalingfactor * scalingfactor;