I guess I figured that out mtself:
public int calcFlingDirection(PointF start, PointF finish,
FrameBuffer fb, Object3D selCube, World world) {
Camera cam=world.getCamera();
// Convert start into a direction vector in world space:
SimpleVector direction1 = new SimpleVector( Interact2D.reproject2D3DWS(
cam, fb, (int)start.x, (int) start.y ) ).normalize();
// Convert finish into a direction vector in world space:
SimpleVector direction2 = new SimpleVector( Interact2D.reproject2D3DWS(
cam, fb,(int) finish.x, (int) finish.y ) ).normalize();
// Calculate the distance to whatever was clicked on:
SimpleVector pos=cam.getCamera().getPosition();
float distance1 = world.calcMinDistance( pos, direction1, 10000 );
float distance2 = world.calcMinDistance( pos, direction2, 10000 );
// Calculate the 3D coordinates for the point that was clicked in world coordinates:
SimpleVector collisionPoint1 = new SimpleVector( direction1 );
collisionPoint1.scalarMul( distance1 );
collisionPoint1.add( cam.getCamera().getPosition() );
collisionPoint1.matMul(selCube.getInverseWorldTransformation());
SimpleVector collisionPoint2 = new SimpleVector( direction2 );
collisionPoint2.scalarMul( distance2 );
collisionPoint2.add( cam.getCamera().getPosition() );
collisionPoint2.matMul(selCube.getInverseWorldTransformation());
collisionPoint2=round(collisionPoint2);
SimpleVector diff=new SimpleVector(collisionPoint2);
diff.calcSub(collisionPoint1);
int res='x';
if (diff.x<0)
res=-res;
float x2=(diff.x>0 ? diff.x : - diff.x);
float y2=(diff.y>0 ? diff.y : - diff.y);
float z2=(diff.z>0 ? diff.z : - diff.z);
if (y2>x2) {
res='y';
if (diff.y<0)
res=-res;
}
if ( (z2>y2) && (z2>x2)) {
res='z';
if (diff.z<0)
res=-res;
}
return res;
}
The above code returns 'x',-'x','y',-'y','z',-'z' in local coordinates (cube coordinates)
This is working fine on my tests. Please notice that both points MUST collide with the cube surface.