Author Topic: Cube rolling  (Read 636 times)

Offline FredAxis

  • byte
  • *
  • Posts: 8
    • View Profile
Cube rolling
« on: November 03, 2013, 10:36:50 pm »
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: [Select]
// 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
« Last Edit: November 03, 2013, 10:43:38 pm by FredAxis »

Offline FredAxis

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Cube rolling
« Reply #1 on: November 04, 2013, 05:42:56 pm »
Found out ..
The animating by using the interpolate function of Matrix works nice.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11749
    • View Profile
    • http://www.jpct.net
Re: Cube rolling
« Reply #2 on: November 04, 2013, 11:26:26 pm »
As long as the matrices to interpolate aren't too different, it should work fine that way.