How to i get inverse matrix of perspective matrix.

64 views
Skip to first unread message

wil...@gmail.com

unread,
Feb 18, 2015, 11:21:38 AM2/18/15
to kivy-...@googlegroups.com
I want to get inverse of perspective projection matrix.
But inverse member function of the matrix is not working as i thought.

look up my source please.


from kivy.graphics.transformation import Matrix
 
aspect = screen.width / screen.height
projMat = Matrix()
projMat.perspective(30., aspect, 1.0, 1000.0) 
print projMat 
 
invProjMat = projMat.inverse() 
print invProjMat 
 

Then this is result.

[[ 3.327745 0.000000 0.000000 0.000000 ]
[ 0.000000 3.732051 0.000000 0.000000 ]
[ 0.000000 0.000000 -1.002002 -2.002002 ]
[ 0.000000 0.000000 -1.000000 0.000000 ]]
 
[[ 0.300504 -0.000000 -0.000000 0.000000 ]
[ -0.000000 0.267949 0.000000 0.000000 ]
[ -0.000000 0.000000 -0.998002 0.000000 ]
[ -0.000000 -0.000000 -0.998002 1.000000 ]]


Above second matrix is inversed matrix of first matrix.
But It looks like wrong matrix.
AB isn't Identity Matrix

How can i get correct inverse matrix of perspective projection matrix?

Help me please.

oly

unread,
Feb 21, 2015, 1:03:59 PM2/21/15
to kivy-...@googlegroups.com
I have just been looking at this myself i am afraid the kivy implementation is incomplete currently, i have just solved this myself if your on the latest kivy you can pull out the matrix with .get and load it into numy and do what ever manipulation you want and put it back into the matrix class with set.

this has only been added in the past week so make sure you have checked out kivy 1.9 and built it yourself.

look here http://kivy.org/docs/api-kivy.graphics.transformation.html for the get and set methods, then just look up how todo what you want in numpy.

wil...@gmail.com

unread,
Feb 21, 2015, 4:22:00 PM2/21/15
to kivy-...@googlegroups.com
Wow!!

There was no 'get/set' methods when i found that.
But now, There is that!

Very good~

I have to resolve that like you.
Thank you for your answer~ =)


2015년 2월 22일 일요일 오전 3시 3분 59초 UTC+9, oly 님의 말:

oly

unread,
Feb 21, 2015, 5:21:33 PM2/21/15
to kivy-...@googlegroups.com
they only just got added because i was trying todo ray picking this maybe what your after in numpy.

    pm = numpy.dot(projection_matrix.T, modelview_matrix.T)
    pmi = numpy.linalg.inv(pm)
Reply all
Reply to author
Forward
0 new messages