5

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?

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
QuantumKarl
  • 479
  • 5
  • 14
  • See this question on [making a dice have smooth edges](http://stackoverflow.com/q/3480161/59303) - specifically my answer. – ChrisF Nov 22 '10 at 22:38
  • thanks, this didn't come up in my search – QuantumKarl Nov 22 '10 at 22:42
  • Loading a .3ds doesn't automatically render an image for you. You have to parse the 3ds and render it yourself. The question of rendering has nothing to do with the file format. – OJ. Nov 22 '10 at 22:43
  • once you have loaded a .3ds into openGL, what would you have to do with it to get it rendered and translatable? – QuantumKarl Nov 22 '10 at 23:13

2 Answers2

4

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;

 }
SingleNegationElimination
  • 151,563
  • 33
  • 264
  • 304
2

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

Goz
  • 61,365
  • 24
  • 124
  • 204
  • the cube itself is going to be part of a child class for rendering a rubiks cube, so doesn't need to seen up close but needs to be fairly good looking. Would a cube being behind of other cubes effect it at all? how long do you think this would take to learn? i am quite limited for time – QuantumKarl Nov 22 '10 at 23:12