You need to find out what the "pick vector" is that shoots from the camera position through the mouse pointer and then select some distance into the screen (along that vector) where you want to place the object.
To find the pick vector you can use
typedef D3DXVECTOR3 Vector3;
void pickVector
(
Vector3& voPickVec,
int iScreenX,
int iScreenY
)
{
// CALCULATE HALF THE SCREEN WIDTH AND HEIGHT
// SUBTRACT 1 BECAUSE POINTS START AT (0,0), NOT (1,1)
float fHalfScreenW = (float)( dbScreenWidth()-1 ) / 2.0f;
float fHalfScreenH = (float)( dbScreenHeight()-1 ) / 2.0f;
// CALCULATE THE RATIO CONSTANTS. REMEMBER, HEIGHT CONSTANT IS ALWAYS .6
float fWidthConst = (float)dbScreenWidth() / (float)dbScreenHeight() * 0.6f;
voPickVec.x = fWidthConst * ( (float)iScreenX - fHalfScreenW ) / fHalfScreenW;
voPickVec.y = 0.6f * ( fHalfScreenH - (float)iScreenY ) / fHalfScreenH;
voPickVec.z = 1.0f;
// MAKE VECTOR A UNIT VECTOR
D3DXVec3Normalize( &voPickVec, &voPickVec );
Vector3 vOldCamRelVec;
float fCamCosX = cosf( D3DXToRadian(dbCameraAngleX()) );
float fCamSinX = sinf( D3DXToRadian(dbCameraAngleX()) );
float fCamCosY = cosf( D3DXToRadian(dbCameraAngleY()) );
float fCamSinY = sinf( D3DXToRadian(dbCameraAngleY()) );
float fCamCosZ = cosf( D3DXToRadian(dbCameraAngleZ()) );
float fCamSinZ = sinf( D3DXToRadian(dbCameraAngleZ()) );
// CALULATE X-AXIS ROTATION RELATIVE TO CAMERA
vOldCamRelVec.y = voPickVec.y;
vOldCamRelVec.z = voPickVec.z;
voPickVec.y = vOldCamRelVec.y*fCamCosX - vOldCamRelVec.z*fCamSinX;
voPickVec.z = vOldCamRelVec.y*fCamSinX + vOldCamRelVec.z*fCamCosX;
// CALCULATE Y-AXIS ROTATION RELATIVE TO CAMERA
vOldCamRelVec.x = voPickVec.x;
vOldCamRelVec.z = voPickVec.z;
voPickVec.x = vOldCamRelVec.x*fCamCosY + vOldCamRelVec.z*fCamSinY;
voPickVec.z = vOldCamRelVec.z*fCamCosY - vOldCamRelVec.x*fCamSinY;
// CALCULATE Z-AXIS ROTATION RELATIVE TO CAMERA
vOldCamRelVec.x = voPickVec.x;
vOldCamRelVec.y = voPickVec.y;
voPickVec.x = vOldCamRelVec.x*fCamCosZ - vOldCamRelVec.y*fCamSinZ;
voPickVec.y = vOldCamRelVec.x*fCamSinZ + vOldCamRelVec.y*fCamCosZ;
}
You can obtain iScreenX and iScreenY from the mouse position. After you call that function and obtain voPickVec, at distance "fDistance" you should be at the 3d point
pointX = dbCameraPositionX() + voPickVec.x * fDistance
pointY = dbCameraPositionY() + voPickVec.y * fDistance
pointZ = dbCameraPositionZ() + voPickVec.z * fDistance
Hope this helps.
I have vague plans for World Domination