Sign in to follow this  

[.net] Drag 3d objects with mouse, I.E., convert 2d mouse coords to 3d coords

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

Hiya. I'm trying to figure out how to drag 3d objects with the mouse in the x/z plane, which basically boils down to converting 2d mouse coords to 3d coords. I'm finding lots of confusing and conflicting articles about this, most not specific to C#, and none which actually seem to work. Can anybody point me to some resources? I would like, in order of preference: 1. C# code that I can plug directly into my app and FORGET about 2. Code in another language which is fairly easy to convert to C# 3. Long and complicated articles explaining the mathematical theory behind what I'm trying to do. Thanks.

Share this post


Link to post
Share on other sites
umm, not exactly. I have picking implemented without a problem. But I need to DRAG objects after picking them. Picking gives me a ray with a direction that I can test against objects for intersections. I need something that returns 3d coordinates from mouse coordinates.

Share this post


Link to post
Share on other sites
Umm. you can't directly. The best you can get is a ray. The problem is that there is no way to directly convert 2d into 3d because you are missing a dimension.

Example, you have a 3d view of some room. There is a box in the center of the room. You pick the box and drag it down and to the right. So do you want to move the box down the y or closer to the camera on the z? There is no direct way to know by just using the 2d dimensions.

theTroll

Share this post


Link to post
Share on other sites
I got it. Thanks for trying.

ummm....not to be a jerk...well, Ok, I'm a jerk....but if you don't know the answer to a posted question, why bother replying at all? "you can't." Only discourages others who may know the answer from replying. There are a thousand people who've experienced the same dilemma...one of them has an answer that they are willing to share...why waste your own time with questions, guesses, and answers that are off the mark? Obviously you've never done what I needed to do...that's ok...I'll wait for somebody who has, or find them on another forum. I mean, c'mon, you either know the answer or you don't! Why take advice from somebody who doesn't know?

And of COURSE you can! Obviously assumptions have to be made for the missing data...maybe if viewing from overhead, move along the X/Z plane, if viewing from the side, move along the X/Y plane. "you can't" does not compute.

Share this post


Link to post
Share on other sites
I misread your original question, that is why I answered at first the way I did.

Quote:
Original post by danromeo
I need something that returns 3d coordinates from mouse coordinates.


The reason I answered the second way was because of what you asked. You wanted to take a 2d coordinate and make a 3d one out of it. You can't do that. Not directly. So how exactly do I not know what I am talking about?

As for doing this, you are correct I have never done that. Why? BECAUSE YOU CAN'T. Not the way you wanted to do it.

Of course you can do a top down view and do it. But that is not what you asked. So don't blame me for YOU not asking the question you really wanted the answer to.

theTroll

Share this post


Link to post
Share on other sites
Quote:
Original post by danromeoAnd of COURSE you can! Obviously assumptions have to be made for the missing data...maybe if viewing from overhead, move along the X/Z plane, if viewing from the side, move along the X/Y plane. "you can't" does not compute.
Maybe you mean that you want vectors in world space for the directions of up/down and left/right relative to the camera? If you want to drag your object right, you can take the normalized Right vector, multiply it by a distance, and then add it to the position of your object.

Getting those involves using your camera's up vector to get the Up vector and a cross product between the up and the camera's direction vector to get the Right vector.

Asking for 3D coordinates doesn't make much sense because a coordinate is a point. You can't drag with a point, you drag in a direction.

Share this post


Link to post
Share on other sites
Not blaming anybody for anything, guy.

I asked EXACTLY the question I needed an answer to.

<"YOU CAN'T"

That's funny, because it works GREAT! Maybe you meant "I can't"? C'mon..."you can't" is a defeatist way of saying "I don't know" (or an arrogant way of saying "I don't know, so it must not be possible"). Again...if you don't know, why bother replying?

Share this post


Link to post
Share on other sites
You take the Ray that you get from the picking operation and you calculate its intersection with the XZ plane.

However, this is a .NET forum. This forum is for asking questions about how to use the .NET class library or how to use language features in any of the .NET languages (VB, C#, C++/CLI, etc). This forum is not for asking how to implement design pattern XYZ in C#. If you don't understand the concepts of calculating Ray-Plane intersections, then this is a Math question and goes in "Math and Physics". If you don't understand how to implement Ray-Plane intersection in code versus standard mathematical notation, then this is a general programming question and goes in "General Programming". If you can figure out how to code an implementation of Ray-Plane intersections in another language, e.g. C++, but can't figure out how to translate that to C#, then you would have a question that would be specific to this forum.

And it's never good to ask for "code I can plug directly into my app". We're not doing your work for you.

Share this post


Link to post
Share on other sites

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