Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

opengl

bezier

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?

like image 285
QuantumKarl Avatar asked Nov 22 '10 22:11

QuantumKarl


2 Answers

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;

 }
like image 113
SingleNegationElimination Avatar answered Oct 31 '22 12:10

SingleNegationElimination


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 :)

like image 2
Goz Avatar answered Oct 31 '22 14:10

Goz