I'm using the Kube application from Android API Samples for an application I'm working on.
The sample creates a model of the Rubik's Cube in OpenGL made out of 27 small cubes. Afterwards the cube is being scrambled in the animate() method by rotating random layers of the cube, after each rotation the layers are being set accordingly in a process I don't fully understand
// adjust mPermutation based on the completed layer rotation
int[] newPermutation = new int[27];
for (int i = 0; i < 27; i++) {
newPermutation[i] = mPermutation[mCurrentLayerPermutation[i]];
// newPermutation[i] = mCurrentLayerPermutation[mPermutation[i]];
}
mPermutation = newPermutation;
updateLayers();
The sample works fine but for some reason when I change the direction of the rotation to true, the cubes start overlapping each other, as if the layers weren't updated correctly.
Help would be appreciated :)
I solved the problem myself, so in case anyone is interested:
changing the direction to true makes the cube rotate in the other direction, which is like rotating three times in the regular direction so in order to save to cubes new location correctly I need to save the new location three times, as seen in the code below:
if (mAngleIncrement < 0) { // checks the turning direction
int[] newPermutation = new int[27];
for (int i = 0; i < 27; i++) {
newPermutation[i] = mPermutation[mCurrentLayerPermutation[i]];
}
mPermutation = newPermutation;
updateLayers();
}
else {
int[] newPermutation = new int[27];
for (int i = 0; i < 27; i++) {
newPermutation[i] = mPermutation[mCurrentLayerPermutation[i]];
}
mPermutation = newPermutation;
newPermutation = new int[27];
for (int i = 0; i < 27; i++) {
newPermutation[i] = mPermutation[mCurrentLayerPermutation[i]];
}
mPermutation = newPermutation;
newPermutation = new int[27];
for (int i = 0; i < 27; i++) {
newPermutation[i] = mPermutation[mCurrentLayerPermutation[i]];
}
mPermutation = newPermutation;
updateLayers();
}
Related
I created 5 sprites using libgdx library, then want to assign the different size to all of them between 0 to 10 and then move from left to right. 5 sprite is succussfully created but the problem is in the size. i tried the S.nextInt(10). but its not working.
Also i want to create all the sprites between 100-200 height. how to do it?
int number = 5;
sprite = new Sprite[number];
for (int i = 0; i < number; i++) {
sprite[i] = new Sprite(texture);
int size = S.nextInt(10);
sprite[i].setSize(size, size);
speed = S.nextInt(2);
sprite[i].setPosition(speed, 100);
}
batch.begin();
for (int i = 0; i < number; i++) {
sprite[i].draw(batch);
}
batch.end();
i have a large image ,then i cut it into 9 equal small images. that is my code
Image pricer[][] = new Image[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
pricer[i][j] = new Image(TextureRegion.split(bg, tile, tile)[i][j]);
pricer[i][j].setSize(200, 200);
pricer[i][j].setPosition((j*200),600-(i*200));
stage.addActor(pricer[i][j]);
}
}
now, i want to create border for those images that i devide into small peace.many thanks for your help
You can use a ShapeRenderer:
ShapeRenderer renderer = new ShapeRenderer();
renderer.begin(ShapeType.Line)
renderer.setColor(color);
renderer.rect(image.getImageX(), image.getImageY(), image.getImageWidth(), image.getImageHeight);
renderer.end();
I am doing a CCPointFromString conversion but my coding crashing whenever I am trying to take input, Here is the code , what I am doing wrong?
CCPoint *temp = new CCPoint(oldLocationCon.x, oldLocationCon.y);
pointInsert->addObject(temp);
for(int i=0; i<pointInsert->count(); i++){
CCString point = (CCString*)pointInsert->objectAtIndex(i);
CCPoint savePoint= CCPointFromString(point->getCString());
}
CCArray * pointInsert = CCArray::create();
CCPoint * temp = new CCPoint(0, 0);
pointInsert->addObject(temp);
for(int i = 0; i < pointInsert->count(); i++){
CCString * point = static_cast<CCString*>(pointInsert->objectAtIndex(i));
CCPoint savePoint= CCPointFromString(point->getCString());
}
If I have an image containing black lines, like the image below. How can I detect the black lines.( to know the x,y of dots on this lines) ?
I want to know how to get started with this topic. What library should I learn to go through
You can use Catalano Framework.
http://code.google.com/p/catalano-framework/
FastBitmap image = new FastBitmap(bitmap);
image.toGrayscale();
int width = image.getWidth();
int height = image.getHeight();
ArrayList<IntPoint> lst = new ArrayList<>();
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (image.getGray(i, j) == 0)
lst.add(new IntPoint(i,j));
}
}
int[] images2 = {
R.drawable.wrong, R.drawable.reviewp,
R.drawable.bowl, R.drawable.ic_action_search
};
List<int[]> pic=Arrays.asList(images2);
Collections.shuffle(pic);
Random random = new Random();
for(int i = 0 ; i <= 3 ; i++){
ReciverI[i].setBackgroundResource(images2[ "at here i want to get the image position" ]);
}
help me to get the position of image
this is not working
ReciverI[i].setBackgroundResource(images2[Integer.parseInt(pic.get(i).toString())]);
this give me wrong result
I rewrite the code
Solution 1
Integer[] images2 = {R.drawable.wrong, R.drawable.reviewp, R.drawable.bowl,R.drawable.ic_action_search};
List<Integer> pic=Arrays.asList(images2);
Collections.shuffle(pic);
for(int i = 0 ; i <= pic.size() ; i++){
ReciverI[i].setBackgroundResource(pic.get(i))
}
You want absolutely to conserve the primitiv int then you have to make a little walk around
Solution 2
List<Integer> pic = new ArrayList<Integer>();
for (int index = 0; index < images2.length; index++)
{
pic.add(images2[index]);
}
Collections.shuffle(pic);
for(int i = 0 ; i <= pic.size() ; i++){
ReciverI[i].setBackgroundResource(pic.get(i))
}
ReciverI[i].setBackgroundResource(pic.get(i))
Sorry wasn't paying attention. You should just make your List<int> and it will work.
As your snippet is now, it has no use to have a List of integer arrays.