2 * PROJECT: NyARToolkit(Extension)
\r
3 * --------------------------------------------------------------------------------
\r
4 * The NyARToolkit is Java edition ARToolKit class library.
\r
5 * Copyright (C)2008-2009 Ryo Iizuka
\r
7 * This program is free software: you can redistribute it and/or modify
\r
8 * it under the terms of the GNU General Public License as published by
\r
9 * the Free Software Foundation, either version 3 of the License, or
\r
10 * (at your option) any later version.
\r
12 * This program is distributed in the hope that it will be useful,
\r
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 * GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
20 * For further information please contact.
\r
21 * http://nyatla.jp/nyatoolkit/
\r
22 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
\r
25 package jp.nyatla.nyartoolkit.core.utils;
\r
27 import jp.nyatla.nyartoolkit.NyARException;
\r
28 import jp.nyatla.nyartoolkit.core.types.NyARIntPoint2d;
\r
31 * 遠近法を用いたPerspectiveパラメータを計算するクラスです。
\r
34 public class NyARPerspectiveParamGenerator
\r
36 protected int _local_x;
\r
37 protected int _local_y;
\r
38 protected int _width;
\r
39 protected int _height;
\r
40 public NyARPerspectiveParamGenerator(int i_local_x,int i_local_y,int i_width, int i_height)
\r
42 this._height=i_height;
\r
43 this._width=i_width;
\r
44 this._local_x=i_local_x;
\r
45 this._local_y=i_local_y;
\r
48 public boolean getParam(final NyARIntPoint2d[] i_vertex,double[] o_param)throws NyARException
\r
52 double ltx=this._local_x;
\r
53 double lty=this._local_y;
\r
54 double rbx=ltx+this._width;
\r
55 double rby=lty+this._height;
\r
56 la1=new double[4][5];
\r
57 la2=new double[4][5];
\r
61 la1[0][0]=ltx; la1[0][1]=lty; la1[0][2]=1; la1[0][3]=-ltx*i_vertex[0].x; la1[0][4]=-lty*i_vertex[0].x;
\r
62 la1[1][0]=rbx; la1[1][1]=lty; la1[1][2]=1; la1[1][3]=-rbx*i_vertex[1].x; la1[1][4]=-lty*i_vertex[1].x;
\r
63 la1[2][0]=rbx; la1[2][1]=rby; la1[2][2]=1; la1[2][3]=-rbx*i_vertex[2].x; la1[2][4]=-rby*i_vertex[2].x;
\r
64 la1[3][0]=ltx; la1[3][1]=rby; la1[3][2]=1; la1[3][3]=-ltx*i_vertex[3].x; la1[3][4]=-rby*i_vertex[3].x;
\r
65 ra1[0]=i_vertex[0].x;ra1[1]=i_vertex[1].x;ra1[2]=i_vertex[2].x;ra1[3]=i_vertex[3].x;
\r
66 NyARSystemOfLinearEquationsProcessor.doGaussianElimination(la1,ra1,5,4);
\r
69 la2[0][0]=ltx; la2[0][1]=lty; la2[0][2]=1; la2[0][3]=-ltx*i_vertex[0].y; la2[0][4]=-lty*i_vertex[0].y;
\r
70 la2[1][0]=rbx; la2[1][1]=lty; la2[1][2]=1; la2[1][3]=-rbx*i_vertex[1].y; la2[1][4]=-lty*i_vertex[1].y;
\r
71 la2[2][0]=rbx; la2[2][1]=rby; la2[2][2]=1; la2[2][3]=-rbx*i_vertex[2].y; la2[2][4]=-rby*i_vertex[2].y;
\r
72 la2[3][0]=ltx; la2[3][1]=rby; la2[3][2]=1; la2[3][3]=-ltx*i_vertex[3].y; la2[3][4]=-rby*i_vertex[3].y;
\r
73 ra2[0]=i_vertex[0].y;ra2[1]=i_vertex[1].y;ra2[2]=i_vertex[2].y;ra2[3]=i_vertex[3].y;
\r
74 NyARSystemOfLinearEquationsProcessor.doGaussianElimination(la2,ra2,5,4);
\r
76 double A,B,C,D,E,F,G,H;
\r
77 H=(ra2[3]-ra1[3])/(la2[3][4]-la1[3][4]);
\r
78 G=ra2[3]-la2[3][4]*H;
\r
80 F=ra2[2]-H*la2[2][4]-G*la2[2][3];
\r
81 E=ra2[1]-H*la2[1][4]-G*la2[1][3]-F*la2[1][2];
\r
82 D=ra2[0]-H*la2[0][4]-G*la2[0][3]-F*la2[0][2]-E*la2[0][1];
\r
83 C=ra1[2]-H*la1[2][4]-G*la1[2][3];
\r
84 B=ra1[1]-H*la1[1][4]-G*la1[1][3]-C*la1[1][2];
\r
85 A=ra1[0]-H*la1[0][4]-G*la1[0][3]-C*la1[0][2]-B*la1[0][1];
\r