#### Archived

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

# The onld triangle pick

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

## Recommended Posts

I''ve got my code working for triangle picking without a problem. The part I don''t understand is what I need to do for triangles that are transformed through a matrix before being rendered. I could multiply every vertex of each object by the transformation matrix needed (like is done automatically after setting the WORLD transform during rendering), but that seems very slow. I''d rather multiply my ray vector for each object and then test it against all the vertices. I assume I should simply multiply the vector by the object''s transformation (or should I use the inverse of the object''s transformation matrix?), but this doesn''t seem to work. Am I on the right track? any comments on how best to do this? Here''s a quick code excerpt: // Get the inverse view matrix D3DXMATRIX matView, m; m_pd3dDevice->GetTransform( D3DTS_VIEW, &matView ); D3DXMatrixInverse( &m, NULL, &matView ); // Now multiply by the object''s transformation matrix to get // into object space D3DXMATRIX translation; D3DXMatrixIdentity( &translation); int* loc = m_Game->m_Characters.getLocation(); D3DXMatrixTranslation(&translation, loc[0], loc[2]+1, loc[1]); // Do I need the inverse? //D3DXMatrixInverse( &translation, NULL, &translation); D3DXMatrixMultiply(&m,&m,&translation); D3DXVECTOR3 vPickRayDir; D3DXVECTOR3 vPickRayOrig; // Transform the screen space pick ray into 3D space vPickRayDir.x = v.x*m._11 + v.y*m._21 + v.z*m._31; vPickRayDir.y = v.x*m._12 + v.y*m._22 + v.z*m._32; vPickRayDir.z = v.x*m._13 + v.y*m._23 + v.z*m._33; vPickRayOrig.x = m._41; vPickRayOrig.y = m._42; vPickRayOrig.z = m._43; Does this make sense? Thanks! Onnel

s/onld/old/

##### Share on other sites
Figured it out!

I *DID* need the inverse of the transformation as well, but I shouldn''t have taken the two inverses and then multiplied them. Instead, multiply the transformations and then take the inverse just once...worked like a charm!

Hope this ends up being of use to someone else!

Onnel

1. 1
2. 2
Rutin
13
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633260
• Total Posts
3011125
• ### Who's Online (See full list)

There are no registered users currently online

×