How to work with camera?

I try to deal with .x format object after loading it from 3ds max I receive big object.
How to make it smaller I understand that I have to move back the camera,
but I don't know how to do it.


Answer this question

How to work with camera?

  • Tuffty

    I don't understand how I get "bounding box or sphere".
    I'm loading the .X using:

    if( FAILED( D3DXLoadMeshFromX( "body.x",
    D3DXMESH_SYSTEMMEM,
    g_pd3dDevice,
    NULL,
    &pD3DXMtrlBuffer,
    NULL,
    &g_dwNumMaterials,
    &g_pMesh ) ) )
    (the mesh object is the last argument).


    I still beleave that I have to move back the camera ...


  • kschuler

    Hi,

    you can use D3DXComputeBoundingSphere to compute the bounding sphere.

    Check the SDK examples for more info.

    Some c++ code:

    HRESULT hr;

    D3DXVECTOR3 vCenter;

    float fRadius;

    D3DXVECTOR3* pData;

    V( pMesh->LockVertexBuffer( 0, (LPVOID*) &pData ) );

    V( D3DXComputeBoundingSphere( pData, pMesh->GetNumVertices(), pMesh->GetNumBytesPerVertex(), &vCenter, &fRadius ) );

    V( pMesh->UnlockVertexBuffer() );


  • Lheo

    Hi,
    what I described was a way to do a zoom extents, that is, to move the camera so that you can view the selected object(s) in the screen.
    A bounding box or bounding volume is a box (or volume) that completely contains your geometry (in this case your model).
    To get the bounding box you have to calculate it. How you do that It's simple, go through your triangles and get the minimum and maximum values of each coordinate and that will give you the coordinates from two corners of your bounding box.


  • Mikmaq

    Hi,
    taking the bounding box or sphere of your object. To calculate how much you have to move to the back (if you used the bounding sphere of your object):

    float dist = boundingSphere.radius / tan(fovY * 0.5f);

    Now that you have the distance you have to move to the back to make your object fully visible on the screen, just take the center of the sphere of the object and move the cam back.

    newPosition = boundingSphere.center + camDirection * (dist + near);

    the near is just a precaution so that the object doesn't intersects with the near plane.


  • How to work with camera?