Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actuallonewolff

Posted 10 December 2012 - 10:47 PM

Hi stc.5421,

I turned your code snippet into a function as below, but the values for fScreenX and fScreenY remain at zero, no matter what the inputs are for world X,Y, & Z.

void Graphics::WorldToScreen(float fPosX,float fPosY,float fPosZ)
{
D3DXMATRIX pm;
D3DXMATRIX vm;
D3DXMATRIX vp;
md3dDevice->GetTransform(D3DTS_PROJECTION,&pm);
md3dDevice->GetTransform(D3DTS_VIEW,&vm);
D3DXMatrixMultiply(&vp,&vm,&pm);
D3DXVECTOR4 posBase;
//D3DXVec4Transform(&posBase,&D3DXVECTOR4(m_positionVal.x,m_positionVal.y,m_positionVal.z,1.0f),&vp);
D3DXVec4Transform(&posBase,&D3DXVECTOR4(fPosX,fPosY,fPosZ,1.0f),&vp);
fScreenX=(posBase.x/=posBase.w); // Screen space X pos
fScreenY=(posBase.y/=posBase.w); // Screen space Y pos
posBase.z/=posBase.w;
}

Any help would be awesome Posted Image

#2lonewolff

Posted 10 December 2012 - 10:46 PM

Hi stc.5421,

I turned your code snippet into a function as below, but the values for fScreenX and fScreenY remain at zero, no matter what the inputs are for world X,Y, & Z.

void Graphics::WorldToScreen(float fPosX,float fPosY,float fPosZ)
{
D3DXMATRIX pm;
D3DXMATRIX vm;
D3DXMATRIX vp;
md3dDevice->GetTransform(D3DTS_PROJECTION,&pm);
md3dDevice->GetTransform(D3DTS_VIEW,&vm);
D3DXMatrixMultiply(&vp,&vm,&pm);
D3DXVECTOR4 posBase;
//D3DXVec4Transform(&posBase,&D3DXVECTOR4(m_positionVal.x,m_positionVal.y,m_positionVal.z,1.0f),&vp);
D3DXVec4Transform(&posBase,&D3DXVECTOR4(fPosX,fPosY,fPosZ,1.0f),&vp);
fScreenX=(posBase.x/=posBase.w); // Screen space X pos
fScreenY=(posBase.y/=posBase.w); // Screen space Y pos
posBase.z/=posBase.w;
}

Any helps would be greatly appreciated Posted Image

#1lonewolff

Posted 10 December 2012 - 10:45 PM

Hi stc.5421,

I turned your code snippet into a function as below, but the values for fScreenX and fScreenY remain at zero, no matter what the inputs are for world X,Y, & Z.

void Graphics::WorldToScreen(float fPosX,float fPosY,float fPosZ)
{
D3DXMATRIX pm;
D3DXMATRIX vm;
D3DXMATRIX vp;
md3dDevice->GetTransform(D3DTS_PROJECTION,&pm);
md3dDevice->GetTransform(D3DTS_VIEW,&vm);
D3DXMatrixMultiply(&vp,&vm,&pm);
D3DXVECTOR4 posBase;
//D3DXVec4Transform(&posBase,&D3DXVECTOR4(m_positionVal.x,m_positionVal.y,m_positionVal.z,1.0f),&vp);
D3DXVec4Transform(&posBase,&D3DXVECTOR4(fPosX,fPosY,fPosZ,1.0f),&vp);
fScreenX=(posBase.x/=posBase.w); // Screen space X pos
fScreenY=(posBase.y/=posBase.w); // Screen space Y pos
posBase.z/=posBase.w;
}

Any helps would be greatly appreciated Posted Image

PARTNERS