행렬을 작성하려고합니다. 행렬을 살펴 보려고했지만, 어딘가에 오류가있어서 찾아 내야합니다. 필자가 사용해야하는 삼각형의 테스트 뷰가 아닌 필자의 함수를 사용할 때 빈 화면이 표시됩니다.LookAt 행렬을 계산하십시오.
public static Mat4 lookAt(
float eyeX, float eyeY, float eyeZ, //Where we are looking from
float centreX, float centreY, float centreZ, //Where we are looking to
float upX, float upY, float upZ) //Which way is up
{
Vec3 eye = new Vec3(eyeX, eyeY, eyeZ);
Vec3 target = new Vec3(centreX, centreY, centreZ);
Vec3 up = new Vec3(upX, upY, upZ);
Vec3 zaxis = normal(subtract(target,eye)); // The "forward" vector.
Vec3 xaxis = normal(cross(up, zaxis)); // The "right" vector.
Vec3 yaxis = cross(zaxis, xaxis); // The "up" vector.
// [ right.x right.y right.z 0]
// [ up.x up.y up.z 0]
// [-forward.x -forward.y -forward.z 0]
// [ 0 0 0 1]
Mat4 orientation = new Mat4(
new Vec4(xaxis.get()[0], yaxis.get()[0], -zaxis.get()[0], +0.0f), //Column 1
new Vec4(xaxis.get()[1], yaxis.get()[1], -zaxis.get()[1], +0.0f), //Column 2
new Vec4(xaxis.get()[2], yaxis.get()[2], -zaxis.get()[2], +0.0f), //Column 3
new Vec4(+0.0f, +0.0f, +0.0f, +1.0f) //Column 4
);
Mat4 translation = new Mat4 (
new Vec4(+1.0f, +0.0f, +0.0f, +0.0f), //Column 1
new Vec4(+0.0f, +1.0f, +0.0f, +0.0f), //Column 2
new Vec4(+0.0f, +0.0f, +1.0f, +0.0f), //Column 3
new Vec4(-eye.get()[0], -eye.get()[1], -eye.get()[2], +1.0f) //Column 4
);
return multiply(orientation, translation);
}
오른손잡이 좌표계 용입니다. 모든 행렬은 주요 열입니다. a11에서 시작하여 첫 번째 열을 a41로 이동 한 다음 a12로 이동하고 a44에서 계속 이동합니다.
나는 다음과 같은 기능을 통해 갔다 그리고 나는 그들이 올바른 상당히 확신하지만 난 단지의 경우 내가 간과 한 일을 포함했다 :
Vec3 normal(Vec3 a)
{
Vec3 unit;
float[] v_a = a.get();
float v_mag = magnitude(a);
unit = new Vec3(v_a[0]/v_mag, v_a[1]/v_mag, v_a[2]/v_mag);
return unit;
}
-
float magnitude(Vec3 a)
{
float[] v_a = a.get();
return((float)Math.sqrt(
Math.pow((double)v_a[0], 2) +
Math.pow((double)v_a[1], 2) +
Math.pow((double)v_a[2], 2)
) // -- end sqrt --
); // -- return --
}
을 -
Vec3 cross(Vec3 a, Vec3 b)
{
Vec3 crossProduct;
float[] v_a = a.get();
float[] v_b = b.get();
crossProduct = new Vec3(
v_a[1]*v_b[2] - v_a[2]*v_b[1], //cx = ay*bz - az*by
v_a[2]*v_b[0] - v_a[0]*v_b[2], //cy = az*bx - ax*bz
v_a[0]*v_b[1] - v_a[1]*v_b[0] //cz = ax*by - ay*bz
);
return(crossProduct);
}
모든 벡터 할당이 정확합니다. get()은 float []를 반환합니다.
아마도 javax.media.opengl.glu.GLU.gluLookAt()의 소스 코드를 살펴 봐야 할 것입니다. – gouessej
소스 코드를 살펴 보았습니다. 문제는 코드에 오류가있어서 찾는데 도움이 필요하다는 것입니다. 다시 GLU 소스 코드를 살펴 보면 그렇게 할 수 없습니다. – Francis