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.

AppGameKit Classic Chat / Draw to screen using getpointerx etc etc

Author
Message
Pumpkin Software
AGK Developer
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location: uk
Posted: 1st Feb 2016 17:33
Hi,

I have been finding a problem with a simple idea of drawing small 1x1 images to screen using getpointerstate(), getpointerx() commands etc etc when trying to draw a freehand line on screen when the screen is touch/movement.. It all works ok as a few simple lines of code is all that's needed but the problem is when you move your finger along at anything other than a snails pace it starts missing parts of the line, but fine, when slower, and ideas if the input updating is a bit slow? The problem is on pc and device.

Thanks
v2.0.14 Tier 1
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 1st Feb 2016 18:34 Edited at: 1st Feb 2016 18:35
If the screen is 1080 pixels high and you are running at 60FPS, then anything faster than 18 seconds to draw from top to bottom is too fast to record every pixel.
Additionally, you may be recording multiple pixels in one place if you go too slow.

I find the best way to draw a line like this is to record waypoints as you go. Then it doesn't matter how fast you draw the line.

* Decide on a reasonable distance per waypoint (I use 5 pixels).
* Each cycle, if the distance from the previous recorded point is 5 pixels or more, record the new point.
* Use either the 2D line command, or a stretched sprite to join the waypoints. I use stretched sprites.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Pumpkin Software
AGK Developer
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location: uk
Posted: 2nd Feb 2016 10:59
Hi BatVink,
I had a bit of screen mapping code in place to stop repeats, I tried 4x4 and 8x8 sprites but made the diagonals a bit jagged. I will give way points ago, there is always a work around.
Thanks
v2.0.14 Tier 1
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 2nd Feb 2016 11:35
Instead of drawing single pixels, draw a single pixel wide line from the last pointer position to the current pointer position, then make this position the last position and repeat.

This is how all drawing software draw their lines. Try it in MS paint, move the pointer quickly and watch as the lines become longer and more angular.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 2nd Feb 2016 13:33 Edited at: 2nd Feb 2016 13:35
I hate doing this, so fiddly, everytime I have to do it I end up drawing a blank on how it's done.

The chances are that you won't be able to use a standard line drawing function, especially if your using images, maybe you need soft edges etc.

So, you need to take the new cursor position and compare it with the last cursor position, and draw each pixel between them. I do this with interpolation, basically take the differences between coordinates and find the most significant one. Like... lets say XA YA XB and YB are the coordinates, and PX PY are the pixel cords you want.

DX#=XA-XB
DY#=YA-YB
If abs(DY#)>abs(DX#)
if DY#>0.0 then SY#=1.0 else SY#=-1.0
SX#=DX#/DY#
else
if DX#>0.0 then SX#=1.0 else SX#=-1.0
SY#=DY#/DX#
endif

So that gets the differences and sets the most significant axis to 1/-1, and the other axis to a multiplier.

The trick now is to step through all the iterations, and increment the other axis by...

PX#=XA
PY#=YA
for p=0 to D
inc PX#,SX#
inc PY#,SY#
dot PX#,PY#
next p

It's pseudo code, but hopefully you understand it. You basically take the 2 points and work out which axis you can increment by 1 or -1, and the other axis increments by a value between -1 and 1. If A=10,30 and B=20,10 the difference would be 10,-20.... so stepping through 20 pixels with Y as the significant axis, increasing Y by -1 and X by 0.5 for.
Pumpkin Software
AGK Developer
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location: uk
Posted: 3rd Feb 2016 12:14
Many thanks everyone.
v2.0.14 Tier 1
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Feb 2016 08:29
Not sure how different the memblocks are in AppGameKit from DBP, I haven't played with them in AppGameKit yet, but this snippet might help you if you're going for anti-aliased lines and other shapes:
https://forum.thegamecreators.com/thread/207987


Simple demo drawing lines with the mouse, well, sorta


"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 6th Feb 2016 00:43
Hi Pumpkin Software,

check out my thread for Doodle Draw:

https://forum.thegamecreators.com/thread/214589

It has some code pasted in there and help also from Paul. It might assist
The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
Pumpkin Software
AGK Developer
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location: uk
Posted: 6th Feb 2016 11:21
Thanks guys, food for thought
v2.0.14 Tier 1

Login to post a reply

Server time is: 2024-04-25 02:02:15
Your offset time is: 2024-04-25 02:02:15