안녕하세요. 3D 프로그램을 내 프로그램에 구현하려고합니다. 원점에서 이동하지 않으면 완벽하게 작동합니다. 그것은 완벽하게 정확합니다. 그러나 모델 행렬을 원점에서 멀리 이동하면 (뷰 매트릭 눈은 여전히 0,0,0 임) 피킹 벡터는 여전히 원래 위치에서 그려집니다. 여전히 뷰 매트릭스 눈 (0,0,0)에서 그려야하지만 그렇지 않습니다. 이유를 찾을 수 있는지 알아 보려면 다음 코드 중 일부를 참조하십시오.3D Picking OpenGL ES 2.0 (모델 행렬 변환 후)
Vector3d near = unProject(x, y, 0, mMVPMatrix, this.width, this.height);
Vector3d far = unProject(x, y, 1, mMVPMatrix, this.width, this.height);
Vector3d pickingRay = far.subtract(near);
//pickingRay.z *= -1;
Vector3d normal = new Vector3d(0,0,1);
if (normal.dot(pickingRay) != 0 && pickingRay.z < 0)
{
float t = (-5f-normal.dot(mCamera.eye))/(normal.dot(pickingRay));
pickingRay = mCamera.eye.add(pickingRay.scale(t));
addObject(pickingRay.x, pickingRay.y, pickingRay.z+.5f, Shape.BOX);
//a line for the picking vector for debugging
PrimProperties a = new PrimProperties(); //new prim properties for size and center
Prim result = null;
result = new Line(a, mCamera.eye, far);//new line object for seeing look at vector
result.createVertices();
objects.add(result);
}
public static Vector3d unProject(
float winx, float winy, float winz,
float[] resultantMatrix,
float width, float height)
{
winy = height-winy;
float[] m = new float[16],
in = new float[4],
out = new float[4];
Matrix.invertM(m, 0, resultantMatrix, 0);
in[0] = (winx/width) * 2 - 1;
in[1] = (winy/height) * 2 - 1;
in[2] = 2 * winz - 1;
in[3] = 1;
Matrix.multiplyMV(out, 0, m, 0, in, 0);
if (out[3]==0)
return null;
out[3] = 1/out[3];
return new Vector3d(out[0] * out[3], out[1] * out[3], out[2] * out[3]);
}
Matrix.translateM(mModelMatrix, 0, this.diffX, this.diffY, 0); //i use this to move the model matrix based on pinch zooming stuff.
도움이 될만한 정보가 있습니까? 감사.
는 사실을 알아 냈다. 광선을 투영하고 설정된 평면과의 교차를 확인하는 것입니다. 나는 나중에 물체의 중심이 광선 주위에 얼마나 가깝게 있는지 점검하고, 충분히 가깝다면 그 물체를 선택했다. 그래도 고마워. – scssquatch