• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Placing Billboard

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Medo3337  Members

Posted 08 January 2013 - 07:25 AM

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;
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);

### #2Medo3337  Members

Posted 10 January 2013 - 08:08 PM

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.

### #3Tispe  Members

Posted 11 January 2013 - 05:11 AM

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?

### #4Medo3337  Members

Posted 11 January 2013 - 07:33 AM

@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.

### #5Tispe  Members

Posted 11 January 2013 - 08:26 AM

Why do you use D3DXIntersectTri() and GetHitPoint() then?

### #6Medo3337  Members

Posted 11 January 2013 - 09:01 AM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.