samboooo / pyeuclid

Automatically exported from code.google.com/p/pyeuclid
0 stars 0 forks source link

Matrix4.new_look_at is incomplete and gives incorrect results #24

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Using Matrix4.new_look_at doesn't yield the expected results.

It looks like this:

    def new_look_at(cls, eye, at, up):
      z = (eye - at).normalized()
      x = up.cross(z).normalized()
      y = z.cross(x)

      m = cls.new_rotate_triple_axis(x, y, z)
      m.d, m.h, m.l = eye.x, eye.y, eye.z
      return m
    new_look_at = classmethod(new_look_at)

But should look something like this:

    def new_look_at(cls, eye, at, up):
      z = (eye - at).normalized()
      x = up.cross(z).normalized()
      y = z.cross(x)
      m = cls.new_rotate_triple_axis(x, y, z)
      m.transpose()
      m.d, m.h, m.l = -x.dot(eye), -y.dot(eye), -z.dot(eye)
      return m
    new_look_at = classmethod(new_look_at)

While translating the http://open.gl/ tutorials from C++ and SFML to Python and 
Pyglet I used pyeuclid in place for GLM, everything worked except for 
Matrix4.new_look_at , that is until I changed it like shown above.

The discussion that brought about the change can be found here: 
http://stackoverflow.com/questions/25027045/applying-glm-like-perspective-and-lo
okat-calculations-results-in-my-shape-di

Example code that doesn't work with the old method but does with the new can be 
found in 4-2.py, 5-1.py, and 5-2.py here: 
https://github.com/01AutoMonkey/open.gl-tutorials-to-pyglet/

And here is the relevant code sniped:

    eye = Vector3(1.2, 1.2, 1.2)
    at = Vector3(0.0, 0.0, 0.0)
    up = Vector3(0.0, 0.0, 1.0)
    view = Matrix4.new_look_at(eye, at, up)
    view = view[:]
    view_ctype = (GLfloat * len(view))(*view)
    uniView = glGetUniformLocation(shaderProgram, "view")
    glUniformMatrix4fv(uniView, 1, GL_FALSE, view_ctype)

Original issue reported on code.google.com by gautamad...@gmail.com on 15 Aug 2014 at 5:33