# Help with Collision

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

## Recommended Posts

I'm kinda new to 3d graphics... Can someone point me to some good articles about matrix functions and how to place items in the world coordinates. And then how to place a ray (used for collision) in the right coordinates so it hits a level underneath the camera. If I change the level's scale or I translate it then how do I change the ray's coordinates so it will be in the same place as the level. Here's what I think I'm doing: I setup all the matrices D3DXMATRIX WorldMatrix; D3DXMATRIX ScaleMatrix; D3DXMATRIX RotationMatrix; D3DXMATRIX RotationMatrix; I enter some coordinates which I want for the level, example scaling: D3DXMatrixScaling(ScaleMatrix, 2.0f, 2.0f, 2.0f); Then I multiply all the matrices to get the world matrix: D3DXMatrixMultiply(&WorldMatrix, &ScaleMatrix, &RotationMatrix); D3DXMatrixMultiply(&WorldMatrix, &WorldMatrix, &TranslationMatrix); then I update the current world with: IDirect3DDevice8::SetTransform(D3DTS_WORLD,WorldMatrix) and I render 1 thing, I update using this function again if an item has different scaling and I render again. So I never have to use any functions to multiply an object by the world matrix... DirectX does it for me? Now comes the hard part. How do I update the ray so it works correctly with each 3d object? I'm using the function: D3DXIntersect(Mesh1->m_Meshes->m_Mesh, &D3DXVECTOR3(XPos,YPos,ZPos), &D3DXVECTOR3(0.0f, -1.0f, 0.0f), &Hit, &FaceIndex, &u, &v, &Dist); And collision works well if I use 0,0,0 for all matrices. But once I change the scale or if I decide to translate the level then this collision function stops working.. So How do I upodate? I have D3DXMATRIX WorldMatrix and I have D3DXVECTOR3(XPos,YPos,ZPos). Do I use D3DXMatrixTranspose(matTransposed, WorldMatrix); How do I multiply the ray by the correct matrix so it works fine? Which functions accomplish this? I think a good tutorial about this would be best :)

##### Share on other sites
The ray collision needs to work in object space so if you are doing picking for example you need to do an inverse transform from the screen 2D co-ords into the space of the object being tested against. Normally transformation is world matrix (object space to world space) , View Matrix (world space to camera space) and Projection Matrix, (camera space to screen space). So just reverse that to go the other way. Picking notes: Picking, Matrices notes: matrices

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
18

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009806
• ### Who's Online (See full list)

There are no registered users currently online

×