Quote: "Guys do you know how can I position an object so that it has the same position has the mouse, I can't seem to do it because the mouse uses the XY system and the object uses the XYZ system."
This is not the cleanest of code but try using this...
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 then call it like this:
Vector3 v;
pickVector( v, dbMouseX(), dbMouseY() );
v.x = v.x * 50 + dbCameraPositionX();
v.y = v.y * 50 + dbCameraPositionY();
v.z = v.z * 50 + dbCameraPositionZ();
The number '50' you see there places the "tip" of the vector you're pointing along at 50 units distance. Simply adjust that to the depth you want.
I have vague plans for World Domination