Cube rolling

Started by FredAxis, November 03, 2013, 10:36:50 PM

Previous topic - Next topic

FredAxis

Hi everybody!

I am just starting in jpct with a basic project. So I came here for some basic questions I guess.

I want to roll a cube to the side that is touched by the user to the front. I managed to create a cube with 4 plane objects added as child to an object at the center. I put each orientation of a side in an array to move to when it was clicked. Works fine but at the moment but with no interpolation. It just switch to the orientation and that's it.

1.) Is there a common way to interpolate the positions to the next best rotation point? w/o rotating to the wrong way and turning around too much

2.) The sides of the cube are now only colors. So it may look strange when the cube rotates more than necessary. I am not sure how to manage this at the moment. Any ideas about that would be much appreciated.

3.) It seems to me that not all clicks are giving the right side/color of the cube. I guess the boundary box is used to get the clicked object. Is there an more accurate way? I put my code next here ...


// code at touch event

SimpleVector dir = Interact2D.reproject2D3DWS(world.getCamera(), fb, Math.round(me.getX()) , Math.round(me.getY())) .normalize();

Object[] res=world.calcMinDistanceAndObject3D(world.getCamera().getPosition(), dir, 10000 /*or whatever*/);

float f = world.calcMinDistance(world.getCamera().getPosition(), dir, 1000);
 
if (f != Object3D.COLLISION_NONE ){

Object3D picked = (Object3D)res[1];

TextView tv = (TextView) findViewById(R.id.textHit);

String nam = picked.getName();

tv.setText( nam);

int idx = indexOf ( nam, colorNames);


if (idx>-1){
rotAim = rotAims[idx];

cube.clearRotation();
cube.rotateX(rotAim[0] * rad );
cube.rotateY(rotAim[1] * rad );
}
}




It would be nice see any advice.

thanks in advance!

Fred

FredAxis

Found out ..
The animating by using the interpolate function of Matrix works nice.

EgonOlsen

As long as the matrices to interpolate aren't too different, it should work fine that way.