Touch events are dropped in android - android

I am using FingerPaint example available in ApiDemos for drawing my finger movement on screen.
Now instead of line, I am adding circles in my path object and this path with circle will be drawn when onDraw method is called.
Now my issue is when I slowly move my finger it draws circles at the points given by onTouchEvent properly but when I move my finger with some speed, unlike line, it draws only few circles.
After debugging, I found that while moving finger rapidly, some of the touch events are dropped by the view and on that points circles are not drawn.
Can anyone give some pointers on this. Why this is happening?

Two things I can think of without seeing code.
First, are you getting the historical points recorded between touchEvents and using them also? If not, that would cause some serious jerkiness like you are talking about.
If you are, and it's just not picking them up, the best you'll be able to do might be to cheat it some. Check the distance between the current and last circle drawn. If it exceeds the circle's diameter too much, draw a line with the same thickness as the circle, with a circle on both ends.

Related

convex path - how to?

Could someone explain me how convex path is calculated? I need to draw some cubic and additionally some lines but then path is shown as non convex. However when I leave only lines or just cubic it is then convex. The problem is that I need some non regular shaped background and need Convex path for shadow outline but can't get how I could connect drawing cubic with some lines to make convex path if it is even possible
A path is convex if it has a single contour, and only ever curves in a single direction.
Convex means it keeps bending / rotating in one direction, and one direction only. You really have to make sure that all your angles and curves add up. If your curve connects to a line it has to have the same angle or be "more convex", I hope the following 2 images will clear this up.
The picture below is not convex. That's also likely your problem. The line connects to a curve, but the curve has a different angle than the line and it will change the direction where it connects. See where the line goes down but instead of continuing the downwards-motion it suddenly goes up again. Instead of keeping one direction it will change for a moment where line and curve meet.
The above Image is exaggerated for clarity, but even small errors in the connection between the line and curve will trigger an error.
The next line connects to a curve with a steeper angle. This is convex and won't be a problem. See how the whole contour keeps a single motion in one direction, depending in which direction you follow it it keeps turning left/right.
I answered because I was facing a similar issue recently and I feel your pain. I recommend pen and paper to double and triple check the math and to use a small epsilon value to account for rounding errors etc... You really have to nail the math, because if your line and curve connection is just off by very little it will throw that exception.
Sorry for my bad paint skills

Android Canvas: Draw line with padding for extended touch/click area

Well I`m trying to find solution to a small problem.
I have multiple points on a canvas and have to connect them with a straight line. So exactly one incoming or outgoing connection per point. I have the 2 points for a line.
It all works with canvas.drawline(...) method. But now i want to be able to detect if a there was a click/touch event on a particular line within the line + padding area.
As line is drawn inside a rectangular bounding box its size varies based on the length and frequently overlaps with other bounding boxes. So considering touch within the bounding box is completely dumb i guess.
Can someone please give me some input in this direction?
Thanks a lot!
You can calculate perpendicular distance of the touch from the line.If the distance is within some range(in your case padding size) you consider as touch event on the line.
To calculate perpendicular distance use this formula refer-Shortest distance between a point and a line segment

Drawing and storing a user's touch path in libgdx

I'm struggling with something I would expect to be straight forward with libgdx.
In short this is a "finger paint" app where I want to draw a path of a certain width where the user touches the screen.
I've earlier done this by using a plain Android android.view.View. I had a android.graphics.Path in which I stored the coordinates of the user's current touch. In the onDraw() method of the view I drew the path to the android.graphics.Canvas. Whenever the user released a finger I drew the path to an offline canvas/android.graphics.Bitmap which also was drawn in the onDraw() method. Plain and simple.
How can that be done using libgdx?
I have tried using a com.badlogic.gdx.graphics.Pixmap that I can draw a line to whenever the user moves a finger. This works well except the fact that I'm unable to control the witdh of the line using Gdx.gl.glLineWidth(). I know I can draw a rectangle instead of a line to set the width, but Pixmap doesn't seem to have any means of rotating, so I don't see how this can be done.
I can use a com.badlogic.gdx.graphics.glutils.ShapeRenderer for drawing lines (or rectangles) in com.badlogic.gdx.Screen.render(). As far as I can see I then need to store every single touch point of the current touch, and then draw all lines on render. Whenever the user relases a finger I guess I can store the screen as-is with something like com.badlogic.gdx.utils.ScreenUtils.getFrameBufferPixmap(). Hopefully there is a easier way to achieve what I want.
I ended up drawing circles on a pixmap where the line should be:
One circle on touchDown
Several circles from last touch point to next touch point reported to touchDragged
I'm not very happy with this solution, but it kinda works.
Maybe you can calculate line dot coordinates manually and use triangles to draw them on pixmap? Like use 2 triangles to form (rotated) box?

What's the best way to do collision detection?

I have a need to define a polygon that would be the "legal" area, and allow a user to move a rectangle around within that polygon, preventing them from moving the rectangle anywhere where its points venture outside the polygon.
The polygon is a fixed shape, so, I was thinking it may be easiest to import a PNG of that shape and pull the points in that way, somehow? But I'm still at a loss as to the math involved in checking the coordinates of the rectangle as the user drags it, and testing at what point they have moved the shape to the edge of the bounding polygon.
Unfortunately the bounding polygon is a fairly complex shape. I'm hoping someone can point me at a tutorial that shows what the best way to run such a collision detection is.
Metanet's excellent collision detection tutorial has a good section on how to do swept collision with axis-aligned bounding boxes (AABB) and arbitrary "walls."
If your polygon is concave, you'll probably find it easiest to first decompose it into multiple convex polygons, which will simplify the available collision detection algorithms.
If you only looking to check the corners of the rectangle, you can do a "inside" test for each of them.
http://en.wikipedia.org/wiki/Point_in_polygon
And if you also want to make sure that no pointy part of the polygon "punctures" your rectangle you could do a test for each of the 4 lines in the rectangle against all the lines in the polygon to see if they are intersecting.
http://en.wikipedia.org/wiki/Line-line_intersection

Android MapView path.draw draws crazy polygon lines all over the place

I've been struggling for a couple of weeks now with google's android mapview.
I'm drawing a large amount of polygons with a large amount of points. on average 15 polygons and around 1000 points each.
The first issue I experienced was performance... No surprise. After doing some testing I realised the culprit is projection.ToPixel() which I successfully bypass when the users pans by simply moving all my points in the direction by x amount of pixels (the difference), however when zooming I have no choice but to make use of the toPixel method.
Is there possibly a more efficient way of modifying my points depending on the zoom level? after some research I've found examples on how to do this with circles and other shapes, but I have no clue where to begin with reshaping polygons, any ideas on this?
The second issue i'm having is that when I have the entire polygon in view all is grand, but when I pan over the map bounds (where the map is effectively starting again to the left and right) on any side the polygon lines seem to reach and stretch out across the map bounds causing crazy spaghetti lines all over the place! I take it what's happening is that the path.close() or path.LineTo() methods think the shortest path is flying halfway across the world to reach the next point which causes these lines. I have no idea how to address this. I simply can't ignore points that do not fall within the current lon/lat spans because that (obviously) causes the polygon to change shape al the time!
Has anyone experienced this issue and how can one go about solving it? I'm not even sure what I should be googling!?
UPDATE 1:
The problem can be easily solved by preventing the mapview from looping. Is there some way to prevent the mapview from looping the world!?!?

Categories

Resources