jPCT-AE - a 3d engine for Android > Support

Problem with object picking and modified camera backbuffer matrix

<< < (5/5)

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

object part :


--- Code: ---                ...
_object.strip();
_object.build();

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

--- End code ---

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

Camera matrix part :


--- Code: ---
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;
}

}

--- End code ---

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: --- 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;

}

--- End code ---

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.

Navigation

[0] Message Index

[*] Previous page

Go to full version