tags:

views:

82

answers:

2

Always in the context of a Rubik's cube app in Java/Opengl with lwjgl, i want to improve my drawing (http://manuelselva.files.wordpress.com/2010/09/cube.gif) in order to have rounded edges for each one of the 27 small cube ? What i would like to acheive at the end is the same as the wikipedia cube picture: http://fr.wikipedia.org/wiki/Fichier:Rubik%27s_cube.svg

What is the easiest solution to do that ?

+2  A: 

The easiest is probably to draw a model of a rounded cube in one of the many 3D modeling programs around (e.g., Maya, Blender), and load 27 instances of the model in your code. Learning to use a program like one of these isn't trivial though, so even though this is the general approach used in most games and such, for something this simple it may be kind of overkill -- it may take longer to figure out how to accomplish anything in the program, than it would have to do things a different way.

The obvious alternative would be to generate a the model in your code. The basic idea is fairly simple, though getting it all put together may be somewhat non-trivial. You start by picking the radius you want to use for the corners. When you generate your faces, you leave enough space between them to fit in a quadrant of a circle with that radius (i.e., each face ends one radius short of where they two would intersect). You connect them with a set of vertex coordinates/normals that follow a quadrant of a circle -- basically, write a small loop that generates a few dozen points (or so) at evenly spaced angles. The angle at each point will be the normal, and the sine/cosine will give the coordinates. At the corners (as opposed to the edges) you need to generate points on a sphere, with one quadrant of a sphere for each corner.

Jerry Coffin
@Manuel Selva : You'll have to learn one of [maya blender 3ds] someday, so I'd recommend you this way. Make a rounded cube with 7 different materials (1 for each face + plastic) and modify them on run time with the desired color.
Calvin1602
Thanks, I'll look into this direction. Manu
Manuel Selva
A: 

Some clever texturing and a properly crafted normal map will mostly fake the look of it being rounded without editing the model. The final render would be shaded as if the individual sides were rounded.

Unfortunately with this approach the illusion falls apart when viewed edge-on.

Brandorf