Problem with object picking and modified camera backbuffer matrix

Started by redfalcon, December 15, 2011, 03:40:51 PM

Previous topic - Next topic

EgonOlsen

That won't work, because Camera accesses the position directly and not via some getter. Are you sure that the position is in 12, 13, 14 and not in 3, 7, 11.... why else should it be the origin in the second case?

Vi_O

I have check my code, and after adjusting some tranformation matrices, it works ! Thanks !

One problem still remains : I don't know why, it doesn't pick planes... Is there a special settings to apply in order to pick planes ?

EgonOlsen

No. A plane is an object just like any other. Make sure that you have the collision modes set correctly and that you are not trying to pick the backside of a plane with culling disabled, because you can't pick backsides even if they are visible.

Vi_O

That was a backside picking problem, I have flipped the plan and now it works !

Thanks a lot !

EgonOlsen

Can you post your final solution to this problem? It seems to be a common problem and i haven't seen a solution that anybody was able to use so far.

Vi_O

Ok, I'll try to synthetize my code and make it as clear as I can :

object part :


                ...
_object.strip();
_object.build();

_object.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS|Object3D.COLLISION_CHECK_SELF);
_object.setCollisionOptimization(true);


I'm not sure collision optimization and CHECK_SELF are necessary but It works that way so... I keep it.

Camera matrix part :



public boolean setCameraMatrix(float[] matrix){

if (_camera != null){

_cameraPosition.set(matrix[12],matrix[13],matrix[14]);
matrix[12] = matrix[13] = matrix[14] = 0;

_cameraMatrix.setDump(matrix);
_cameraMatrix = _cameraMatrix.invert();

_camera.setBack(_cameraMat);
_camera.setPosition(_cameraPosition);

return true;

} else {
return false;
}

}


Here, I guess you could invert the matrix before calling setCameraMatrix ( and you would have to change 12/13/14 to 3/7/11) but again, it works that way... So I keep it.

Picking part :


public Object3D pick(int x,int y){

Log.d("jpctEngine", "Picking...");

SimpleVector dir=Interact2D.reproject2D3DWS(_camera, _frameBuffer, x, y).normalize();
Object[] res=_world.calcMinDistanceAndObject3D(_camera.getPosition(), dir, 10000 /*or whatever*/);

if (res[1] != null){
Log.d("Jpct-Engine","Picking réussi.");
return res[1];
}

return null;

}


In fact, the advices you gave on picking work well.
But somehow, dumping a false(maybe inverted) matrix still gives a nice graphical result and craps the picking. Seeing graphics working, I thought the matrix was OK and looked for the problem elsewhere... Matrices are very tricky...

Well, now that's fixed ^^ thanks again, I hope this comment will help !

Bye.