Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Draging object in 3D space

Author
Message
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 22nd Sep 2012 19:44 Edited at: 22nd Sep 2012 19:49
Hey everybody,

I'm wondering how to approach dragging an object with the mouse.

Example: I have a camera that can move and rotate in a 3D space (free roaming FPS). I have a single box object. I would like to move that object by holding down a mouse button, but relative to the camera angle (in other words, no matter what angle the camera has on the cube, the object will follow the direction of the mouse cursor.

Any suggestions on how to approach something like this?

Thanks!

Regards Sph!nx
www.mental-image.net
The Weeping Corpse
14
Years of Service
User Offline
Joined: 19th Sep 2011
Location: United Kingdom
Posted: 22nd Sep 2012 21:54
It would boil down to a 2D -> 3D conversion of some sort but until you give more info it's difficult to give you any meaningful help.

how do you want the object to move?

mouse up = move object away? or move object up?
mouse down = move object closer? or move object down?

I would do the following. When the object is first clicked for dragging, create a plane parallel to the camera that intersects the objects origin. Then as the mouse is moved in real time use a ray\plane intersect test to convert the mouse XY into a world XYZ coordinate (the intersect point on the plane). Then position the object at that world XYZ.

The orientation of the plane would determine how the mouse Y coordinate is converted into world Y or world Z.

Stab in the Dark software
Valued Member
23
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 23rd Sep 2012 02:15
Try this link.
It is good code I use a variation of it.

http://forum.thegamecreators.com/?m=forum_view&t=154169&b=6


[img][/img]


WindowsXP SP3,Vista,Windows 7 SP1, DBpro v7.7RC7
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.
Kezzla
17
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 23rd Sep 2012 05:21
That's bazaar, i was just working on the exact same problem last night.

i solved it by recording the objects original yangle data in a variable

I then rotate the object to the camera y angle, then move object left right forward backward, and then at the end of the routine i rotate the object back to its original position. works a treat and little maths involved.

I got a similar project going, i walk around my environment with mouselook and place objects, then i use the arrowkeys to move them around and the left right forward and back need to be relative to the camera angle.

Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 23rd Sep 2012 15:14 Edited at: 23rd Sep 2012 15:15
Thanks guys!

@ The Weeping Corpse
Like this...
Quote: "
mouse up = move object away
mouse down = move object closer"


To move the object up/down would be mouse up/down but while holding down CTRL or something.


@ Stab in the Dark software
Thanks for the link! It's a little more complex than what I need but it's the best example I have so far. I might be able to extract the info I need.

Regards Sph!nx
www.mental-image.net

Login to post a reply

Server time is: 2026-07-10 22:28:34
Your offset time is: 2026-07-10 22:28:34