Jump to content
  • Advertisement
Sign in to follow this  
Powzoom

Draging an object in 3d

This topic is 4674 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, Im trying to figure out how i can drag a mesh in my 3d world with the mouse. I've found plenty of info on ray picking but nothing that seems to help me with this topic. I can select the object, but I'm not sure how to map the movement of the mouse to the object I'm dragging. Also, I want to restrict the movement of the object to just 2 axies. Any info at all would be great. I've searched for an anwser to this question using google n found nada. Please help if u can. Thnx.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Powzoom
Hiya,

Im trying to figure out how i can drag a mesh in my 3d world with the mouse. I've found plenty of info on ray picking but nothing that seems to help me with this topic. I can select the object, but I'm not sure how to map the movement of the mouse to the object I'm dragging. Also, I want to restrict the movement of the object to just 2 axies. Any info at all would be great. I've searched for an anwser to this question using google n found nada. Please help if u can. Thnx.
You say you want to restrict the motion to 2 axes - which two axes do you have in mind? (Options that immediately come to mind are the cardinal plane most aligned to the screen, or an arbitrary screen-aligned plane.)

I'm guessing there are standard 'interface rules' for this, but I haven't done much work with modeling programs so I'm not sure what the usual approach would be.

Share this post


Link to post
Share on other sites

I was refereing to the x n y axis. I'm trying learn the basics of a 3d graphics engine by making a 3d chess program. I already had chess piece models I made with 3ds max so I figured y not try a chess game. The game right now basicly works, except for any AI, but I would like to be able to "pick up" one of the pieces and move it to another square on the board. I have the picking rays down. I can move a piece from one square to another now but it just "jumps" there. I want to no how I can pick it up and drag it with the mouse.

Share this post


Link to post
Share on other sites
How about just intersecting the ray with the plane of the chess board as you drag, and dynamically updating the position of the piece frame by frame? Of course you'll be able to drag the piece through other pieces, which you may or may not want. In any case, when you release the mouse button, you could either move the piece to the nearest square if it's a legal move, or back to the original square if not. Just an idea.

Share this post


Link to post
Share on other sites
I think jyk has the right idea.

There are many different ways you can handle dragging (we've been implementing a few different types at work). However, as you have a simple case of only moving them along a simple plane (the chess board) you can take a simple approach.

Each frame, calculate the intersection point of the mouse ray with the board. Find the difference between the current frame and the previous frame's intersection point. Move the piece by this difference vector.

You have a couple of options for which square to place the piece in when the mouse is released. Personally I'd find the square the centre of the piece is in and place it in that square. The other option is to find the square the mouse ray intersects with.

Share this post


Link to post
Share on other sites
Hey,

Thnx for the replies. How do find the point of intersection in 3d space? I understand how to cast the ray n find out which object it intersects first but I'm not sure how to find the coordinate in world space that the intersection occured.

Share this post


Link to post
Share on other sites
i saw a couple of chess games before , when you make a move you try pointing to the square where you want the piece to move , when the sqare you selected is legal , they make all the sqares between the piece and that square Green and when you realese , the piece is livitated, Flys there and goes down , so if every Square on your chess board isn't an object then you will have to decide thier coodinates , you could make a square class with members Left,Top,Width&Height (these might not be so useful cause all the squares are probably the same size) ,Name e.g A1,B3 something like that , so when your about to move an object you could trace the position of the mouse and compute the square its over from a relation like this
CurSquare.left = Mouse.x / SquareWidth
CurSquare.top = Mouse.y / SquareHeight
this is not so perfect it needs some work cause the result wouldn't be so precise (i.e Mouse.x might not be exactly at the begining of a square) but you could find the nearest square , hope this helped

Share this post


Link to post
Share on other sites
For finding the point of intersection with the board, google 'ray plane intersection'.

[Edit: the equation for ray-plane intersection can be found in this thread, among other places.]

[Edited by - jyk on January 1, 2006 12:40:01 PM]

Share this post


Link to post
Share on other sites
The best thing is to enclose the 3d mesh in a boundingvolume, cuz for what i understand you want to know which mesh was selected and not the exact triangle of which the mesh may consist...

Cuz with a bounding box you would have to perform only the "plane-intersection" test of the boundingbox instead of the 100's or 1000's intersection tests with true mesh.

For the movement part... you can use a internal axes system for the mesh (like right,up,front) so if you got a
mouse movement to the left:
mesh->move(-elapsed * right_vector * mouse_movementx)
Mouse movement to the right:
mesh->move(elapsed * right_vector * mouse_movementx)
Mouse movement up:
mesh->move(elapsed * up_vector * mouse_movementy)
Mouse movement down:
mesh->move(-elapsed * up_vector * mouse_movementy)

etc.

Greetz
Drake

Share this post


Link to post
Share on other sites
Hi again,

Ok... I still can't figure out how to find the point of intersection. I've read the link suggested but it just hurts my brain n doesnt seem to anwser my question. At some point, I need a vector containing the coordinates where the intersection occured. I know which mesh the mouse ray intersected, but at what point did this happen at? Any code or further info would help lots. I'm using c++ n directX 9.

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!