Archived

This topic is now archived and is closed to further replies.

lly20000

ShadowVolume question???

Recommended Posts

Now I want make a animate object shadow but when I was look dx9 example ShadowVolume I have a problem in the ShadowVolume the airport is a CD3DMESH but my animate object is a LPD3DFRAME how to make a Shadow with the LPD3DFRAME ?????????????

Share this post


Link to post
Share on other sites
Hi! I just made an ''alternative'' way of building the volumes so that I can make cubes that casts shadow. It might help you, or not.. Sorry about the Quads-variable''s indexing. I wasn''t really sober when I make this. However it works.


HRESULT ShadowVolume::BuildBox(float width, float height, float length, D3DXVECTOR3 vLight, D3DXMATRIX * matTransform) {
D3DXVECTOR3 Quads [4][6];
m_dwNumVertices = 0;

// Top
Quads [0][0] = D3DXVECTOR3(- width / 2, height / 2, - length / 2);
Quads [1][0] = D3DXVECTOR3(- width / 2, height / 2, length / 2);
Quads [2][0] = D3DXVECTOR3( width / 2, height / 2, - length / 2);
Quads [3][0] = D3DXVECTOR3( width / 2, height / 2, length / 2);

Quads [0][1] = D3DXVECTOR3(- width / 2, - height / 2, length / 2);
Quads [1][1] = D3DXVECTOR3( width / 2, - height / 2, length / 2);
Quads [2][1] = D3DXVECTOR3(- width / 2, height / 2, length / 2);
Quads [3][1] = D3DXVECTOR3( width / 2, height / 2, length / 2);

Quads [0][2] = D3DXVECTOR3( width / 2, height / 2, - length / 2);
Quads [1][2] = D3DXVECTOR3( width / 2, height / 2, length / 2);
Quads [2][2] = D3DXVECTOR3( width / 2,- height / 2, - length / 2);
Quads [3][2] = D3DXVECTOR3( width / 2, - height / 2, length / 2);

Quads [0][3] = D3DXVECTOR3(- width / 2, height / 2, - length / 2);
Quads [1][3] = D3DXVECTOR3( width / 2, height / 2, - length / 2);
Quads [2][3] = D3DXVECTOR3(- width / 2, - height / 2, - length / 2);
Quads [3][3] = D3DXVECTOR3( width / 2, - height / 2, - length / 2);

Quads [0][4] = D3DXVECTOR3(- width / 2, - height / 2, length / 2);
Quads [1][4] = D3DXVECTOR3(- width / 2, - height / 2, - length / 2);
Quads [2][4] = D3DXVECTOR3( width / 2, - height / 2, length / 2);
Quads [3][4] = D3DXVECTOR3( width / 2, - height / 2, - length / 2);

Quads [0][5] = D3DXVECTOR3(- width / 2, height / 2, - length / 2);
Quads [1][5] = D3DXVECTOR3(- width / 2, - height / 2, - length / 2);
Quads [2][5] = D3DXVECTOR3(- width / 2, height / 2, length / 2);
Quads [3][5] = D3DXVECTOR3(- width / 2, - height / 2, length / 2);

// For every side of Cube
for(int j=0; j<6; j++) {
// For every triangle
for(int i=0; i<2; i++) {
// Get the vertices making up the triangle
D3DXVECTOR3 v0 = Quads[0][j];
D3DXVECTOR3 v1 = Quads[1][j];
D3DXVECTOR3 v2 = Quads[2][j];

if(i==1) {
v0 = Quads[1][j];
v1 = Quads[3][j];
v2 = Quads[2][j];
}

// Calc Normal of tri and check if it''s to be included
D3DXVECTOR3 vNormal;
D3DXVec3Cross( &vNormal, &(v2-v1), &(v1-v0) );

if(D3DXVec3Dot(&vNormal, &vLight) >= 0.0f) {
// Add every ''face'' (3 in a triangle) and extend it to a quad
// Connect vertex 1->2 and 2->3 and 3->1 get it?
for(int k=0; k<3; k++) {
D3DXVECTOR3 fv1 = v0;
D3DXVECTOR3 fv2 = v1;
D3DXVECTOR3 fv3 = v1 - vLight * 10;
D3DXVECTOR3 fv4 = v2 - vLight * 10;

if(k==0) {
fv1 = v0;
fv2 = v1;
}
else if(k==1) {
fv1 = v1;
fv2 = v2;
}
else if(k==2) {
fv1 = v2;
fv2 = v0;
}

fv3 = fv1 - vLight * 10;
fv4 = fv2 - vLight * 10;

// Add new quad (6 vertices = 2 triangles = 1 quad)
m_pVertices[m_dwNumVertices++] = fv1;
m_pVertices[m_dwNumVertices++] = fv2;
m_pVertices[m_dwNumVertices++] = fv3;

m_pVertices[m_dwNumVertices++] = fv2;
m_pVertices[m_dwNumVertices++] = fv4;
m_pVertices[m_dwNumVertices++] = fv3;
}
}
}
}
}

Share this post


Link to post
Share on other sites