Author Topic: MODULE: DrawAntialiased v1.1  (Read 6857 times)

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: MODULE: DrawAntialiased v1.1
« Reply #20 on: 07 Jul 2010, 09:15 »
I did, yes - as it says in the source code :)

Ah? I've read it and recognized the algorithm but didn't spot the comment. Selective vision! :-)

About the assumptions: Yes, there are definitely some assumptions to make, but I was wondering if some expert had already made them 20 years ago ;-)
 

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: MODULE: DrawAntialiased v1.1
« Reply #21 on: 07 Jul 2010, 09:41 »
One last question: Unfortunately, I can't test your line-drawing implementation myself. Did you run some speed tests? How does it compare to AGS' built-in DrawingSurface.DrawLine ? (I know that your one is antialiased and DrawLine is not, but I can compare yours with DrawLine x 3).

 

Kweepa

  • Mutated Guano Deviser
    • Best Innovation Award Winner 2009, for his modules and plugins
    •  
    • Kweepa worked on a game that was nominated for an AGS Award!
Re: MODULE: DrawAntialiased v1.1
« Reply #22 on: 09 Jul 2010, 01:13 »
(I know that your one is antialiased and DrawLine is not, but I can compare yours with DrawLine x 3).

x3? That's optimistic! My guess would be x200 - x500, given the amount of interpreted instructions that have to be run.

