Draggable object

Blitz3D Forums/Blitz3D Programming/Draggable object

Mr. Slat(Posted 2007) [#1]
This is going to be a re-post...but I could find exactly what I needed, so...

I wanted to drag an object, but how can I relate 2D to 3D coordinates?

I mean, How can I make the object move along with the mouse?

I was looking for a function(retrieving the new 3D coordinates from the 2D mouse coordinates) only, so that I could fit it in my game....

Sorry for any mistake.... English isn't my native language... :P


jfk EO-11110(Posted 2007) [#2]
Obviously you can move a 3d object witht he mouse only in 2 dimensions at a time. So I'd suggest to do a camerapick at the mouseposition when the user starts dragging. Get the entity he wants to drag and the (3D) Y position the Pick occurred/hit the entity. Now position an invisible (alpha =0) plane on this Y height. set the world and entities unpickable, the plane pickable. Now repeatly camerapick the plane at the new mouse position and calculate the distance to the original picked position, then reposition the entity at the original Y position, and at the X and Z position plus the mentioned distances.

You need a flipflop variable that will tell you if you're already dragging something, kind of:

(pseudocode only)
if mousedown=1
 if dragging=0
  initialize dragging stuff
  dragging=1
 endif
else
 if dragging=1
  end of dragging stuff
  dragging=0
 endif
endif

if dragging=1
 drag stuff
endif



Additionally you could use the mousewheel to alter the Y position.

PS I wouldn't be surprised if there is already some sourcecode in the code archives.


big10p(Posted 2007) [#3]
Yeah, I'm pretty sure there's something for this in the code archives. I *think* it's by BlitzSupport.

[edit] Wow, my memory actually worked! :)
http://www.blitzbasic.com/codearcs/codearcs.php?code=379


Moraldi(Posted 2007) [#4]
Setting all entities unpickable and vice versa is it a slow or not operation? (when there are hundreds of them)
Is there any way to calculate which coordinates are picked up on the plane you mentioned given the screen mouse position?


big10p(Posted 2007) [#5]
Not sure I understand. PickedX/Y/Z return the coords of a pick, if that's what you mean?


Moraldi(Posted 2007) [#6]
Given MouseX, MouseY and a plane in a 3D world is it possible to calculate which point is picked on the plane without use any pick command?


Moraldi(Posted 2007) [#7]
I am using the jfk-11110's method in my Unlimited Drop program but I want to avoid picking and unpicking objects when drag the cursor


big10p(Posted 2007) [#8]
Given MouseX, MouseY and a plane in a 3D world is it possible to calculate which point is picked on the plane without use any pick command?
Not that I know of. This is the type of thing picking was invented for. ;)


Moraldi(Posted 2007) [#9]
I have to search a C forum for a picking algorithm
Thanks big10p


big10p(Posted 2007) [#10]
OK, but I doubt you'll find anything faster/better than the inbuilt pick commands, TBH. They're coded in C++, afterall. I could be wrong, though. :)


jfk EO-11110(Posted 2007) [#11]
there are some linepick replacements, but actually it's a lot of work for almost nothing, the builtin Camerapick works well. If you have the scenes entities stored in an array or type, then it's easy to hide/show them. (Re-)Setting the pickmode is not a speed issue since you do it only at a mousedown and mouseup event.


Moraldi(Posted 2007) [#12]
Having in mind a discussion from another forum I thought something alternative:
I can create a second hidden camera too far from the main camera having no objects front of it.
In this case I can make camera picks from the hidden camera without changing the pick mode of objects