## glgeom::create_sphere()

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

Posted in glgeom