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 Discussion / Help With Horrid Theory (just theory please x_x) - Select > Click > Drag > Place 3D Object

Author
Message
James McGlocken
17
Years of Service
User Offline
Joined: 29th Jan 2008
Location: In The Beautiful Mountains of Vermont
Posted: 2nd Feb 2008 16:38
I need some theory on the clicking and dragging of a 3d object.
Not necessarilly code, but just theory for now. What I would like to have is:

[u]Select[u] - > Click on 3D Object while Not-Selected: self explanitory

[u]Click and Drag[u] -- > Clicking while Selected: while left click is held down move the object with some mathematical equasion involving the MouseMoveX and MouseMoveY variables (don't know if that's correct dB)

[u]Place[u] ---- > Not-Clicking while Selected: (though the object is still selected)

PHP Programming, Music Composition
James McGlocken
17
Years of Service
User Offline
Joined: 29th Jan 2008
Location: In The Beautiful Mountains of Vermont
Posted: 2nd Feb 2008 18:03
I have to mention also, if it's alright, that there are two options to choose from when moving a box.

XYmove=0 - means that when you drag the mouse up and down it modifys the objects Z-position

XYmove=1 - means that when you drag the mouse up and down it modifys the objects X-position

This is just to clear things up, and to clearify that I'm not asking for the theory behind a gizmo (3d studio max object selector, rotator, scaler and positioner)

PHP Programming, Music Composition
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 2nd Feb 2008 18:40 Edited at: 2nd Feb 2008 18:42
The 3D object's position is a single point, so to make it easier for the user to select it you should detect an area around this point, the more precise calculations you perform to create this area will make your program more accurate.

Next you need to check for mouse clicks.

The easiest way to move the object is to change its position (if the mouse is clicked and pointer is inside the detection area) depending on the movement of the mouse. MouseMoveX() and MouseMoveY() are correct

I have to go to work now but unless someone else steps in I'll explain a more detailed version later.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 2nd Feb 2008 19:50
Unlike DBPro, DBC has no Pick Object command so the biggest hurdle is getting your program to detect which object the user is clicking on.

You do however have the OBJECT SCREEN X() and OBJECT SCREEN y() functions which return the 2D X and Y screen positions of a given object.

So, if you know that your objects have numbers between 1 and 100 then a For..Next can run through them and get their X and Y screen positions in turn - each time, comparing the results with the current Mouse X and Y co-ordinates.

Whichever object has the closest Screen X and Y values to the X/Y mouse position when the button was clicked is the selected object.

Dragging is best done with the mouse button held down. Normally you would move on the X axis with MouseMoveX() and on the Z axis with MouseMoveY().

To move an object along the Y axis it's generally done by using either the right mouse button or the left one in conjunction with a key - such as the shift key.

I've knocked together the following short snippet to point you in the right direction:



TDK_Man

James McGlocken
17
Years of Service
User Offline
Joined: 29th Jan 2008
Location: In The Beautiful Mountains of Vermont
Posted: 2nd Feb 2008 21:56
Thanks TDK.

You say that DBPro has a Pick Object command!!?? No! ;-(

The only part of the code I don't understand is the mathematical equasion involved:

Quote: "Dist=sqrt((mx-objx)^2+(my-objy)^2)"


Even though I know what it is meant to do is

I have made my own way for everything, even though the code is completely elementary, please have a look:



I'll be improving this using the snippet you have just given me (shift for XY movement rather than XZ)

PHP Programming, Music Composition
tha_rami
19
Years of Service
User Offline
Joined: 25th Mar 2006
Location: Netherlands
Posted: 3rd Feb 2008 07:11
The equation is the Pythagorean theorem.

In a triangle with one 90 degree corner:
a^2 + b^2 = c^2

Thus:
c = sqrt(a^2 + b^2).

Or, maybe:
dist = sqrt(xoffset^2 + yoffset^2)


A mod has been erased by your signature because it was larger than 600x120
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 4th Feb 2008 17:49 Edited at: 11th Aug 2010 23:06
You can overcome the lack of ray intersection in standard DarkBasic (without mem blocks) via using the object collision commands. There's a few examples that show how to do on my site. As well as selection and positioning in 3d space with the mouse. See 3D Object Positioning With Mouse & 3D Pick Object Selection Code

http://www.dbcode.underwaredesign.com/

Comrade Robski
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location:
Posted: 4th Feb 2008 19:02 Edited at: 4th Feb 2008 19:03
Quote: "The only part of the code I don't understand is the mathematical equasion involved:

Quote: "Dist=sqrt((mx-objx)^2+(my-objy)^2)""


The SQRT command is pretty slow - better to leave it out - it is just as easy to compare the distance^2 of two objects as it is the distance.

Here's what I mean (modifying TDK's code):

James McGlocken
17
Years of Service
User Offline
Joined: 29th Jan 2008
Location: In The Beautiful Mountains of Vermont
Posted: 6th Feb 2008 00:52
Quote: "The equation is the Pythagorean theorem.

In a triangle with one 90 degree corner:
a^2 + b^2 = c^2

Thus:
c = sqrt(a^2 + b^2).

Or, maybe:
dist = sqrt(xoffset^2 + yoffset^2)
"


thanks rami. I'll be sure to look that up right away.

Quote: "You can get around the lack of ray intersection in standard DB (without mem blocks) via using the object collision commands. There's a few examples that show how to do on my site. As well as selection and positioning in 3d space with the mouse. See 3D Object Positioning With Mouse & 3D Pick Object Selection Code "


Thanks you for the link Kevin. I've seen and looked around at a lot of your code already. This help even more.

Quote: "The SQRT command is pretty slow - better to leave it out - it is just as easy to compare the distance^2 of two objects as it is the distance.

Here's what I mean (modifying TDK's code):"


Thank you for the snippet Robski. It seems that I will definitely have to manage the speed of the program if I'm working with arrays that are storing the Position, Scale, and Angle of objects.

PHP Programming, Music Composition

Login to post a reply

Server time is: 2025-06-04 02:13:34
Your offset time is: 2025-06-04 02:13:34