Sign in to follow this  

Getting Vertex Positions for individual Triangles

This topic is 4270 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 want to use D3DXIntersectTri() to detect whether the ray being cast from my cursor is colliding with either of the trianlges in one tile (There are two triangles in one tile) So I was wondering how can I get the Vertex positions for each triangle as D3DXIntersectTri takes Vectors containing the X,Y and Z values of each Vertex as parameters. I think I should also point out that each of my tiles is drawn like so: d3ddevice->SetTexture(0, texture); D3DXMatrixTranslation(&WorldMat, x, y, 0.0f); d3ddevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); d3ddevice->SetTexture(0, NULL); The above code is contained inside a function which is called between the BeginScene() and EndScene() functions.

Share this post


Link to post
Share on other sites
Extract the positions from your vertex buffer and then use D3DXVec3TransformCoord() to put them into world space... Or you could use the D3DXVec3Unproject() function to transform your mouse coordinates into a model-space vector, which might be more efficient (less transforming) - but its difficult to say without more data.

hth
Jack

Share this post


Link to post
Share on other sites
I'm supposing that as my Vertex Buffer is set to D3DUSAGE_WRITEONLY I won't be able to extract the data I need? And also I only use 1 VB for all of my tiles. It is just re-used and the indivdual tiles are then transformed.

Share this post


Link to post
Share on other sites
OK I'm rather stupid and I actually don't know how to do that...
But still wouldn't that be pretty pointless as the co-ordinates given to the VB never change so if you transformed them to World Space those new co-ordinates would be the same for each tile. I'm trying to get the co-ordinates of the tile after it has been transformed and moved about by the World Matrix

Share this post


Link to post
Share on other sites
Well it's not Direct3D specific - it's entirely dependent on how you've written your software in general.

At the point where you initially fill up your vertex buffer (with a IDirect3DVertexBuffer9::Lock() call) with data you should just keep a copy of that data somewhere else. If you're using a class instance then maybe create a clone of the array as a private member. It aint pretty, but you could also create it as a global variable.

hth
Jack

Share this post


Link to post
Share on other sites

This topic is 4270 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this