1

I've a problem using glm math lib with simd. I've encounter a problem during the calculation of the lookat matrix.

Follow my lookAt functions:

FORCE_INLINE_ALWAYSINLINE const glm::detail::fmat4x4SIMD LookAt( const glm::detail::fvec4SIMD &eyePos, const glm::detail::fvec4SIMD &lookAtPos, const glm::detail::fvec4SIMD &upVec )
{
    glm::detail::fvec4SIMD v3X, v3Y, v3Z;

    v3Y = glm::normalize(upVec);
    v3Z = glm::normalize(eyePos - lookAtPos);
    v3X = glm::normalize(glm::cross(v3Y, v3Z));
    v3Y = glm::cross(v3Z, v3X);

    glm::detail::fmat4x4SIMD m4EyeFrame = glm::detail::fmat4x4SIMD(v3X, v3Y, v3Z, eyePos);

    return m4EyeFrame;
}

Unfortunately doesn't work well, for example: If the eyePos (the camera position) is in 0,0,-10 and lookAtPos (target position) is in 0,0,0 and the object is at that position, the view work well. But if I move eyePos on X or Y axis, the model seems deformed (like stretched) or disappears as if it had gone outside of the frustum, but in real it is still within. NOTE: every fourth element of fvec4SIMD is set to 1.0f

I've also read this post: My SSE implementation of lookAt doesn't work but I cannot use within fmat4x4SIMD because of rows to columns translation, maybe I need to shuffle all elements to convert from row to column, but I don't know how to do it in a fast way. This is just my impression, but maybe the problem lies elsewhere.

Any suggestion?

Nicol Bolas
  • 378,677
  • 53
  • 635
  • 829
Kohal
  • 11
  • 2
  • "NOTE: every fourth element of fvec4SIMD is set to 1.0f" it shouldn't be for `upVec`, instead it should be 0.0f – ratchet freak Nov 05 '14 at 15:45
  • 1
    Hi ratchet, I tried your suggestion, but it didn't work, but you made me think to set to 0 also the 'w' value of the right vector and the forward vector that I used to multiply the camera matrix position... and WORKS!!! Thanks! – Kohal Nov 05 '14 at 16:28
  • I have a suggestion that you might not like: you dont _need_ a SIMD implementation of `lookAt()` because it will not be a perf bottleneck, unless you are doing something very strange. This smells like premature optimization, unless you are doing it for the educational exercise. – Preet Kukreti Oct 16 '17 at 10:40

0 Answers0