root/as3/FLARToolKit/trunk/src/org/libspark/flartoolkit/core/squaredetect/FLARSquare.as

リビジョン 4718, 3.2 kB (コミッタ: rokubou, コミット時期: 3 日 前)

FLARToolKit v4 core

Line 
1 /*
2  * PROJECT: FLARToolKit
3  * --------------------------------------------------------------------------------
4  * This work is based on the FLARToolKit developed by
5  *   R.Iizuka (nyatla)
6  * http://nyatla.jp/nyatoolkit/
7  *
8  * The FLARToolKit is ActionScript 3.0 version ARToolkit class library.
9  * Copyright (C)2008 Saqoosha
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  *
24  * For further information please contact.
25  *      http://www.libspark.org/wiki/saqoosha/FLARToolKit
26  *      <saq(at)saqoosha.net>
27  *
28  */
29 package org.libspark.flartoolkit.core.squaredetect
30 {
31         import org.libspark.flartoolkit.core.types.*;
32         /**
33          * ARMarkerInfoに相当するクラス。 矩形情報を保持します。
34          *
35          */
36         public class FLARSquare
37         {
38                 public var line:Vector.<FLARLinear> = FLARLinear.createArray(4);
39                 public var sqvertex:Vector.<FLARDoublePoint2d>= FLARDoublePoint2d.createArray(4);
40                 /**
41                  * 中心点を計算します。
42                  * @param o_out
43                  * 結果を格納するバッファ。
44                  */
45                 public function getCenter2d(o_out:FLARDoublePoint2d):void
46                 {
47                         o_out.x=(this.sqvertex[0].x+this.sqvertex[1].x+this.sqvertex[2].x+this.sqvertex[3].x)/4;
48                         o_out.y=(this.sqvertex[0].y+this.sqvertex[1].y+this.sqvertex[2].y+this.sqvertex[3].y)/4;
49                         return;
50                 }
51                 public function checkVertexShiftValue( i_square:FLARSquare ):int
52                 {
53                         var a:Vector.<FLARDoublePoint2d> = this.sqvertex ;
54                         var b:Vector.<FLARDoublePoint2d> = i_square.sqvertex ;
55                         var min_dist:int = int.MAX_VALUE ;
56                         var min_index:int = 0 ;
57                         var xd:int , yd:int ;
58                         for( var i:int = 3 ; i >= 0 ; i-- ) {
59                                 var d:int = 0 ;
60                                 for( var i2:int = 3 ; i2 >= 0 ; i2-- ) {
61                                         xd = int(( a[i2].x - b[( i2 + i ) % 4].x )) ;
62                                         yd = int(( a[i2].y - b[( i2 + i ) % 4].y )) ;
63                                         d += xd * xd + yd * yd ;
64                                 }
65                                 if( min_dist > d ) {
66                                         min_dist = d ;
67                                         min_index = i ;
68                                 }
69                                
70                         }
71                         return min_index ;
72                 }
73                
74                 private static const _gcd_table4:Vector.<int>=Vector.<int>([ -1 , 1 , 2 , 1 ]);
75                 public function rotateVertexL( i_shift:int ):void
76                 {
77                         //assert( ! (( i_shift < 4 ) ) );
78                         var vertext:FLARDoublePoint2d ;
79                         var linet:FLARLinear ;
80                         if( i_shift == 0 ) {
81                                 return  ;
82                         }
83                        
84                         var t1:int , t2:int ;
85                         var d:int , i:int , j:int , mk:int ;
86                         var ll:int = 4 - i_shift ;
87                         d = _gcd_table4[ll] ;
88                         mk = ( 4 - ll ) % 4 ;
89                         for( i = 0 ; i < d ; i++ ) {
90                                 linet = this.line[i] ;
91                                 vertext = this.sqvertex[i] ;
92                                 for( j = 1 ; j < 4 / d ; j++ ) {
93                                         t1 = ( i + ( j - 1 ) * mk ) % 4 ;
94                                         t2 = ( i + j * mk ) % 4 ;
95                                         this.line[t1] = this.line[t2] ;
96                                         this.sqvertex[t1] = this.sqvertex[t2] ;
97                                 }
98                                 t1 = ( i + ll ) % 4 ;
99                                 this.line[t1] = linet ;
100                                 this.sqvertex[t1] = vertext ;
101                         }
102                 }
103         }
104 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。