Author Topic: Lineto to draw a line as the finger goes - what is wrong ??  (Read 3846 times)

MnM

  • Guest
Lineto to draw a line as the finger goes - what is wrong ??
« on: August 21, 2012, 02:20:39 pm »
Hi
I am trying to draw a line along the user's finger drag path.
Created a Draw surface, added Ontouch and just used DrawLineTo ( code attached )
On Windows , with a mouse, it works like expected. On iPad,however, it is pretty strange.
The line is strange and streaky. Although the general direction of the line does indeed follow my finger, there are streaks and interruptions all over the line. Image attached.
You can see this is not a DrawLineTo problem . the first line segment ,where I set a point programmatically, the line was drawn to there as expected...
I guess something in touch coordinates reporting is weird on the actual device
Another weird thing is that the streaks are very thin in comparison to the pen widt (40)

wanted to get an advice before starting coordinates logging...

MnM

  • Guest
Re: Lineto to draw a line as the finger goes - what is wrong ??
« Reply #1 on: August 21, 2012, 02:31:07 pm »
Now with the code and the screen shot
btw : the device is ipad new

int OnWholeScreenTouch( int id,
                  int event,
                  int x,
                  int y )
{
   if ( event < 3 ) // down or move
   {
   
      DrawLineTo(TrailSurface,x,y );
   }
      return 0;
}
void AppMain()
{
   LandscapeMode();
   TrailSurface = DrawAdd (0,0,500,500);
   TouchAdd(0,0,1000,700,OnWholeScreenTouch,WHOLE_SCREEN_TOUCH);

   CurrentPathColor = 0xFF;
   // Set up my draw colors and pen width...
   DrawSetColor(TrailSurface, CurrentPathColor);
   DrawSetFillColor(TrailSurface, 0x0000FF00);
   DrawSetPenWidth(TrailSurface, 90);

}

Thanks

MnM

  • Guest
Re: Lineto to draw a line as the finger goes - what is wrong ??
« Reply #2 on: August 22, 2012, 12:58:55 am »
update
i found out it is the fault of DrawLineTo. I was trying to draw a thick line ( 40 pixels wide ) and it just freaked out.
When back to pen width 1 - everything is ok .

Anyone any idea why ? Probably algo difficulties to draw a thick line in such a short distance ?

Should I use Poly ? if yes - why would that be different ?

And in any case - how all those finger-draw applications do that ?

thanks

tim

  • Administrator
  • Hero Member
  • *****
  • Posts: 1595
  • Karma: +11/-1
    • View Profile
    • DragonFireSDK
Re: Lineto to draw a line as the finger goes - what is wrong ??
« Reply #3 on: August 22, 2012, 02:13:40 pm »
Using a Draw surface is not optimal for this type of app.  There is a limitation on how many objects can be drawn to the surface and doing stuff like this will run you out of things that can be drawn really quickly.

Instead, you might want to consider using a single Bitmap area and manipulating the individual pixels...
Tim Sommers
DragonFireSDK Team

MnM

  • Guest