I put each in a loop (so there's some loop overhead too) drawing random lines between 0 and 64*sqrt(2) long.
Results:
AA 1360 lines/second.
DL 96928 lines/second.
So DrawLine is approximately 70 times faster.
Actually that's a surprisingly good result for DrawAntialiased. Hooray!
Still waiting for Purity of the Surf II

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: MODULE: DrawAntialiased v1.1
« Reply #23 on: 09 Jul 2010, 11:32 »
AA 1360 lines/second.
DL 96928 lines/second.

Woaw, I didn't expect that at all.
The reason why I was considering comparing AA and DLx3 is because I'm thinking of doing a fake AA using 2 grey lines and one white line (total: 3 lines). But considering the results, I could even afford plenty more gray lines...
 

Re: MODULE: DrawAntialiased v1.1
« Reply #24 on: 20 Jul 2010, 20:18 »
That's a mighty module!!
Is there any way to control the speed the lines are drawn with?

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: MODULE: DrawAntialiased v1.1
« Reply #25 on: 21 Jul 2010, 09:30 »
Is there any way to control the speed the lines are drawn with?

Slow it down, you mean? Slow down the drawing of individual lines, so that the player can see the steps of the drawing?
 

Re: MODULE: DrawAntialiased v1.1
« Reply #26 on: 21 Jul 2010, 10:14 »
Yes, that's what I mean. To draw an antialiased line from point a to point b step by step, slowly so the user can watch it. Like a track on a map, for example.

Gilbert

  • Local Moderator
  • * KILL* * KILL * * KILL *
    • Lifetime Achievement Award Winner
    •  
Re: MODULE: DrawAntialiased v1.1
« Reply #27 on: 21 Jul 2010, 10:20 »
This is just trivial. Something like (untested):
Code: Adventure Game Studio
  1. int ii=0;
  2. DrawingSurface* blah;
  3. while(ii<=100){
  4.   blah=Room.GetDrawingSurfaceForBackground();
  5.   blah.DrawAntialiasedLine(x1, y1, (x1*(100-ii)+x2*ii)/100, (y1*(100-ii)+y2*ii)/100, 0);
  6.   blah.Release();
  7.   Wait(1)
  8.   ii++;
  9. }
  10.  
« Last Edit: 21 Jul 2010, 16:04 by Gilbet V7000a »

Re: MODULE: DrawAntialiased v1.1
« Reply #28 on: 21 Jul 2010, 13:33 »
Thanks for replying so quickly!
I tried to implement your code like this:

Code: Adventure Game Studio
  1. ii=0;
  2. DrawingSurface* blah;
  3. while(ii<=100){
  4.   blah=Room.GetDrawingSurfaceForBackground();
  5.   blah.DrawAntialiasedLine(88.0, 65.0, (88.0*(100-ii)+65.0*ii)/100, (65.0*(100-ii)+15.0*ii)/100, 0);
  6.   blah.Release();
  7.   Wait(1)
  8.   ii++;
  9. }

But I get this message:
Type mismatch: cannot convert 'float' to 'int'

What's wrong?
« Last Edit: 21 Jul 2010, 16:03 by Gilbet V7000a »

Dualnames

  • Local Moderator
  • Rottwheelers
  • Pretty Badass
    • Dualnames worked on a game that was nominated for an AGS Award!
      Dualnames worked on a game that won an AGS Award!
Re: MODULE: DrawAntialiased v1.1
« Reply #29 on: 21 Jul 2010, 14:44 »
Code: Adventure Game Studio
  1. ii=0;
  2. DrawingSurface* blah;
  3. while(ii<=100){
  4.   blah=Room.GetDrawingSurfaceForBackground();
  5.   blah.DrawAntialiasedLine(88, 65, (88*(100-ii)+65*ii)/100, (65*(100-ii)+15*ii)/100, 0);
  6.   blah.Release();
  7.   Wait(1)
  8.   ii++;
  9. }

You used floats instead of integers
float of zero = 0.0
integer of zero = 0
No more military army stuff. I'm alive and back.

Re: MODULE: DrawAntialiased v1.1
« Reply #30 on: 21 Jul 2010, 15:37 »
Sorry, I already tried that. Now it's the other way round:

Type mismatch: cannot convert 'int' to 'float'

I think it's not possible to mix int and float in that progress line.

Gilbert

  • Local Moderator
  • * KILL* * KILL * * KILL *
    • Lifetime Achievement Award Winner
    •  
Re: MODULE: DrawAntialiased v1.1
« Reply #31 on: 21 Jul 2010, 16:03 »
Sorry, I missed the declaration part. ii should be an integer (I don't like floating point numbers :P). Original post updated.

Re: MODULE: DrawAntialiased v1.1
« Reply #32 on: 21 Jul 2010, 16:31 »
Yes, I declared ii as an integer, but it won't do the trick.
I don't like floating point numbers too  :P  But Steve's DrawAntialiasedLine function claims floats.
So it seems like you can't mix floats and ints in one calculation, like (float*(int-int)+float*int)/int for example  :(

Gilbert

  • Local Moderator
  • * KILL* * KILL * * KILL *
    • Lifetime Achievement Award Winner
    •  
Re: MODULE: DrawAntialiased v1.1
« Reply #33 on: 21 Jul 2010, 18:14 »
You can, but you need to use those inconvenient FloatToInt() and IntToFloat() functions.

All right. I've downloaded the module and seems that it requires float for the coordinates. :P (As I don't use modules I don't care to download them unnecessary I really need to.)

This may work instead:
Code: Adventure Game Studio
  1. int ii=0;
  2. DrawingSurface* blah;
  3. while(ii<=100){
  4.   blah=Room.GetDrawingSurfaceForBackground();
  5.   blah.DrawAntialiasedLine(x1, y1, (x1*(100.0-IntToFloat(ii))+x2*ii)/100.0, (y1*(100.0-IntToFloat(ii))+y2*IntToFloat(ii))/100.0, 0);
  6.   blah.Release();
  7.   Wait(1)
  8.   ii++;
  9. }
  10.  

Re: MODULE: DrawAntialiased v1.1
« Reply #34 on: 21 Jul 2010, 18:41 »
No, sorry, doesn't work. I'm still getting the same error message.
But never mind. I'm going to do this with rawdrawline, like here:

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=25664.0

It won't be antialiased, but that's ok.

Thank you very much for your time and help!!!
bye

Kweepa

  • Mutated Guano Deviser
    • Best Innovation Award Winner 2009, for his modules and plugins
    •  
    • Kweepa worked on a game that was nominated for an AGS Award!
Re: MODULE: DrawAntialiased v1.1
« Reply #35 on: 21 Jul 2010, 21:38 »
Don't give up... You are nearly there.
Code: Adventure Game Studio
  1. float x1 = 100.0;
  2. float y1 = 100.0;
  3. float x2 = 200.0;
  4. float y2 = 200.0;
  5. int ii=0;
  6.  
  7. DrawingSurface* blah;
  8. DynamicSprite *ds = DynamicSprite.CreateFromBackground();
  9. while(ii<=100)
  10. {
  11.   blah=Room.GetDrawingSurfaceForBackground();
  12.   blah.DrawImage(0, 0, ds.Graphic);
  13.   float t = IntToFloat(ii)/100.0;
  14.   float omt = 1.0 - t;
  15.   blah.DrawAntialiasedLine(x1, y1, omt*x1 + t*x2, omt*y1 + t*y2, 0);
  16.   blah.Release();
  17.   Wait(1);
  18.   ii++;
  19. }
  20. ds.Delete();
  21.  
Still waiting for Purity of the Surf II

Re: MODULE: DrawAntialiased v1.1
« Reply #36 on: 21 Jul 2010, 21:59 »
Wow, this looks complicated...

"Error: Floating point devide by zero" in DrawAntialiased.asc line 84:

Code: Adventure Game Studio
  1. (...)
  2.  
  3. [b]float gradient = dy / dx;[/b]
  4.  
  5. (...)

Edit:
my coordinates:
x1 = 88; y1 = 65;
x2 = 140; y2 = 15

in a 320x200 room.
« Last Edit: 21 Jul 2010, 22:03 by Adrian »

Gilbert

  • Local Moderator
  • * KILL* * KILL * * KILL *
    • Lifetime Achievement Award Winner
    •  
Re: MODULE: DrawAntialiased v1.1
« Reply #37 on: 22 Jul 2010, 01:52 »
It seems that the module cannot draw just a point then (as the divide by zero case is not isolated out).

Just set ii to 1 initially instead of 0.


Re: MODULE: DrawAntialiased v1.1
« Reply #38 on: 22 Jul 2010, 06:44 »
YES, THAT'S IT !!! Works perfectly, now!
Thank you very much, I would never have come there by myself!  :D

EDIT:
These antialiased lines look so sexy...!  ;D
« Last Edit: 22 Jul 2010, 09:42 by Adrian »

Re: MODULE: DrawAntialiased v1.1
« Reply #39 on: 22 Apr 2018, 23:55 »
Hey.



Just adding some modifications in the original, mainly removing the anti-alias for instead using pixel lines.

Rope Test example room

Updated, to demonstrate how to use. Now Rope has a GetGraphic() property, that passes the integer that points to the sprite, so you can apply it to an object, an overlay, a GUI or anything.

using Rope.Create(int rope_area_width , int rope_area_height, int rope_thickness = 1, int rope_color = 65535 )

you have to set the area, also you can set the color and the rope thickness.

Rope.scm - Rope packaged as a module.

Rope.ash - the .ash file , the header.

Rope.asc - the .asc file if you just want to read.

Maybe this modification is useful for someone.

Chicky asked for help getting it to work on the Discord chat, but if you noticed, I cheated by removing the anti-alias part.
If someone has a better understanding of DrawAntialiasedLine and can make it work in similar fashion with AGS 3.4.1 in an object in the room, it would be useful!