glgeom::create_sphere()

with 3 comments

Per the first ever user request (thanks Dave), GLGeom has a new feature:

glgeom::primitive_buffer glgeom::create_sphere();

Implementation

The code, located here, works as follows:

  1. Creates a unit cube
  2. Moves vertices onto the surface of a unit sphere
  3. Split each quad into four quads via introducing a quad midpoint
  4. Move the new vertex onto the surface of the unit sphere
  5. Repeat steps 3 & 4 for several iterations

Why add this?

While LxEngine does already support loading meshes from Blender files, I do like the idea of providing some basic shapes for the GLGeom library. It does have practical application: especially when throwing together a quick test or maybe implementing a research project, it can be nice to create a zero-dependencies executable that creates rather than loads the geometry it needs. I see this as a feature useful for the small samples and tests use cases.

Image

The result is a (fairly) evenly divided sphere:

…and yes, the “snow” from the previous post is still in the image – I lazily hacked the new functionality into Tutorial 5 for testing :)

And also, since the rasterizer is OpenGL 3.2 based, it renders using triangles rather than (the now deprecated) quads. Thus, I mention “quads” above, yet the wireframe image displays a sphere composed of triangles. The conversion takes place at the LxEngine rasterization level so I’ve ceased to think too much about such conversions!

Details

The create_sphere() function creates a glgeom::primitive_buffer with the following properties:

primitive.type = "quads";
primitive.vertex.positions = /*vector filled with the unit sphere positions*/;
primitive.vertex.normals = /*vector filled with normals for each vertex*/;
primitive.indices = /*four 16-bit indices per quad in the sphere*/;
primitive.bbox = /*unit bounding box*/;
primitive.bsphere = /*unit bounding sphere*/;

Written by arthur

April 9th, 2012 at 8:26 pm

 

3 Responses to 'glgeom::create_sphere()'

Subscribe to comments with RSS or TrackBack to 'glgeom::create_sphere()'.

  1. Dave here! Coolbeans!!! Glad to see it!

    Mars_999

    10 Apr 12 at 21:21

  2. BTW will primitive buffer hold tangents and/or texcoords?

    Mars_999

    10 Apr 12 at 21:22

  3. I plan to add a function glgeom::compute_uv_mapping(primitive_buffer&, int channel, std::function<vec2 (vec3)>) that will allow UVs to be generated fairly easily. (The exact signature of the function may vary – I also want to support uvw’s as well as uv’s so there will likely be several overloads.)

    There are already several functions in the library to generate mappings in the glgeom_extension_mappers module. It should be just a matter of writing code like this:

    glgeom::primitive_buffer sphere = glgeom::create_sphere();
    glgeom::compute_uv_mapping(sphere, glgeom::mapper_spherical);

    But to the point: it *will* support UV generation, but it doesn’t yet!

    As for generating tangents/bitangents, I don’t see why that can’t be added as well.

    arthur

    10 Apr 12 at 21:34

Leave a Reply