MODULE: DrawAntialiased v1.1

Started by Kweepa, Tue 12/01/2010 08:43:30

Previous topic - Next topic

Monsieur OUXX

Quote from: SteveMcCrea on Wed 07/07/2010 00:37:04
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

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

Quote from: Monsieur OUXX on Wed 07/07/2010 09:41:45
(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

Quote from: SteveMcCrea on Fri 09/07/2010 01:13:27
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...
 

Adrian

That's a mighty module!!
Is there any way to control the speed the lines are drawn with?

Monsieur OUXX

Quote from: Adrian on Tue 20/07/2010 20:18:59
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?
 

Adrian

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

#27
This is just trivial. Something like (untested):
Code: ags

int ii=0;
DrawingSurface* blah;
while(ii<=100){
  blah=Room.GetDrawingSurfaceForBackground();
  blah.DrawAntialiasedLine(x1, y1, (x1*(100-ii)+x2*ii)/100, (y1*(100-ii)+y2*ii)/100, 0);
  blah.Release();
  Wait(1)
  ii++;
}

Adrian

#28
Thanks for replying so quickly!
I tried to implement your code like this:

Code: ags
ii=0;
DrawingSurface* blah;
while(ii<=100){
  blah=Room.GetDrawingSurfaceForBackground();
  blah.DrawAntialiasedLine(88.0, 65.0, (88.0*(100-ii)+65.0*ii)/100, (65.0*(100-ii)+15.0*ii)/100, 0);
  blah.Release();
  Wait(1)
  ii++;
}


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

What's wrong?

Dualnames

Code: ags
ii=0;
DrawingSurface* blah;
while(ii<=100){
  blah=Room.GetDrawingSurfaceForBackground();
  blah.DrawAntialiasedLine(88, 65, (88*(100-ii)+65*ii)/100, (65*(100-ii)+15*ii)/100, 0);
  blah.Release();
  Wait(1)
  ii++;
}


You used floats instead of integers
float of zero = 0.0
integer of zero = 0
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Adrian

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

Sorry, I missed the declaration part. ii should be an integer (I don't like floating point numbers :P). Original post updated.

Adrian

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

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: ags

int ii=0;
DrawingSurface* blah;
while(ii<=100){
  blah=Room.GetDrawingSurfaceForBackground();
  blah.DrawAntialiasedLine(x1, y1, (x1*(100.0-IntToFloat(ii))+x2*ii)/100.0, (y1*(100.0-IntToFloat(ii))+y2*IntToFloat(ii))/100.0, 0);
  blah.Release();
  Wait(1)
  ii++;
}


Adrian

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

Don't give up... You are nearly there.
Code: ags

float x1 = 100.0;
float y1 = 100.0;
float x2 = 200.0;
float y2 = 200.0;
int ii=0;

DrawingSurface* blah;
DynamicSprite *ds = DynamicSprite.CreateFromBackground();
while(ii<=100)
{
  blah=Room.GetDrawingSurfaceForBackground();
  blah.DrawImage(0, 0, ds.Graphic);
  float t = IntToFloat(ii)/100.0;
  float omt = 1.0 - t;
  blah.DrawAntialiasedLine(x1, y1, omt*x1 + t*x2, omt*y1 + t*y2, 0);
  blah.Release();
  Wait(1);
  ii++;
}
ds.Delete();
Still waiting for Purity of the Surf II

Adrian

#36
Wow, this looks complicated...

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

Code: ags
(...)

[b]float gradient = dy / dx;[/b]

(...)


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

in a 320x200 room.

Gilbert

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.


Adrian

#38
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

eri0o

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!

SMF spam blocked by CleanTalk