• Advertisement
Sign in to follow this  

Placing Billboard

This topic is 1834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to place a bullet hole billboard, unfortunately I can't get it to work correctly, so I need help to correct my code.

 

LPD3DXMESH mesh = GetMesh();
D3DXVECTOR3 *vertices;
mesh->LockVertexBuffer(D3DLOCK_READONLY, (void **)&vertices);
for(int j = 0; j < mesh->GetNumFaces(); j++)
{
      v1 = vertices[j];
      v2 = vertices[j+1];
      v3 = vertices[j+2];
      if (D3DXIntersectTri(&v1, &v2, &v3, &rayOrigin, &rayDirection, NULL, NULL, NULL))
          break;
}
mesh->UnlockVertexBuffer();
mesh->UnlockIndexBuffer();

// Calculate the bullet billboard quad position
D3DXVECTOR3 p = GetHitPoint()
D3DXVECTOR3 A = v2 - v1;
D3DXVECTOR3 B = v3 - v1;
D3DXVECTOR3 N;
D3DXVec3Cross(&N, &A, &B);
D3DXVec3Normalize(&N, &N);

D3DXVECTOR3 up;
D3DXVec3Normalize(&up, &(p - v1));
D3DXVECTOR3 right;
D3DXVec3Cross(&right, &up, &N);

float scale = 2.0f;
D3DXVECTOR3 Q1 = p + up * scale;
D3DXVECTOR3 Q2 = p - up * scale;
D3DXVECTOR3 Q3 = p + right * scale;
D3DXVECTOR3 Q4 = p - right * scale;

AddBillboard("bullet.png", Q1, Q2, Q3, Q4);

Share this post


Link to post
Share on other sites
Advertisement

Anyone even know if what I'm doing is correct or not? If there is any sample out there for placing bullet billboard in DirectX 9 that would be great.

 

Any help would be appreciated.

Share this post


Link to post
Share on other sites

where did you hear about using billboards for bullet holes? Is this a common method?

 

What if the ray does not hit the mesh, you will end up with the last three vertices as the result. You need to add a defualt result to your loop.

 

What does GetHitPoint() do? Do you plan on passing it parameters or do you use some globals?

 

Why do you unlock the index buffer if you dont use it?

Share this post


Link to post
Share on other sites

@Tispe: I use Bullet raycasting to get the hit point, I don't have any problem with shooting, the only thing that I'm trying to do in the above code is to place a bullet hole billboard.

 

Bullet raycasting tell me which mesh was hit so I can use it to get the intersected triangle.

 

GetHitPoint() = Get the point that was hit by bullet physics raycasting.

GetMesh() = Get the mesh that was hit by bullet physics raycasting.

Share this post


Link to post
Share on other sites

GetHitPoint() does not exists, I just wrote it to make it clear on what I'm doing. 

 

You can consider the code as the following:

D3DXVECTOR3 p = GetHitPoint() // Bullet physics raycasting hit point (where the bullet hit)

D3DXIntersectTri() is used to get the intersected triangle on the mesh.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement