Digging a polygon according to another with libgdx - android

I actually develop a 3D application on Android, and i manipulate 3D object.
I want to dig a polygon according to another polygon form such as a cube or a cylinder.
In the following image you can imagine I have two superimposed polygons, a cylinder and a rectangular cuboid.
If I get the intersection of these two polygons and I calculate the inverse (included in the rectangular cuboid) I get a new polygon with a hole in the shape of the cylinder like in this picture.
I don't know how to achieve this with libGDX, I know the Intersector class, but I do not know how to retrieve the reverse of an intersection between two polygons.

Related

How to draw a polygon with texture in Sceneform/ARCore?

How can I draw custom texture/material inside a defined polygon (defined by 3 or 4 or more points)?
I found this: How to draw a polygon with Sceneform, ARCore?
It's a good start. But it's only for 3 points. What if the user adds 4th point? I tried to update the code but it always draw texture as a triangle.
Next, I found this: Sceneform applying textures to triangle seamlessly (it's similar problem to mine)
I want to achieve something like this:
I'm using SceneView in my app https://github.com/SceneView/sceneform-android
Also, it's possible to rotate and zoom in/out the texture?
Thanks for the info!

can I draw polygons on texture with GLSL?

I'm completely new to OpenGL so my question might sound stupid but I'm trying to do one thing for more then week and I got completely stuck.
I'm trying to draw a globe that you can rotate and zoom and pick the country on Android. There are no problems with rotation but there are some with zooming (texture looks ugly if camera come closer) and I have no idea how to implement country picking. I have an arrays for each country with lat,log for each vertex of country border. But how can I draw it on the sphere ?
I've been trying to convert lat,long to zyx and draw lines but there is a triangulation issue to build polygons. Is it possible to draw texture on run-time with shaders? and is it possible to get a touch point on texture ? (I'd like to highlight selected country by filling it with another color)
I don't need a map, just a countries with one color, borders with another one and rest of the globe with third one.
I'm using Rajawali lib for this purpose. Although it is opensource but it has no comment and tiny doc is outdated so if you know better framework please suggest me.

Drawing 2D curves in Android canvas?

How we can draw 2D curves like this in Canvas?
All similar curves have mathematical formula or are fractals, but the canvas only has some methods for drawing simple shapes like a triangle or rectangle. I know that most curves can divide into simpler shapes such as with drawing a Heart Curve, but is there an easier way to draw 2D curves with the canvas?
Using the Path object you can do some fancier lines and curves in the Canvas. Just randomly found these two questions concerning those; I hope they can point you in the right direction as I personally have not used them.
Draw a perfect curve connecting three points
Bezier curve and canvas
If you look up how to draw 2D curves in general you'll either be drawing points or lines and it only looks smooth.
Your question has two parametric forms and one fractal form. All can be drawn with lines and points. The parametric forms can be done directly via the algorithms in your question or could be transformed into more general ones like the Bezier curve as mentioned by #leenephi
Most of the time the equations/algorithms for generating fractals are using lines, Koch Snowflake, or points, the Mandelbrot set. If you actually understand how to generate them, you'll see that fractals are less about drawing 'a curve' and more about process (recursion) and results (self-similarity).
You have to approximate the curve by simpler primitives for example short line segments.

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

Spinning globe in Opengl-es

I need to draw a spinning globe using opengl es in android. I think we need to draw a sphere and then apply a texture map on it. If I am correct, we cannot use the utility library glu in Opengl ES for drawing a sphere. I did find some code in objective C, but then I would have to make it work on android.
http://www.iphone4gnew.com/procedural-spheres-in-opengl-es.html
Is there any other way to do this ? I'm no sure how to approach this problem, Could you give me some inputs that would set me looking in the right direction.
Thanks
You could actually create your own sphere rendering function.
A tesselated sphere is no more then a stack of n cone segments, each approximated with m slices.
This image (courtsey of dglwiki.de) illustrates this:
(the german text translates to 'If the resolution is to low, the sphere degenerates to other symetric Bodies)
In order to construct the sphere, you'll need to specify the center point, radius, number of stacks and number of slices per stack.
The first pole of your sphere can be any point with a distance of radius from the center point. The vector from this point to the center point defines your sphere's axis of rotation (and thereby the position of the second pole)
Next, you'll need to approximate several equidistant circles of latitude on your sphere around the axis of rotation. The number of circles should be number of stacks -1. Each of these circles should have as much vertices as your desired number of slices.
Having calculated these, you have enough geometry information to construct your spheres faces.
Begin with a triangle fan originating at one of the poles using the vertices of the first circle.
Then, construct Triangle strips for each pair of neighbouring circles of latitude. The last step is to construct another triangle fan from the second pole to the last of your circles of latitude.
Using this approach, you can generate arbitrary spheres of arbitrary smoothness
In addition to what sum1 says, the link you provide to obj-C code is mostly just C, which translates quite nicely to Java/android. The technique provided is very similar to the one sum1 suggests, although the author uses only one fan at the top, then draws the entire remainder of the sphere with a single triangle strip. In addition, his globe is "laying on its side", with the fan at the "East pole" and the other point at the "west pole."
However, you can either use the link you provide as-is, or make the adjustments easily enough.

Categories

Resources