humbletim / glm-js

JavaScript adaptation of the OpenGL Mathematics (GLM) C++ library interfaces. JavaScript adaptation of the OpenGL Mathematics (GLM) C++ library interfaces. (project currently inactive)
http://humbletim.github.io/glm-js/
Other
43 stars 5 forks source link

lookAt returns a vector instead of a matrix #2

Closed Beuc closed 7 years ago

Beuc commented 7 years ago

Hi,

Thanks for writing a JS library compatible with GLM! Much appreciated to try and port my https://en.wikibooks.org/wiki/OpenGL_Programming#The_basics_arc tutorials :)

I found a bug: glm.lookAt returns a quat rather than a matrix. Cf. http://glm.g-truc.net/0.9.8/glm-0.9.8.pdf §5.2. At first glance, stripping "glm.quat" in the various implementation of 'lookAt' in source code fixes the issue.

Note: I wanted to test my changes but I cannot run 'make test' or 'make build' from nodejs (tested with v4.7.2 and 6.9.2), I get various errors:

humbletim commented 7 years ago

Hi Beuc,

Cool! Porting those kinds of tutorials sounds like an interesting use case.

As a short term workaround you could try converting the return value to a matrix using var m = glm.toMat(glm.lookAt(...)));

And yeah... my hacked-together build system needs some TLC. Fortunately, you can also bootstrap glm-js from source (ie: without any build system or minification); here's a quick snippet to demonstrate:

Hope that helps and I'll schedule a permanent fix for glm.quat with the next update.

Regards, -Tim

Beuc commented 7 years ago

Hi,

AFAICS this work-around is incomplete. When I try it, the tut05 rotating cube is not centered on the screen anymore. Inspecting the results shows that the last matrix vector (last line in toString()) is zero'd:

# GLM 31728cb4
glm.toMat4(glm.lookAt(glm.vec3(0.0, 2.0, 0.0), glm.vec3(0.0, 0.0, -4.0), glm.vec3(0.0, 1.0, 0.0))).toString()
"mat4x4(
    (1.000000, 0.000000, 0.000000, 0.000000), 
    (0.000000, 0.894427, 0.447214, 0.000000), 
    (0.000000, -0.447214, 0.894427, 0.000000), 
    (0.000000, 0.000000, 0.000000, 1.000000)
)"

# patched GLM without the extra "glm.quat" in glm.lookAt
# (AFAIU "glm-js.min.js" is relying on GL-Matrix.)
glm.lookAt(glm.vec3(0.0, 2.0, 0.0), glm.vec3(0.0, 0.0, -4.0), glm.vec3(0.0, 1.0, 0.0)).toString()
"mat4x4(
    (1.000000, 0.000000, 0.000000, 0.000000), 
    (0.000000, 0.894427, 0.447214, 0.000000), 
    (0.000000, -0.447214, 0.894427, 0.000000), 
    (0.000000, -1.788854, -0.894427, 1.000000)
)"

Thanks for sharing the non-minified setup, though what I aimed at was running the test suite against a patch so I could submit it here :)

humbletim commented 7 years ago

Thanks for sharing the non-minified setup, though what I aimed at was running the test suite against a patch so I could submit it here :)

OK, will figure out the missing console dependencies so the command line test / build can be used by others. :)

Just to mention -- you can also run the entire test suite locally using a web browser -- like by opening file:///..../glm-js/test/index.html from the project folder.

humbletim commented 7 years ago

ps: I see now that the glm.toMat4 workaround can't ever work here -- because the glm.quat only brings forward the rotation information, while the lookAt matrix also contains a translation.

Beuc commented 7 years ago

Cf. #5 for a patch :)

humbletim commented 7 years ago

Thanks! :)