Best way to draw a cube with smooth edges? Bezier Curve, load a .3ds or other?

半腔热情 提交于 2019-12-05 11:10:59

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;

 }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!