In my android app, I want to draw circles and then have to find their intersection points. And then i need to draw the lines between the intersection points which i got. I know how to implement this logic but dont know where to draw like graph.
I tried to draw this on mapview using Geopoints, considered lattitude as "x" axis and longitude as "y"axis. Its not good enough as I expected.(Sometimes lines disappear when zooming).
Which feature of Android facilitate this? Guide me to implement this.
Thanks in advance...
You want a custom view. Custom views allow you to draw to a Canvas. Canvas has functions like drawLine and drawCircle. It takes x,y coordinates, with 0,0 being the upper left corner and x and y growing bigger as you go right and down. If you don't want 0,0 to be the upper left, you can always use some basic algebra to translate it wherever you want.
Related
I want to draw some path with user's touch. if users moves finger from one position to another position a path will be drawn exactly as user moved finger.
We can draw a line with by defining color but i want to draw that line with sprite(image).
What I exactly meant is I just want to use image using sprite instead of using color to draw line. is it possible with LibGDX? if yes , how can we do that? and how will I generate image to use as sprite for that?
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?
As is known, drawCircle(x, y, radius, paint); takes in the canvas coordinates, which may be different from the screen coordinates.
So if I just want to draw something on one particular point on the screen, how would I do that with that method?
I am asking this because the canvas may be moved or even zoomed, but I do NOT wish my circle to move. I want it to stay at that particular point on screen.
Here is the description of drawCircle() method.
It seems that there are no direct converting methods.
We have to convert it manually by the help of maths.
We can process the coordinates according to the properties, like translation or scaling or even rotation.
I am drawing a filled polygon on a canvas in android.
canvas.drawPath(path,myPaint);
Now I want to do exactly the opposite: Fill the area outside of the polygon.
how can I tell the paint to fill the outer region - the region which is not covered by the polygon?
simply use
path.setFillType(FillType.INVERSE_EVEN_ODD);
This can be complicated or very simple.
The complicated way:
Create a path exactly like your polygon, except don't close it. The continue that path to the nearest wall. Draw around the walls. Close and fill. In code, this isn't too fun.
The simple way:
Color the canvas. Draw the polygon.
Good luck.
So I'd like to be able to draw a circle where I can specify the amount of circle drawn as shown in the following diagram.
AS an opengl newbie I'm not really sure how to approach this.. I've previously drawn full circles using GL_TRIANGLE_FAN
You already know how to draw a circle using a triangle fan. Now you just have to calculate the angles of the cutoff corners, use those as the beginning and end of the arc and place the hub of the triangle fan at the middle of the cutoff edge.
you could use a glScissor test to cut off the parts of the circle that you don't want.
http://www.khronos.org/opengles/sdk/1.1/docs/man/glScissor.xml