Rectangle 27 2

You can find a very efficient C++ implementation in the Computational Geometry Algorithms Library (CGAL) in package Bounding Volumes. (There is no need to use all of CGAL; just extract the required source and header files and you are up and running.)

Note: If you are looking for an algorithm to compute the smallest enclosing sphere of points only, there are other implementations out there, see this post.

+1 This post clearly should have much more upvotes since your thesis deals exactly with question problem!

c# - Finding the smallest circle that encompasses other circles? - Sta...

c# math geometry
Rectangle 27 1

Geocoder Android API is not as efficient as the Google Maps Geocoding API so I suggest you to use this one instead of Geocoder. You can find below the function to get location from address through Volley queue (For Lentoasemantie 1, Vantaa, it works) :

public void getLocationFromAddress(String address) {
    String url = "https://maps.googleapis.com/maps/api/geocode/json?address="
            + Uri.encode(address) + "&sensor=true&key=API_KEY";
    RequestQueue queue = Volley.newRequestQueue(this);
    JsonObjectRequest stateReq = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            JSONObject location;
            try {
                // Get JSON Array called "results" and then get the 0th
                // complete object as JSON
                location = response.getJSONArray("results").getJSONObject(0).getJSONObject("geometry").getJSONObject("location");
                // Get the value of the attribute whose name is
                // "formatted_string"
                if (location.getDouble("lat") != 0 && location.getDouble("lng") != 0) {
                    LatLng latLng = new LatLng(location.getDouble("lat"), location.getDouble("lng"));

                    //Do what you want
                }
            } catch (JSONException e1) {
                e1.printStackTrace();

            }
        }

    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d("Error.Response", error.toString());
        }
    });
    // add it to the queue
    queue.add(stateReq);

}

java - Android Geocoder getFromLocationName fails with valid address -...

java android google-geocoder
Rectangle 27 0

