The Daily Click ::. Forums ::. Klik Coding Help ::. How to draw the way between two points?
 

Post Reply  Post Oekaki 
 

Posted By Message

Tharky



Registered
  05/10/2009
Points
  30
10th February, 2011 at 20:39:36 -

Hello guys, I just encountered a problem about "drawing the way from Point A to Point B".

I tried many ways to do that, changing the angle of a 1 pixel thick bar, looping and drawing 1 pixel until it reaches Point B...

But it doesn't give me the best look / graphics.

 
Newbie in Lua +
5 year experience with MMF =

Still nothing...

GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
10th February, 2011 at 22:58:25 -

Try turning anti-aliasing on with that 1-pixel thick bar and make sure the rotation quality is 1.

I've achieved this by scaling a bar that was a few pixels thick between two points, but I don't remember if I tried it with only 1 pixel.

 
n/a

Tharky



Registered
  05/10/2009
Points
  30
10th February, 2011 at 23:12:13 -

Actually, I haven't managed to do the precise line...

 
Newbie in Lua +
5 year experience with MMF =

Still nothing...

~Matt Esch~

Stone Goose

Registered
  30/12/2006
Points
  870

VIP Member
10th February, 2011 at 23:19:21 -

I made this example a while ago

http://mattesch.info/click/linedraw.zip

 
http://create-games.com/project.asp?id=1875 Image


Tharky



Registered
  05/10/2009
Points
  30
10th February, 2011 at 23:24:02 -


Originally Posted by ~Matt Esch~
I made this example a while ago

http://mattesch.info/click/linedraw.zip

Oh, Thanks a lot for the example Matt! This was exactly the thing I've asked. Thanks a lot.

Sorry, I don't have any point to give you a trophy

 
Newbie in Lua +
5 year experience with MMF =

Still nothing...

GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
11th February, 2011 at 16:37:50 -


Originally Posted by ~Matt Esch~
I made this example a while ago

http://mattesch.info/click/linedraw.zip

Woah thats a little overly-complicated, but it works I guess . Why does the line jump around the line is drawn anywhere to the left?

 
n/a

~Matt Esch~

Stone Goose

Registered
  30/12/2006
Points
  870

VIP Member
11th February, 2011 at 19:00:21 -

How would you simplify it? I do have a 1 line event that does it as well by taking dot products and wedge products to compute the angle of rotation. I am not sure what you mean by jumping around. Perhaps you refer to the slight unavoidable inaccuracy in the calculation?

 
http://create-games.com/project.asp?id=1875 Image


GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
11th February, 2011 at 21:45:59 -

I dunno. You're obviously more well versed in math than I am, but the line jumps around pretty bad when the line is drawn towards the left/upper left region of the screen. I just remember the one I made used a less conventional - possibly longer yet a bit simpler method and it worked flawlessly. I'll see if I can dig it up, but I really don't think I have it anymore .

 
n/a

~Matt Esch~

Stone Goose

Registered
  30/12/2006
Points
  870

VIP Member
11th February, 2011 at 22:03:46 -

Perhaps this is more accurate.

http://www.mattesch.info/click/linedraw2.zip

 
http://create-games.com/project.asp?id=1875 Image


GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
11th February, 2011 at 22:08:18 -

Thats much much much better .

I actually came up with a method, but MMF loops aren't working properly for some reason - ie: they continue to run even if told to stop or even if a condition is no longer met =/. This happens to me randomly. Oh well- not like Its needed anymore anyways .

Nice work.



 
n/a

~Matt Esch~

Stone Goose

Registered
  30/12/2006
Points
  870

VIP Member
11th February, 2011 at 22:15:57 -

Well you say it's not needed, but some people might appreciate a simpler approach. Some people might be intimidated by expressions like


(((LeftY( "Line" )-RightY( "Line" ))/Abs(LeftY( "Line" )-RightY( "Line" )))+0.5)/Abs(((LeftY( "Line" )-RightY( "Line" ))/Abs(LeftY( "Line" )-RightY( "Line" )))+0.5)*ACos((RightX( "Line" )-LeftX( "Line" ))/Sqr(((RightX( "Line" )-LeftX( "Line" ))*(RightX( "Line" )-LeftX( "Line" )))+((RightY( "Line" )-LeftY( "Line" ))*(RightY( "Line" )-LeftY( "Line" )))))

I wouldn't really condone a brute force rotate-until-it's-right approach though.


 
http://create-games.com/project.asp?id=1875 Image


GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
11th February, 2011 at 22:45:51 -

Yeah I don't know formulas like that so I take my own way out x_x. I'm really not a fan of workarounds, but when I can't comprehend whats going when coding something the proper way I sometimes have no choice.

I just recently learned how to halfway use basic trig properly thanks to the atan2 function. I'm awful with stuff like that.

Edited by GamesterXIII

 
n/a

Jenswa

Possibly Insane

Registered
  26/08/2002
Points
  2723
12th February, 2011 at 22:08:10 -

I would go with the Bresenham Line algorithm, since that's with what I am playing these days.

But basically you need the slope to hop from spot to spot, and the slope is dy/dx where
dx = the horizontal distance between the two points and dy = the vertical distance between the two points.

Or read the wiki at http://en.wikipedia.org/wiki/Slope

Maths is fun, but those expressions in mmf aren't.

 
Image jenswa.neocities.org

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49667

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
12th February, 2011 at 22:31:22 -

This will help with mmf math

http://create-games.com/download.asp?id=7421

I use this all the time.

 
n/a

GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
13th February, 2011 at 00:44:43 -


Originally Posted by UrbanMonk
This will help with mmf math

http://create-games.com/download.asp?id=7421

I use this all the time.



Thanks, this is actually an amazing little app.

I am a retard when it comes to using "other peoples work." I know this stuff has been around for ages, code is somewhat supposed to be shared, not protected, and that the work can't necessarily be tied to any one individual, but I am really weird (ieumb!).

I guess I'll have to stop being dumb and just learn to deal with it and just give credit where its due .

 
n/a
   

Post Reply



 



Advertisement

Worth A Click