Bullet Hole Billboard

Started by
19 comments, last by Medo Mex 11 years ago

Show some more code. How do you obtain bRayFrom & bRayTo?

EDIT: When drawing billboards did you transform them with objects transform with which they are "attached"?

Advertisement

No, it's not attached yet, to attach it, do I need to multiply the mesh transformation matrix with the billboard vertices position? Any example how to?

I get bRayFrom and bRayTo from bullet raycasting.

When you click on an object you want billboard to be attached to it, right? Then you need to transform your billboard with that objects transformation matrix, usually you set this up just before you draw your billboard:

// from your code above
D3DXMATRIX matWorld = GetMeshWorldMatrix();// object matrix you have clicked
D3DXMATRIX matInverse; // not this!
D3DXMatrixInverse(&matInverse, NULL, &matWorld);
...
// billboard is now a "child" of that object
d3d9device->SetTransform(D3DTS_WORLD, &matWorld);
DrawBillboard();

You need a way to "remember" which billboard is attached to which object.

As you know, I'm drawing all bullet hole billboards with one single draw call, so the transformation matrix must be set to identity, I want a way to change this:


// Billboard vertices position
D3DXMATRIX matWorld = GetMeshWorldMatrix();
pVertices[j*4+0] = CUSTOM_VERTEX(billboard.Q1, 0.0f, 0.0f);
pVertices[j*4+1] = CUSTOM_VERTEX(billboard.Q2, 0.0f, 1.0f);
pVertices[j*4+2] = CUSTOM_VERTEX(billboard.Q3, 1.0f, 1.0f);
pVertices[j*4+3] = CUSTOM_VERTEX(billboard.Q4, 1.0f, 0.0f);

I want to make the calculation of the billboard position with respect to (matWorld).

Then you transform billboard vertices at a time you place them on object:

D3DXVec3TransformCoord(&bulletBillboardV1, &bulletBillboardV1, &matWorld);
D3DXVec3TransformCoord(&bulletBillboardV2, &bulletBillboardV2, &matWorld);
D3DXVec3TransformCoord(&bulletBillboardV3, &bulletBillboardV3, &matWorld);
D3DXVec3TransformCoord(&bulletBillboardV4, &bulletBillboardV4, &matWorld);

That should attach the billboard to the model, the problem is now with the intersected triangle, I'm only getting a valid intersected triangle if the mesh position is: 0.0f, 0.0f, 0.0f.

That should attach the billboard to the model, the problem is now with the intersected triangle...

It would be a lot easier to help you if you could attach your whole project for us to examine?

Then you might want to consider different approach like instancing (if you want 1 draw call), but you'll then need to learn how to use shaders (as i know instancing is not possible in "fixed function pipeline"). You could store in vertex declaration quaternion (float4) for rotation and position + uniform scale scalar(float4) to build a transfom matrix in vertex shader. Then you just lock->write-unlock for "billboards" that is attached to objects that might move in the scene. With this approach you might want to consider to specialize 2 classes, one for static (no need to lock->write->unlock) and other for dynamic objects.

@belfegor: The current problem is with getting a valid intersected triangle, not the billboards.

The intersected triangle that I get ASSUME that the model is located in XYZ: 0.0f, 0.0f, 0.0f

When I use D3DXIntersect() to get the intersected triangle, the result is only valid if the model position is: 0.0f, 0.0f, 0.0f

I tried:


// Transform intersected triangle v0, v1, v2 according to the model location in the world
D3DXVec3TransformCoord(&v0, &v0, &matWorld);
D3DXVec3TransformCoord(&v1, &v1, &matWorld);
D3DXVec3TransformCoord(&v1, &v1, &matWorld);

But it's not working, I need to find a way to make v0, v1, v2 results according to the model transformation.

You have to show some more code!

How do you visualise triangle that you have picked? Maybie the problem is elsewhere.


D3DXVec3TransformNormal(&rayDir, &bRayTo, &matInverse);
Hmmm, did Postie et.al. here not already point out that or a similar problem ?

This topic is closed to new replies.

Advertisement