I need to make a cube with smooth corners and smooth edges in C++ with OpenGL. For all I know I have three options: Bezier curves (maybe, is it possible?), a cube with cylinders for edges and spheres for corners or load a .3ds of a cube.
Any ideas?
pseduocode:
mesh rounded_cube(int size, int edge_radius)
{
mesh result = sphere(edge_radius)
vertex octants[] = result.verteces()
for each v in octants
{
if (v.x != 0.0)
v.x = size * ( v.x/abs(v.x) );
if (v.y != 0.0)
v.y = size * ( v.y/abs(v.y) );
if (v.z != 0.0)
v.z = size * ( v.z/abs(v.z) );
}
for i in result.vertices().size()
{
result.vertex[i] += octants[i]
}
return result;
}
You can simulate a cube with smooth lighting by pointing the normals directly out from the center (simulating an 8 cornered sphere). It totally depends on what exactly you are trying to do. Using the above method may be perfectly good enough.
If you want to define a cube with curved corners (up close) then you are going to have to subdivide the cube. In fact if you subdivide strongly around corners but ignore the flat faces you will get a good effect.
All it comes down to is thinking about how you subdivide at edges. Think about how you could smooth it out and you'll, surely, come up with a fine solution :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With