We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › perspective transformation matrix
Page Index Toggle Pages: 1
perspective transformation matrix (Read 580 times)
perspective transformation matrix
Jul 15th, 2008, 12:13am
 
Hi, I'm stuck with this custom perspective matrix thing.

I would like to perform a custom perspective transformation (exactly like Gimp's perspective tool). Actually, I want to map a quad (the applet window) to another quad (arbitrary coordinates). I am using Sun's Java Advanced Imaging (JAI) library since it seems to provide all needed methods for such things.

The problem is, I reset the matrix and apply the matrix I just got from JAI, and I've got this ArrayIndexOutOfBoundsException. If I don't reset the matrix before applying the new one, I don't get expected results either.

Here is the matrix JAI is returning and that I would like to apply :
Code:
Perspective transform matrix
90000.0 0.0 6000000.0
0.0 80000.0 6000000.0
0.0 0.0 120000.0

Here is what I get with printMatrix() after reseting and applying (looks ok) :
Code:
0090000,0000  0000000,0000  6000000,0000  0000000,0000
0000000,0000 0080000,0000 6000000,0000 0000000,0000
0000000,0000 0000000,0000 0120000,0000 0000000,0000
0000000,0000 0000000,0000 0000000,0000 0000001,0000

My window's dim are 400 x 300 and I've got this exception (looks like an overflow) :
Code:
java.lang.ArrayIndexOutOfBoundsException: 120200

at processing.core.PLine.drawLine_plain_spatial(PLine.java:762)
...


What's wrong?
Re: perspective transformation matrix
Reply #1 - Jul 15th, 2008, 10:10am
 
Apologies if you are already aware of this and I am just stating the obvious...

The error message for an array out of bounds exception will give you the  position of the array that is out of bounds, not array contents. Since the erroneous array position is 120200, my guess would be that somewhere in your code, there is a confusion between the contents of the array (of order 120000) and its position (0-8).
Re: perspective transformation matrix
Reply #2 - Jul 15th, 2008, 11:06am
 
Actually, I am not iterating the array myself, so there is no possible confusion. I'm just drawing a simple rect and the exception is thrown at runtime when - it seems - Processing tries to draw things out of screen : 120200 is just above 400x300 (which are my window's dimensions).

I think the values I try to apply to the matrix should be somehow scaled down but is there a rule?

Edit : I think I'm going to give up this matrix thing (just thought of another idea for simulating the perspective).
Page Index Toggle Pages: 1