Sign in to follow this  

ray trace multiple items

This topic is 4657 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 fairly new to directx so I'm hoping there's an easy answer. I've got the basics going, drawing a number of shapes and controlling the view direction, etc. I'm now moving on to attempting to select shapes with the mouse. I'm working from varoius tutorials and samples, but there's one thing that doesn't make sense to me. I'm positiong my objects by adjusting the device world transform before drawing each one, then drawing the mesh, which I think is the right way to do it. But it means that the actual mesh is always local, whereever the shape is in world space, and however it may be rotated / scaled. So, when I use mesh.intersect to find out if my ray goes through the mesh as I draw it, all my shapes get selected when the mouse is in the middle, as that's where all the local meshes are. It seems to me I have to either: 1. Apply my scaling / transformations to the mesh, then draw it without changing the world transform 2. Recover the global mesh (if there is such a thing) after drawing all the items to it, then test the intersection on that. What is the correct way to do this? Thanks

Share this post


Link to post
Share on other sites
Thanks for the suggestion which seems to make sense, but I'm struggling a bit to get it working. My code is below, WMat is my world transform for drawing the object, and P1 is the ray starting point, and PDir is the ray direction, which I think have the right values. When I do these transforms, I get no intersections at all. Are there any good examples anywhere?

Thanks

InvWorld = Matrix.Invert(WMat)

P1.TransformCoordinate(InvWorld)
PDir.TransformCoordinate(InvWorld)

If DMesh.Intersect(P1, PDir) Then...


Share this post


Link to post
Share on other sites
The ray direction should be treated as a normal vector - therefore the TransformCoordinate should be changed to TransformNormal to just rotate it by the matrix. The ray start position, on the other hand, should be rotated and translated just like you have already written.

Share this post


Link to post
Share on other sites
I've seen two interpretations of "inverse transpose": First, like you said, inverts the matrix and then transposes it, effectively isolating the rotation part. Second, orthonormal1 rotation matrix can be inverted by taking it's transpose (because you essentially flip the space around all axes when taking the transpose). The first one is more general of these two.

I was never good at maths terms, even though I have a sharp understanding (if I do say myself [wink]) of the actual calculations. Didn't learn this from school, though...

1 Orthonormal: a matrix in which all it's basis vectors are perpendicular regarding each other, AKA uniform rotation.

Share this post


Link to post
Share on other sites
Thanks,
I am interested in the specializations of inverse transpose for when you need the worldIT, viewIT, projectionIT in shaders.

So would an orthonormal matrix be a normal matrix - oh, only with affine transformations, so projection matrix wouldn't be?

I haven't covered matrices in school either. Since I am 15, I am doing my GCSEs (in the acceleration set for maths ;-}). Still, we were revising straight lines graphs today, finding gradients, lengths and midpoints of lines etc. When I had recently been finding the length of quaternions with pythag and interpolating across a vector to find the collision point between to sphere - that was rather frustrating[grin]

Cheers + ratings!

Share this post


Link to post
Share on other sites
An orthonormal matrix's vectors defining the rotation (first 3x3 part for a 3d transform) are perfectly perpendicular to each others so that they form a perfect cube given any rotation if visualized as each vector defining a cube root. It has the advantage of being "symmetrical" (in lack of better word) along all axes of the transform, and therefore it's effect can be exactly inverted by simply transposing it.

Perspective projection matrix defines a more complex interaction with the values, so it can't be inversed by simply transposing. An ordinary view matrix can be decomposed using transposition, but you can't get the target vector from it because it doesn't exist in the matrix, even though it is used when constructing the matrix to determine the view rotation.

Share this post


Link to post
Share on other sites

This topic is 4657 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