쥔장, 이 코드 킵 .. (기저 벡터를 통한 회전)

  ...

  const zaxis = dir.negate().normalize().toConst();
  const xaxis = cross(vec3(0, 1, 0), zaxis).normalize().toConst();
  const yaxis = cross(zaxis, xaxis).toConst();

  const mat = mat3(
    xaxis.x, yaxis.x, zaxis.x,
    xaxis.y, yaxis.y, zaxis.y,
    xaxis.z, yaxis.z, zaxis.z
  ).toConst();

  const finalVert = modelWorldMatrix.mul(mat.mul(positionLocal))
    .add(positionStorage.element(instanceID)).toConst();

  return cameraProjectionMatrix.mul(cameraViewMatrix).mul(finalVert);
}

아래는 dir(forward; 바라보는 방향 벡터), up(“위쪽”을 정의하는 기준 벡터)를 알고 있을때, 단위벡터라고 할때 회전 행렬을 얻는 함수이다.

mat3 lookAt(vec3 dir, vec3 up) {
  vec3 right = cross(dir, up);
  true_up = cross(right, dir);
  return mat(right, true_up, -dir);
}

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다