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 / line in 2d/3d space

Author
Message
Regnuar
17
Years of Service
User Offline
Joined: 25th Dec 2008
Location:
Posted: 13th Jul 2010 10:26 Edited at: 13th Jul 2010 10:30
I got a small problem, trying to make some sorda drawing tool, but i got problem even at the begining Well simply the issue is drawing line in 2d space between x1,y1 and x2,y2. When i move the position of y2 in this 2d space for example, it leaves the old line when i move it inside the program. The same issue does not follow in 3d.

here's a example code, try it in 3d space too.



How can i update end of the line without coloring the whole area?
blairgo
16
Years of Service
User Offline
Joined: 13th Jul 2010
Location:
Posted: 13th Jul 2010 11:06
Thank you for your update. In my opinion, i think this is very helpful for me.
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 13th Jul 2010 11:28
use the cls command at the start of your loop to clear the screen, or change the ink to the background color and draw over the old line, then change the ink back to the ink color and draw the line at the new position.

hope that helps

Regnuar
17
Years of Service
User Offline
Joined: 25th Dec 2008
Location:
Posted: 14th Jul 2010 08:12 Edited at: 14th Jul 2010 09:13
Sorry for late reply, i made cube 1,0 so it went to 3d space and made line drawing inside the loop, but now i got new issue. I'm trying to make end of the lines snap when they're close to each other so there would be a possibilty to make closed area. Well, no success this far, any idea how i can make the mouse snap to the nearest end?

code:


Sorry the code is a bit messy, since i quited too early yesterday. Also you can ignore the sprite commands, they'r not needed and you can select line drawing tool by pressing 1 (text appears "Johdon piirto" which means line drawing.

anyhow, if you like to use the sprite, it's attached.

EDIT: Oh, there's existing command "position mouse x,y", so problem solved

EDIT2: Oh, no it's not. The mouse still not snap to the end of the line, i also updated the code. Seems like the position mouse can't be forced to the sprite.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 14th Jul 2010 15:27
Ignore the idea about moving the mouse for snaping. Just do a distance check from your mouse to the points already made by other lines. If the distance is less than whatever snap distance you want then simply move the line's endpoint. If your mouse moves out of that "snap distance" then the line's endpoint goes back to the mouse.
The line's startpoint can be done the same way....

The fastest code is the code never written.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Jul 2010 14:46 Edited at: 15th Jul 2010 14:46
Moving the mouse for snapping is fairly common in CAD apps but not everyone likes it. If you decide to do it anyway try doing like Hawkblood said... something like this to check for each possible snap-point:



...not checked...

Regnuar
17
Years of Service
User Offline
Joined: 25th Dec 2008
Location:
Posted: 16th Jul 2010 07:52
Cheers, gonna try it i get the idea from the cad, working with it 8h/5d.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 16th Jul 2010 08:29
if it's 2d you don't really need any euclidean distance checking.

Let me come up with some good code for snapping. brb


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
Regnuar
17
Years of Service
User Offline
Joined: 25th Dec 2008
Location:
Posted: 16th Jul 2010 08:36
can't wait to hear you soon
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 16th Jul 2010 15:37
Neuro Fuzzy is technically correct, you could simply have an if statement:

I'm not sure about the abs(), I assume DBP has an absolute value function....? But, that's the other method.

The fastest code is the code never written.

Login to post a reply

Server time is: 2026-07-25 16:20:08
Your offset time is: 2026-07-25 16:20:08