0

What is the "easiest" solution to code a Rubik's Cube with the following features in Opengl:

  • "Camera" moves to let user see the cube from any point of view
  • Smooth display of cube moves in response to user clicks when playing

I started with a solution drawing the cube "Face by Face" but I am not sure it's a good solution (I am facing many problems ...)

May be a solution "unit cube" by unit cube (27 cubes has to be drawn) is easier to implement ?

starblue
  • 55,348
  • 14
  • 97
  • 151
Manuel Selva
  • 18,554
  • 22
  • 89
  • 134

1 Answers1

1

You will have to draw 27 cubes because almost every cube belongs to several faces, so you want the faces to rotate...

What's the problem with this ? Are you worried about performance because you're on a mobile target ? 12x27 triangles is not a problem.

Calvin1602
  • 9,413
  • 2
  • 44
  • 55
  • No problem with drawing the 27 cubes. Just asking before implementing a new solution and discover new troubles. Why are you speaking about 12x17 triangles ? At a first try i was thinking to start to draw the 27 cubes as 27 GL11.glBegin(GL11.GL_LINE_LOOP); Is it wrong ? – Manuel Selva Aug 26 '10 at 15:00
  • Calvin wanted to say 12x27 triangles. 27 cubes, every cube has 6 sides, every side (square) has 2 triangles => 6x2x27 triangles to draw – sloth Aug 26 '10 at 15:44
  • Sorry, I thought I edited that. For your second question, yes it's wrong : 1) with lines you won't be able to see anything and 2) don't use glBegin but VBOs http://www.songho.ca/opengl/gl_vbo.html (even if it sounds more complicated) – Calvin1602 Aug 26 '10 at 15:59
  • How can we make a Square with 2 triangles ? – Manuel Selva Aug 26 '10 at 18:50
  • 1
    ?? Draw a square, draw a diagonal.. you've got two triangles – Calvin1602 Aug 26 '10 at 21:39
  • Sorry I read 3 triangles !!! Is drawing 2 triangles more efficient than drawing square with GL_QUADS ? – Manuel Selva Aug 27 '10 at 07:06
  • No, but internally, openGL only knows triangles, hence my remark – Calvin1602 Aug 27 '10 at 07:37