Re: [PyOpenGL-Users] Perspective and LookAt matrices: Python implementation renders nothing
Brought to you by:
mcfletch
From: Florian N. <flo...@en...> - 2015-11-28 20:16:53
|
I forgot to join my lookAt function: def getLookAtMatrix(_eye, _lookat, _up): ez = _eye - _lookat ez = ez / np.linalg.norm(ez) ex = np.cross(_up, ez) ex = ex / np.linalg.norm(ex) ey = np.cross(ez, ex) ey = ey / np.linalg.norm(ey) rmat = np.eye(4) rmat[0][0] = ex[0] rmat[0][1] = ex[1] rmat[0][2] = ex[2] rmat[1][0] = ey[0] rmat[1][1] = ey[1] rmat[1][2] = ey[2] rmat[2][0] = ez[0] rmat[2][1] = ez[1] rmat[2][2] = ez[2] tmat = np.eye(4) tmat[0][3] = -_eye[0] tmat[1][3] = -_eye[1] tmat[2][3] = -_eye[2] # numpy.array * is element-wise multiplication, use dot() lookatmat = np.dot(rmat, tmat).transpose() > Le 28 nov. 2015 à 21:09, Florian NICOLAS <flo...@en...> a écrit : > > >> Le 28 nov. 2015 à 18:15, Nicolas P. Rougier <Nic...@in...> a écrit : >> >> >>> I also provide my running code (where getXRotation, getYRotation and getZRotation behave as expected) so I suppose the issue com from my perspective and lookAt matrices. >> >> >> Make sure to stick to np.float32 when you create matrices > It is done but it changes nothing apparently. Part of my problem was that I did not use numpy.dot (stupid mistake!). Could someone have a look at my lookAt function? Indeed, I do not understand why, when I set the Z component of my view vector (for example incrementing it thanks to the clock variable), the size of my cube does not decrease on screen as the distance between my camera and my cube increase. Is there any problem with my depth buffer? >> >>> >>> I have two last questions about matrices in GLSL: >>> - I have found that mat*vec4(position, 1) and vec4(position,1)*mat do not trigger any errors while the latter, in my opinion, should fail, why? >> >> See section 5.11 of GLSL spec at https://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf > > Ok, I will only use mat*vect to match the mathematical theory :). I will go deeper into glsl matrix/vector operations later. > I >> >> >>> - As OpenGL and bumpy are not identically ordered (column/row major), should I always have to transpose my matrix before using OpenGL functions? >> >> You can fix the order in the shader. >> >> >> Nicolas > |