Author Topic: Rounded Cube  (Read 1133 times)

Offline miron123

  • byte
  • *
  • Posts: 16
    • View Profile
Rounded Cube
« on: September 17, 2012, 10:38:32 am »
Hello.
I have a small problem. In the last 4 month i tried to create a cube with rounded edges. First I tried OpenGl ES and finally I found my way to jpct-ae. Now its a imported obj file.
Problem: I try to start new Activities based on the cube side the user is looking at, but I don t want to check for all 4 rotation matrices of each cube side. So I wanted to ask if someone knows a better solution. I heard Quaternion are a good way to go, but I don t realy have a clue how they work.
Code: [Select]
public class MyMath {

public static int getVisibleCubeSide(SimpleVector vector){
int vectorX = (int) Math.round(vector.x);
int vectorY = (int) Math.round(vector.y);
int vectorZ = (int) Math.round(vector.z);
    int[][] posibilities = new int[6][4];

//klassenbuch
posibilities[0][0] = 0;
posibilities[0][1] = 0;
posibilities[0][2] = 1;
posibilities[0][3] = 2;

//studenplan
posibilities[1][0] = 0;
posibilities[1][1] = 1;
posibilities[1][2] = 0;
posibilities[1][3] = 1;

//countdown
posibilities[2][0] = 0;
posibilities[2][1] = 0;
posibilities[2][2] = -1;
posibilities[2][3] = 0;

//Lehrer
posibilities[3][0] = 0;
posibilities[3][1] = -1;
posibilities[3][2] = 0;
posibilities[3][3] = 5;

//Trainer
posibilities[4][0] = 1;
posibilities[4][1] = 0;
posibilities[4][2] = 0;
posibilities[4][3] = 4;

//new termine
posibilities[5][0] = -1;
posibilities[5][1] = 0;
posibilities[5][2] = 0;
posibilities[5][3] = 3;

//checks if the parameter vector equals one of the vectors above
for(int i = 0; i < 6; i++){
if(vectorX == posibilities[i][0] && vectorY == posibilities[i][1] && vectorZ == posibilities[i][2]){
Log.i("side", "v" + vector.toString());
Log.i("side", "s: " + posibilities[i][3]);
return posibilities[i][3];
}
}

Log.i("side", "" + -1);
return -1;
}
Thats how i calculate my cube side atm. but it s not always correct cause i only check for one rotation matrix for each side but each side has 4 rotation matrices.
So I hope somebody has a good idea how to calculate the cube side based on matrices.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Rounded Cube
« Reply #1 on: September 17, 2012, 09:14:21 pm »
If you know which polygons belong to which side, picking (see wiki) might be an option.