Author Topic: Problem with object picking and modified camera backbuffer matrix  (Read 42099 times)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12298
    • View Profile
    • http://www.jpct.net
Re: Problem with object picking and modified camera backbuffer matrix
« Reply #15 on: January 09, 2012, 05:34:57 pm »
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?

Offline Vi_O

  • byte
  • *
  • Posts: 17
    • View Profile
Re: Problem with object picking and modified camera backbuffer matrix
« Reply #16 on: January 10, 2012, 05:43:28 pm »
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 ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12298
    • View Profile
    • http://www.jpct.net
Re: Problem with object picking and modified camera backbuffer matrix
« Reply #17 on: January 10, 2012, 08:16:49 pm »
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.

Offline Vi_O

  • byte
  • *
  • Posts: 17
    • View Profile
Re: Problem with object picking and modified camera backbuffer matrix
« Reply #18 on: January 11, 2012, 11:08:33 am »
That was a backside picking problem, I have flipped the plan and now it works !

Thanks a lot !

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12298
    • View Profile
    • http://www.jpct.net
Re: Problem with object picking and modified camera backbuffer matrix
« Reply #19 on: January 11, 2012, 11:33:20 am »
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.

Offline Vi_O

  • byte
  • *
  • Posts: 17
    • View Profile
Re: Problem with object picking and modified camera backbuffer matrix
« Reply #20 on: January 11, 2012, 12:16:17 pm »
Ok, I'll try to synthetize my code and make it as clear as I can :

object part :

Code: [Select]
                ...
_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 :

Code: [Select]

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 :

Code: [Select]
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.