Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mat4.look_at not as expected #708

Closed
gizmoore opened this issue Nov 18, 2022 · 6 comments
Closed

Mat4.look_at not as expected #708

gizmoore opened this issue Nov 18, 2022 · 6 comments
Labels
bug Something isn't working reproducible Has example code which reproduces the issue

Comments

@gizmoore
Copy link

I started with the example/openGL

I noticed instead of using the look_at to set the view matrix, the example used:
window.view = Mat4.from_translation(Vec3(0, 0, -5))

I tried to get the same result using:
window.view = Mat4.look_at(Vec3(0, 0, -5), Vec3(0, 0, 0), Vec3(0, 1, 0))

But it didn't match. I tried some other cases and also tried comparing with Euclid Matrix4.new_look_at().transposed(). If I create simple camera positions with translate and rotate, they match the Euclid look_at matrix, but not the Mat4.look_at.

Please let me know if I have the wrong idea on how the look_at should work.

test_Mat4.zip

@benmoran56
Copy link
Member

This method was a fairly recent addition, and as you pointed out is not being used internally in pyglet (or the examples) yet.

I think the intention of this method was to mimic what something like GLM produces, so for good measure we should give this a check against PyGLM.

@einarf
Copy link
Member

einarf commented Nov 19, 2022

https://glm.g-truc.net/0.9.5/api/a00176.html#ga454fdf3163c2779eeeeeb9d75907ce97

I'm not sure if PyGLM have implemented look_at (yet).

@benmoran56
Copy link
Member

It looks like they have. I did a quick comparison, and it does confirm that pyglet's implementation is off.

>>> v1 = 0, 0, -5
>>> v2 = 0, 0, 0
>>> v3 = 0, 1, 0
>>> 
>>> pm = Mat4.look_at(Vec3(*v1), Vec3(*v2), Vec3(*v3))
>>> print(list(pm))
[-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 5.0, 1.0]
>>> 
>>> gm = glm.lookAt(glm.vec3(*v1), glm.vec3(*v2), glm.vec3(*v3))
>>> print([e for sublist in gm.to_list() for e in sublist])
[-1.0, 0.0, -0.0, 0.0, 0.0, 1.0, -0.0, 0.0, 0.0, -0.0, -1.0, 0.0, -0.0, -0.0, -5.0, 1.0]
>>> 
>>> em = euclid.Matrix4.new_look_at(euclid.Vector3(*v1), euclid.Vector3(*v2), euclid.Vector3(*v3))
>>> print([float(e) for e in list(em)])
[-1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, -5.0, 1.0]

@benmoran56 benmoran56 added bug Something isn't working reproducible Has example code which reproduces the issue labels Nov 21, 2022
@einarf
Copy link
Member

einarf commented Nov 21, 2022

Ah nice. Definitely keeping them indentical is a good idea.

benmoran56 added a commit that referenced this issue Nov 24, 2022
@benmoran56
Copy link
Member

@gizmoore This should now be fixed in master. Can you let us know how it goes?
Mat4.look_at should now function the same as glm.lookAt (with some small differences due to float precision).

I also updated the examples/3dmodel/model.py example to use this method. It's not "interactive", but might be useful as a starting point for someone.

@gizmoore
Copy link
Author

gizmoore commented Dec 2, 2022

@gizmoore This should now be fixed in master. Can you let us know how it goes? Mat4.look_at should now function the same as glm.lookAt (with some small differences due to float precision).

I also updated the examples/3dmodel/model.py example to use this method. It's not "interactive", but might be useful as a starting point for someone.

This works great now, thanks for fixing so quickly.

@gizmoore gizmoore closed this as completed Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproducible Has example code which reproduces the issue
Projects
None yet
Development

No branches or pull requests

3 participants