Jump to content

  • Log In with Google      Sign In   
  • Create Account

stc.5421

Member Since 06 Dec 2012
Offline Last Active Dec 08 2012 12:54 PM

#5008003 Calculate screen co-ords from a point in 3D space

Posted by stc.5421 on 06 December 2012 - 11:47 PM

Simply transform your 3d position by view projection matrix .
md3dDevice->GetTransform(D3DTS_PROJECTION,&pm);
md3dDevice->GetTransform(D3DTS_VIEW,&vm);
D3DXMATRIX vp;
D3DXMatrixMultiply( &vp, &vm, &pm );
D3DXVECTOR4 posBase;
D3DXVec4Transform(&posBase,&D3DXVECTOR4(m_positionVal.x,m_positionVal.y,m_positionVal.z,1.0f),&vp);
posBase.x/=posBase.w; // Screen space X pos
posBase.y/=posBase.w; // Screen space Y pos
posBase.z/=posBase.w;




#5007777 Creating Bullet Holes

Posted by stc.5421 on 06 December 2012 - 09:11 AM

1- "p" is your intersected point

2- "v1,v2,v3" are your intersected face vertices

3- "N" is your face normal or you can calculate it from your vertices
{
A = v2 - v1
B = v3 - v1
N = normalize( cross( A , B ) )
}

4- Calculate your Up and Right vector
{
up = normalize( p - v1 )
right = cross( up , N )
}

5- "Q1,Q2,Q3,Q4" are your Quad vertices and can calculate like this
{
Q1 = p + up * scale
Q2 = p - up * scale
Q3 = p + right * scale
Q4 = p - right * scale
}


PARTNERS