I found a solution to this problem by circumventing the geometry service altogether and building a solution of my own. There is a great site that implements the Vincenty algorithm for measuring the distance between two coordinates. This is a very accurate approximation algorithm (within .5mm on Vincenty's earth ellipsoid), and is meant to be very efficient so that it can be used frequently (e.g. after a mouse moves).

  • Add an event listener to the map that listens for a mouse click
  • Once the mouse is clicked, convert the coordinates of the location of the click on the screen to map coordinates and add a listener to watch for a mouse move event
  • When the mouse moves, grab the coordinates of the mouse (as in step 2) and perform the Vincenty calculation. Create a custom tooltip on the map and add the Vincenty result to the tooltip text.
  • Upon double-click, send the result to the Geometry service and remove the tooltip from the map

flex - Measure the Length of a Line on a Map after a MOUSE_MOVE Event ...

flex api actionscript mouseevent esri
Rectangle 27 0

Even if you feed OpenGL quads, the triangularization is done by the driver on the CPU side before it even hits the GPU. Modern GPUs these days eat nothing except triangles. (Well, and lines and points.) So something will be triangulating, whether it's you or the driver -- it doesn't matter too much where it happens.

This would be less efficient if, say, you don't reuse your vertex buffers, and instead refill them anew every time with quads (in which case the driver will have to retriangulate every vertex buffer), instead of refilling them with pretriangulated triangles every time, but that's pretty contrived (and the problem you should be fixing in that case is just the fact you're refilling your vertex buffers).

I would say, if you have the choice, stick with triangles, since that's what most content pipelines put out anyways, and you're less likely to run into problems with non-planar quads and the like. If you get to choose what format your content comes in, then use triangles for sure, and the triangulation step gets skipped altogether.

geometry - OpenGL: Is it more efficient to use GL_QUADS or GL_TRIANGLE...

opengl geometry gpu quad
Rectangle 27 0

Efficient drawing in OpenGL means sending the least information, and fewest batches of information possible. As with everything, it depends on the situation and you should try various things and benchmark for your situation. But as a rule of thumb, the most efficient way (if the vertices are stationary) is to store the vertices on the card once (in a buffer) and render many times, next best (when it makes sense) is to use a geometry shader to generate most vertices on the card, next best is to send all vertices at once, next best is to send batches, and finally the worst is to do one at a time.

900 really isn't very many, and it sounds like a buffer or shader wouldn't make sense in this context.

To send in a batch, you need to put your vertices in sequential memory, such as:

float coords[] = { 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0 };

(That's x1, y1, x2, y2, etc. You probably want to malloc some memory so that it can be variable length)

glVertexPointer( 2, GL_FLOAT, 0, coords ); // 2 = dimensions
glDrawArrays( GL_LINES, 0, 4 ); // 4 = number of points, => 2 lines

GL_LINES will draw a line from 1 to 2, 3 to 4, etc. there are a lot of other options. You can be a bit looser with the memory; take a look at the stride parameter (0 above) if you need to. Here's the documentation:

I understand what glVertexPointer and glDrawArrays are doing, but for some reason, it still doesn't work. Is there anything else you have to do? Perhaps it's because I'm overriding draw() in CCDrawNode, and your example is for something else that doesn't require additional setup?

@GoldenJoe you will also need to enable all the bits you're using, which is a minimum of glEnableClientState(GL_VERTEX_ARRAY), but that should be the same for drawing one line at a time. You might also need to set the current context if the library isn't managing that for you.

iphone - What is the best way to draw a large number of lines using op...

iphone ios objective-c opengl-es cocos2d-iphone
Rectangle 27 0

It can be done with 2 triangle strips, but strips are usually replaced with indexed triangles for more complex geometry because they become more efficient when you need multiple strips. I think it can also be done with a single strip if you use a degenerate triangle to connect the two, but indexed is usually better for larger geometry. Quads just get converted into triangles.

The winding direction is important only when backface culling is enabled. Also, things get more complicated when you add texture coordinates and surface normals for lighting. The normals can be used to make the cube look faceted or smooth shaded, which is really for larger models, like spheres. Here is a tutorial I wrote years ago for OpenGL ES 2.0:

/******************************************************************************

  Function      DrawCubeSmooth

  Return        None

  Description   Draw a cube using Vertex and NormalsPerVertex Arrays and
                glDrawArrays with two triangle strips.  Because normals are
                supplied per vertex, all the triangles will be smooth shaded.
                Triangle strips are used instead of an index array.  The first
                strip is texture mapped but the second strip is not.

******************************************************************************/

void Cube2::DrawCubeSmooth(void)
{
    static GLfloat Vertices[16][3] =
    {   // x     y     z
        {-1.0, -1.0,  1.0}, // 1  left    First Strip
        {-1.0,  1.0,  1.0}, // 3
        {-1.0, -1.0, -1.0}, // 0
        {-1.0,  1.0, -1.0}, // 2
        { 1.0, -1.0, -1.0}, // 4  back
        { 1.0,  1.0, -1.0}, // 6
        { 1.0, -1.0,  1.0}, // 5  right
        { 1.0,  1.0,  1.0}, // 7
        { 1.0,  1.0, -1.0}, // 6  top     Second Strip
        {-1.0,  1.0, -1.0}, // 2
        { 1.0,  1.0,  1.0}, // 7
        {-1.0,  1.0,  1.0}, // 3
        { 1.0, -1.0,  1.0}, // 5  front
        {-1.0, -1.0,  1.0}, // 1
        { 1.0, -1.0, -1.0}, // 4  bottom
        {-1.0, -1.0, -1.0}  // 0
    };
    static GLfloat NormalsPerVertex[16][3] =    // One normal per vertex.
    {   // x     y     z
        {-0.5, -0.5,  0.5}, // 1  left          First Strip
        {-0.5,  0.5,  0.5}, // 3
        {-0.5, -0.5, -0.5}, // 0
        {-0.5,  0.5, -0.5}, // 2
        { 0.5, -0.5, -0.5}, // 4  back
        { 0.5,  0.5, -0.5}, // 6
        { 0.5, -0.5,  0.5}, // 5  right
        { 0.5,  0.5,  0.5}, // 7
        { 0.5,  0.5, -0.5}, // 6  top           Second Strip
        {-0.5,  0.5, -0.5}, // 2
        { 0.5,  0.5,  0.5}, // 7
        {-0.5,  0.5,  0.5}, // 3
        { 0.5, -0.5,  0.5}, // 5  front
        {-0.5, -0.5,  0.5}, // 1
        { 0.5, -0.5, -0.5}, // 4  bottom
        {-0.5, -0.5, -0.5}  // 0
    };
    static GLfloat TexCoords[8][2] =
    {   // x   y
        {0.0, 1.0}, // 1  left                  First Strip
        {1.0, 1.0}, // 3
        {0.0, 0.0}, // 0
        {1.0, 0.0}, // 2
        {0.0, 1.0}, // 4  back
        {1.0, 1.0}, // 6
        {0.0, 0.0}, // 5  right
        {1.0, 0.0}  // 7
    };

    glEnableVertexAttribArray(VERTEX_ARRAY);
    glEnableVertexAttribArray(NORMAL_ARRAY);
    glEnableVertexAttribArray(TEXCOORD_ARRAY);

    // Set pointers to the arrays
    glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, Vertices);
    glVertexAttribPointer(NORMAL_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, NormalsPerVertex);
    glVertexAttribPointer(TEXCOORD_ARRAY, 2, GL_FLOAT, GL_FALSE, 0, TexCoords);

    // Draw first triangle strip with texture map
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);

    // Draw second triangle strip without texture map
    glDisableVertexAttribArray(TEXCOORD_ARRAY);
    glDrawArrays(GL_TRIANGLE_STRIP, 8, 8);

    glDisableVertexAttribArray(VERTEX_ARRAY);
    glDisableVertexAttribArray(NORMAL_ARRAY);
};

3d - OpenGl Vertex Order for Cube - Stack Overflow

opengl-es 3d cube vertices
Rectangle 27 0

Ok, I don't know about the real performance gain for simple quads. But if your "geometry" is static you get most out of display lists. They are quite simple to use and require almost no code change.

It is important to note that the most expensive operation are context switches. That is anything from binding a texture (very expensive) to changing the color (not so expensive). So the best thing you probably can do is render all sprites using one texture in one go.

If you have one big static level, you can draw the entire thing into a display list and only call that. There is to note that you still should try to optimize for context switches.

You should also invest some time in code that prevents trying to render things that are not visible. (Check that against the DL solution for the entire level.)

display lists have been deprecated since openGL 3.1. VBOs are not much more complicated and should be used in their stead.

Yeah I'm already careful about context switches and have them at an absolute minimum (all sprites come from a single atlas), same with visibility calculation. The question was more about sprites though - if I'm drawing hundreds of sprites/quads moving around, should they all be VBO's or is that overkill for geometry that simple?

Wow, true, I did not know this. I liked displaylists for the fact that when you built custom scenes and had something that rendered always the same you could cram that into one DL and be happy with it. But I don't know if OP will get much out of VBOs, save lots of setup code.

iphone - Most efficient way to use OpenGL for 2d games? - Stack Overfl...

iphone performance opengl-es 2d vbo
Rectangle 27 0

Develotecca's answer shows how to load a basic THREE.geometry from a JSON file. However, in my experience, the geometries exported by the three.js editor are of type BufferGeometry (which is more efficient than a basic Geometry) so they need to be loaded using a THREE.BufferGeometryLoader rather than a THREE.JSONLoader.

Also, the question is about saving and loading scenes, not geometries. JSONLoader is designed only to load basic geometries, and a geometry contains only a single model's per-vertex and per-face information (which includes material numbers for indexing into a MeshfaceMatrial, but no other material information, and so it needs to be combined with a material before use). If you try to load an entire scene using JSONLoader, instead of just a part of one object in the scene, the loader should spot this and deliver the message

THREE.JSONLoader: <url> seems to be a Scene. Use THREE.SceneLoader instead.'

to the console log. This gives a big clue to the proper way to proceed.

All of that is a lot to wade through. I haven't actually used SceneLoader myself yet, though I intend to soon, but from what I've read so far it looks similar to BufferGeometryLoader or JSONLoader except because you're loading a whole scene instead of just part of one you have

scene = loaded.scene
scene.add()

and you may need to include other loaders and handlers for any specialized geometries that your scene uses, e.g.

<script src="js/loaders/ColladaLoader.js"></script>
..
loader.addHierarchyHandler( "dae", THREE.ColladaLoader );

javascript - Export scene from Three.js editor and import - Stack Over...

javascript import three.js editor export
Rectangle 27 0

Any geometry can be represented with triangles, and that is why it was decided to use triangles instead of quads. Another reason is two triangles do not have to be co-planar, which is not true for quad.

Yes, you select to render quads, but the driver will converting the quad into two triangles.

Therefore, by choosing to render a quad will not make GPU work less, but will make your CPU work more, because it has to do the conversion.

geometry - OpenGL: Is it more efficient to use GL_QUADS or GL_TRIANGLE...

opengl geometry gpu quad
Rectangle 27 0

The most efficient way is to use the existing geometry buffers such as:

geometryGroup.__vertexArray
geometryGroup.__normalArray
WebGLRenderer.initMeshBuffers
importScripts("/js/lib/mrdoob-three.js-35db421/build/three.js");

In the worker you create another instance of the geometry you want to process.

Trigger one initial rendering in the main thred renderer.render(scene, camera); now the buffers are available...

Send the required buffers from the main thread to the worker

Do the hard work on the geometry at the worker thread

  • Manually (there is no support for that in threejs) fill the required buffers (see WebGLRenderer.setMeshBuffers) e.g.: var vertexArray = new Float32Array(vertexBuffer); var normalArray = new Float32Array(normalBuffer); var vertices : Array = geometry.vertices; var obj_faces : Array = geometry.faces; var offset = 0; var offset_normal = 0; for (f in 0...obj_faces.length) { var face = obj_faces[ f ]; var v1 = vertices[ face.a ]; var v2 = vertices[ face.b ]; var v3 = vertices[ face.c ]; var v4 = vertices[ face.d ]; vertexArray[ offset ] = v1.x; vertexArray[ offset + 1 ] = v1.y; vertexArray[ offset + 2 ] = v1.z; vertexArray[ offset + 3 ] = v2.x; vertexArray[ offset + 4 ] = v2.y; vertexArray[ offset + 5 ] = v2.z; vertexArray[ offset + 6 ] = v3.x; vertexArray[ offset + 7 ] = v3.y; vertexArray[ offset + 8 ] = v3.z; vertexArray[ offset + 9 ] = v4.x; vertexArray[ offset + 10 ] = v4.y; vertexArray[ offset + 11 ] = v4.z; offset += 12; }
  • send the buffers back to the main thread and update the geometry there: var geometryGroup = mesh.geometry.geometryGroupsList[0]; var _gl = renderer.context; _gl.bindBuffer(_gl.ARRAY_BUFFER, geometryGroup.__webglVertexBuffer ); _gl.bufferData(_gl.ARRAY_BUFFER, transferVertexArray, _gl.DYNAMIC_DRAW );

If you are doing complex operations on geometries this works well. Understanding how the buffers are created and used by WebGLRenderer is important.

Nice and complete answer, seems to worth the bounty.

I'm not sure though i shouldn't do the hard work on arraybuffers directly and do the work of building a correct THREE.Geometry outside of the worker (from thoses arrays)

javascript - How to efficiently convert THREE.Geometry to ArrayBuffer,...

javascript performance three.js web-worker arraybuffer
Rectangle 27 0

You can find a very efficient C++ implementation in the Computational Geometry Algorithms Library (CGAL) in package Bounding Volumes. (There is no need to use all of CGAL; just extract the required source and header files and you are up and running.)

Note: If you are looking for an algorithm to compute the smallest enclosing sphere of points only, there are other implementations out there, see this post.

c# - Finding the smallest circle that encompasses other circles? - Sta...

c# math geometry
Rectangle 27 0

Efficient drawing in OpenGL means sending the least information, and fewest batches of information possible. As with everything, it depends on the situation and you should try various things and benchmark for your situation. But as a rule of thumb, the most efficient way (if the vertices are stationary) is to store the vertices on the card once (in a buffer) and render many times, next best (when it makes sense) is to use a geometry shader to generate most vertices on the card, next best is to send all vertices at once, next best is to send batches, and finally the worst is to do one at a time.

900 really isn't very many, and it sounds like a buffer or shader wouldn't make sense in this context.

To send in a batch, you need to put your vertices in sequential memory, such as:

float coords[] = { 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0 };

(That's x1, y1, x2, y2, etc. You probably want to malloc some memory so that it can be variable length)

glVertexPointer( 2, GL_FLOAT, 0, coords ); // 2 = dimensions
glDrawArrays( GL_LINES, 0, 4 ); // 4 = number of points, => 2 lines

GL_LINES will draw a line from 1 to 2, 3 to 4, etc. there are a lot of other options. You can be a bit looser with the memory; take a look at the stride parameter (0 above) if you need to. Here's the documentation:

I understand what glVertexPointer and glDrawArrays are doing, but for some reason, it still doesn't work. Is there anything else you have to do? Perhaps it's because I'm overriding draw() in CCDrawNode, and your example is for something else that doesn't require additional setup?

@GoldenJoe you will also need to enable all the bits you're using, which is a minimum of glEnableClientState(GL_VERTEX_ARRAY), but that should be the same for drawing one line at a time. You might also need to set the current context if the library isn't managing that for you.

iphone - What is the best way to draw a large number of lines using op...

iphone ios objective-c opengl-es cocos2d-iphone