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?
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 :)
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;
}
来源:https://stackoverflow.com/questions/4250889/best-way-to-draw-a-cube-with-smooth-edges-bezier-curve-load-a-3ds-or-other