## here a 3D graphics course

links : http://who.is.free.fr/wiki/index.php?e=project&edit=Rubiks http://rzr.online.fr/java.htm

BTW, I'd like a to own a “rubiks clock” or/and a “powerball” toy which is 1 euro on ebay :)

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #

Faces

y
|\
|_\
O  x
int x=1; int y=1;
vertex = { { 0, 0, 0 } ,  { 0,0,x } ,  {0,y,0 } };
faces = { { 0 , 1 , 2 } };  // index in vertex array , here : O, x, y
color = { 0x00FF0000 } ; // red color

For a square (which is 2 triangles) :

y __
|\ |
|_\|
O    x
int x=1; int y=1;
vertex = { 0, 0, 0,   0,0,x,  0,y,0 ,  x,y,0 };
faces = { {0,1,2} , {1,2,3} };
color = { 0x0099FF00, 0x0000FF00 } ; // two triangles are green

helper :

2  3
0  1

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # 2×2 scare = 3×3 = 9 vertex (on xy plane)

  +y
  |
.  .  .
.  o  .   --> +x
.  .  .
int x = 1; int y = 1;
coords = {
* x , y ,           0 , y ,               x , y ,    // row 1
  *x , 0 ,           0 , 0 ,               x , 0 ,    // row 2
* x , -y ,          0 , -y ,              x , -y ,   // row 3
}

helper : read array pairs like :

0  1  2
3  4  5
6  7  8
TODO : make the face array

faces = { {0,1,2}, {1,2,3}, {1,0,4}, { 0,4,5}, {0,6,5}, {6,5,7}, {0,8,2}, {8,0,6} : FALSE

};

wrong : { 0 1 2 } is not a triangle because points are aligned

answer is : from up to down , left to right :

{ 0 , 1 , 3 } , { 3 , 1 , 4 } , // for up left scare
{ 1 , 2 , 4 } , { 4 , 2 , 5 } , //     up right scare
{ 3 , 4 , 6 } , { 6 , 4 , 7 } , //     bottom left
{ 4 , 5 , 7 } , { 7 , 5 , 8 } , //     bottom right

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # now do it again in 3D :

int z= 1;
int x = 1;
int y = 1;
coords= {
* x , y , -z          0 , y , -z              x , y , -z,  // row 1
  *x , 0 , -z          0 , 0 , -z              x , 0 ,  -z,  // row 2
* x , -y , -z         0 , -y , -z             x , -y , -z,  // row 3
/// ^ far plane
* x , y , 0          0 , y , 0              x , y , 0,  // row 4
  *x , 0 , 0          0 , 0 , 0              x , 0 , 0,  // row 5
* x , -y , 0         0 , -y ,0              x , -y , 0,  // row 6
/// ^ center plane
* x , y , +z          0 , y , +z              x , y , +z,  // row 7
  *x , 0 , +z          0 , 0 , +z              x , 0 ,  +z,  // row 8
* x , -y , +z         0 , -y , +z             x , -y , +z,  // row 9
/// ^ near plane
}
TODO : make the face array

helper:

0  1  2
3  4  5
6  7  8

rear side (-z)

for middle side (z=0) add 9 to rear side vertex indices

for front side (+z) add 2*9 to rear side vertex indices

faces = { {0,1,2}, {1,2,3}, : FALSE

  {1,0,4}, {0,4,5},: FALSE ==================
  {0,6,5}, {6,5,7},: FALSE ==================
  {0,8,2}, {8,0,6}: FALSE ==================

};

Wrong there must be : 2 * 4 * 6 triplets (2 triangle per square, 4 square per faces, 6 faces)

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Once done, make a color array (one color per face), a color is represented as a triplet of values ( { R, G, B} } or stored in a 32 bit int : 0x00RRGGBB ;

Once done, make a function that “rotate” the colors in the cube : void rotateRow( int row_indice, bool right_or_left) { }

this method only swap the colors on a full slice of the cube (think 3D) thoses ones are a the most complicated.

As well : void rotateCols( int col_indice, bool right_or_left) { }

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #

now make the ”»> TODO :” parts

BTW, I'd like a to own a “rubiks clock” or/and a “powerball” toy which is 1 euro on ebay :)

rubiks.txt · Last modified: 2022/04/16 12:24 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki