🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Determine Hit location on gizmo

Started by
2 comments, last by ilia.glushchenko 6 years, 3 months ago

I am currently working on setting up some gizmos for my level editor and am running into a bit of a snag and am not really sure how to proceed. When I get the hit location from the raycast, I would like to determine what part of the gizmo that the user has hit. I am looking for something that would work for each viewport. I believe it would be possible, just not sure how to pull it off.

What I am lookin for is when the user mouses over the gizmo it would change color in that area. For instance, if the user mouses over the x axis (red arrow) it would turn from red to white. It doesn’t have to be pixel perfect but I would like to find a single solution that would work in all viewports.

I was thinking that after I get the hit location, I could transform the hit location to match the inverse of the rotation of the camera and perform the checks from there. However, I don’t think that is correct and am not sure what steps I need to do from there.

Thank you,
Chaz H

Gizmo.png

Thank you,
Chaz
Advertisement

I would be thinking in terms of just calculate the position of the arrow heads of the gizmo in world space, or screen space, and just pick the mouse coords as a ray in world space or a point in screen space, and pick the nearest gizmo thingy / bounding box?

You can use the same matrices you use for rendering to get them into world space / screen space (same as software transforming a vertex).

I'm not sure if I got your question right. But I'll write it anyway, maybe some part of it would be helpful.

I don't think for it to work in every viewport is not even relevant here. Basically, what you have here is an MVP matrix, that provides you with space transformation for different camera positions and perspectives. The problem that you have is that you want to be able to take some MVP transformed primitive, find a point or a sector on it transform back into the model space and make something with this data, highlight an area or whatever. That's how I got that.

What I would do, I would cast a ray in the MVP space, the ray origin would be on the on the nearest frustum plane with respect to mouse coordinates, that ray would be normal to that plane. Then I would get a point of contact, if the ray hits the primitive, in the MVP space, and from this point, I could just take inverse MVP matrix and transform this point back to the model space. Then I would have my primitive and a point of contact that would be on the surface of this primitive. And now one I could do whatever I want with it, find the vertex I want to change, find the closest features of the primitive that I want to change. If you wonder how to do that, then it is a different question.

This topic is closed to new replies.

Advertisement