Skip to main content
gamedev.net
🔒 Locked

Using D3DXCreateSphere

Started by sdoherty55 Oct 11, 2001 at 7:56 AM 0 replies 1k views
Original Post
sdoherty55
sdoherty55
The following is some sample code that came from http://www.mvps.org/directx/articles/spheremap.htm. However, I am finding that my textures are not properly wrapping around the sphere. Instead there seems to be a bit of a mirror effect. Please comment if you have seen this code, or you know what the problem might be. The following is where I create the sphere: m_oYellow.mesh->m_pSysMemMesh = CreateMappedSphere(m_pd3dDevice, 2.25f, 80, 80); Maybe the problem has to do with the number of stack? Honestly, I have consulted the Direct3D docs and I am unclear on this parameter? Thanks struct _VERTEX { D3DXVECTOR3 pos; // vertex position D3DXVECTOR3 norm; // vertex normal float tu; // texture coordinates float tv; } VERTEX,*LPVERTEX; #define FVF_VERTEX D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1 LPD3DXMESH CreateMappedSphere(LPDIRECT3DDEVICE8 pDev,float fRad,UINT slices,UINT stacks) { // create the sphere LPD3DXMESH mesh; if (FAILED( D3DXCreateSphere(pDev,fRad,slices,stacks,&mesh,NULL)) ) return NULL; // create a copy of the mesh with texture coordinates, // since the D3DX function doesn''t include them LPD3DXMESH texMesh; if (FAILED(mesh->CloneMeshFVF(D3DXMESH_SYSTEMMEM,FVF_VERTEX,pDev,&texMesh))) // failed, return un-textured mesh return mesh; // finished with the original mesh, release it mesh->Release(); // lock the vertex buffer LPVERTEX pVerts; if (SUCCEEDED(texMesh->LockVertexBuffer(0,(BYTE **) &pVerts))) { // get vertex count int numVerts=texMesh->GetNumVertices(); // loop through the vertices for (int i=0;i // calculate texture coordinates pVerts->tu=asinf(pVerts->norm.x)/D3DX_PI+0.5f; pVerts->tv=asinf(pVerts->norm.y)/D3DX_PI+0.5f; // go to next vertex pVerts++; } // unlock the vertex buffer texMesh->UnlockVertexBuffer(); } // return pointer to caller return texMesh; }

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.