Re: Lineto to draw a line as the finger goes - what is wrong ??
« Reply #4 on: August 23, 2012, 11:06:59 am »
Hi Tim
Thanks for the suggestion
Just tried it.  Same behavior, unfortunately.
As soon as the line goes thicker than just a couple of pixels, and as long as the destination point of the DrawTo are pretty close - the line on the device is funky :). On windows the line is ok both with draw and bitmap surfaces...
Could you think of a workaround please ? I am at a dead end :(

Thanks in advance

tim

  • Administrator
  • Hero Member
  • *****
  • Posts: 1595
  • Karma: +11/-1
    • View Profile
    • DragonFireSDK
Re: Lineto to draw a line as the finger goes - what is wrong ??
« Reply #5 on: August 24, 2012, 08:42:51 am »
Can you send me a short code sample that reproduces the issue?  I'll take a look at it and get back with you...

Thanks,
Tim Sommers
DragonFireSDK Team

MnM

  • Guest
Re: Lineto to draw a line as the finger goes - what is wrong ??
« Reply #6 on: August 24, 2012, 01:42:49 pm »
Hi Tim
In one of my posts above there is the code. that's all there is to.
If you build and try drawing with your finger you will see the behavior
Or do you want me to prepare a build.zip ?

Thanks

tim

  • Administrator
  • Hero Member
  • *****
  • Posts: 1595
  • Karma: +11/-1
    • View Profile
    • DragonFireSDK
Re: Lineto to draw a line as the finger goes - what is wrong ??
« Reply #7 on: August 28, 2012, 07:49:26 am »
Hi, MnM,

I thought that you said you also had an issue using the Bitmap surface?  The code above is using a Draw surface instead, so I have to admit to being a little confused...

Thanks,
Tim Sommers
DragonFireSDK Team

MnM

  • Guest
Re: Lineto to draw a line as the finger goes - what is wrong ??
« Reply #8 on: August 28, 2012, 01:04:48 pm »
Hi Tim

I am now confused too. Was trying to reproduce the code with the bitmap but realized that DrawLineTo does not even work with a surface which is not a Draw surface ... Strange. I now have no idea and recollection what I was building my argument upon when claiming the problem exists with the Bitmap. I clearly remember playing around with the Bitmap but the rest is just blured .... My bad ! Sorry. Crazy days ...

The DrawLineTo is not supposed to work with Bitmap, right ?

if this is correct - could you please just check out the Draw ?
I failed to find a simple C++ class which would give me a smooth line functionality so I can apply it to Bitmap surface and draw a line pixel b y pixel. And I certainly dont have the time to write one on my own.

Thanks

tim

  • Administrator
  • Hero Member
  • *****
  • Posts: 1595
  • Karma: +11/-1
    • View Profile
    • DragonFireSDK
Re: Lineto to draw a line as the finger goes - what is wrong ??
« Reply #9 on: August 31, 2012, 08:45:12 am »
DrawLineTo() is for drawing lines on a Draw surface and you're right- it doesn't work with Bitmap surfaces.  What I was trying to suggest doing was something along these lines:

Code: [Select]
#include "DragonFireSDK.h"

int MyBitmap;

int OnTouch(int id, int event, int x, int y)
{
    BitmapSetPixel(MyBitmap,x,y,0x00FF00);
    BitmapSetPixel(MyBitmap,x-1,y-1,0x00FF00);
    BitmapSetPixel(MyBitmap,x+1,y+1,0x00FF00);
    BitmapUpdate(MyBitmap);
    return(id);
}

void AppMain()
{
    MyBitmap=BitmapAdd(0,0,320,480);
    TouchAdd(0,0,320,480,OnTouch,1);
}
 
void OnTimer()
{
}

void AppExit()
{

}

This is a rather simple (and crude) example of how to draw on a Bitmap surface in response to the user moving their finger, but it gets the idea across.  I simply have a bitmap surface with a touch area over it and where ever the user touches, I draw some pixels...

I hope this helps!
Tim Sommers
DragonFireSDK Team

MnM

  • Guest
Re: Lineto to draw a line as the finger goes - what is wrong ??
« Reply #10 on: September 03, 2012, 04:08:11 am »
Hi Tim
Thanks
I already implemented something similar.
Since I need to draw rather a thick line - I am now playing with drawing filled circles on each touch
It has a lot of problems, I am using a Bitmap and brought in some classes for circles drawing but this is a nightmare to make it work properly and so that the user does not feel that it is a "fake"

Does your reply mean that DrawLineTo indeed has a problem in the current release ?

thanks

nednones

  • Guest
Re: Lineto to draw a line as the finger goes - what is wrong ??
« Reply #11 on: September 04, 2012, 12:01:43 am »
Could you not just generate an object, so instead of filling in a circle it takes the centre point of your touch and calculates the approximate width of the line required on the bitmap to draw you a line. You could calculate the angle of the swipe and then fill in the areas around that swipe but adjust the area by the angle of the swipe?

tim

  • Administrator
  • Hero Member
  • *****
  • Posts: 1595
  • Karma: +11/-1
    • View Profile
    • DragonFireSDK
Re: Lineto to draw a line as the finger goes - what is wrong ??
« Reply #12 on: September 05, 2012, 12:20:32 pm »
Does your reply mean that DrawLineTo indeed has a problem in the current release ?

No.  It means that there are set limits on how many things can be drawn to an individual Draw surface.  With a Bitmap surface, you have full control over every pixel in the area, so the limits above go away...
Tim Sommers
DragonFireSDK Team

MnM

  • Guest
Re: Lineto to draw a line as the finger goes - what is wrong ??
« Reply #13 on: September 26, 2012, 06:11:35 am »
Hi all

I kept investigating this issue and thought to come back here and update the findings for the sake of those who might have similar problem.

The problem was found. It it resulting in the points of the lines being located too close to one another. And when the width of the line becomes thicker than the distance between points to be connected - the iOS would have troubles drawing the connecting joints properly.

That is - it will have the troubles to do so as long as you are using the default params of LineCaps and LineJoin properties of the CG of iOS. When I wrote a simple test in iOS , I had the same effect. But when changed those settings - the line is pretty good.

The issue is - DFSDK has no API to change those defaults, AFAIK right now. I guess future versions will have it.

Anyway, dont spend too much time and dont pull too much hair on that one.