Jump to content
  • Advertisement
Sign in to follow this  
Ingot

Help with Collision

This topic is 4856 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'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 this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!