/ *   
 
   *   P R O J E C T :   N y A R T o o l k i t C S ( E x t e n s i o n ) 
 
   *   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
   *   T h e   N y A R T o o l k i t C S   i s   J a v a   e d i t i o n   A R T o o l K i t   c l a s s   l i b r a r y . 
 
   *   C o p y r i g h t   ( C ) 2 0 0 8 - 2 0 0 9   R y o   I i z u k a 
 
   * 
 
   *   T h i s   p r o g r a m   i s   f r e e   s o f t w a r e :   y o u   c a n   r e d i s t r i b u t e   i t   a n d / o r   m o d i f y 
 
   *   i t   u n d e r   t h e   t e r m s   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e   a s   p u b l i s h e d   b y 
 
   *   t h e   F r e e   S o f t w a r e   F o u n d a t i o n ,   e i t h e r   v e r s i o n   3   o f   t h e   L i c e n s e ,   o r 
 
   *   ( a t   y o u r   o p t i o n )   a n y   l a t e r   v e r s i o n . 
 
   *   
 
   *   T h i s   p r o g r a m   i s   d i s t r i b u t e d   i n   t h e   h o p e   t h a t   i t   w i l l   b e   u s e f u l , 
 
   *   b u t   W I T H O U T   A N Y   W A R R A N T Y ;   w i t h o u t   e v e n   t h e   i m p l i e d   w a r r a n t y   o f 
 
   *   M E R C H A N T A B I L I T Y   o r   F I T N E S S   F O R   A   P A R T I C U L A R   P U R P O S E .     S e e   t h e 
 
   *   G N U   G e n e r a l   P u b l i c   L i c e n s e   f o r   m o r e   d e t a i l s . 
 
   * 
 
   *   Y o u   s h o u l d   h a v e   r e c e i v e d   a   c o p y   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e 
 
   *   a l o n g   w i t h   t h i s   p r o g r a m .     I f   n o t ,   s e e   < h t t p : / / w w w . g n u . o r g / l i c e n s e s / > . 
 
   *   
 
   *   F o r   f u r t h e r   i n f o r m a t i o n   p l e a s e   c o n t a c t . 
 
   * 	 h t t p : / / n y a t l a . j p / n y a t o o l k i t / 
 
   * 	 < a i r m a i l ( a t ) e b o n y . p l a l a . o r . j p >   o r   < n y a t l a ( a t ) n y a t l a . j p > 
 
   *   
 
   * / 
 
 u s i n g   S y s t e m ; 
 
 n a m e s p a c e   j p . n y a t l a . n y a r t o o l k i t . c s . c o r e 
 
 { 
 
 
 
 
 
 
 
 
 
 
 
 
 
         / * * 
 
           *   S0n0000o00Sh00S000Oc0_0o{pe0[W0~0Y00
 
           *   000n0000k0o00SLR0]0n0LRL0B00~0Y00
 
           *   cOY00_jo00S0Oc0_0o{g0Y00
 
           * / 
 
         p u b l i c   c l a s s   N y A R F r u s t u m 
 
         { 
 
                 / * *   f r u s t u m LR* / 
 
                 p r o t e c t e d   N y A R D o u b l e M a t r i x 4 4   _ f r u s t u m _ r h   =   n e w   N y A R D o u b l e M a t r i x 4 4 ( ) ; 
 
                 / * *   f r u s t u m LR* / 
 
                 p r o t e c t e d   N y A R D o u b l e M a t r i x 4 4   _ i n v _ f r u s t u m _ r h   =   n e w   N y A R D o u b l e M a t r i x 4 4 ( ) ; 
 
                 / * *   dP;ubn0000* / 
 
                 p r o t e c t e d   N y A R I n t S i z e   _ s c r e e n _ s i z e   =   n e w   N y A R I n t S i z e ( ) ; 
 
                 / * * 
 
                   *   0000000g0Y00
 
                   *   *gRgSn00000000\ObW0~0Y00
 
                   * / 
 
                 p u b l i c   N y A R F r u s t u m ( ) 
 
                 { 
 
                 } 
 
                 / * * 
 
                   *   0000000g0Y00
 
                   *   A R T o o l k i t n0\q_	YcLRK0000000000\O0~0Y00
 
                   *   @ p a r a m   i _ p e r s p e c t i v e _ m a t 
 
                   *   @ p a r a m   i _ w i d t h 
 
                   *   00000000g0Y00
 
                   *   @ p a r a m   i _ h e i g h t 
 
                   *   00000000g0Y00
 
                   *   @ p a r a m   i _ n e a r 
 
                   *   яs^b~0g0n0ݍg0Y00XSMOo0m m 
 
                   *   @ p a r a m   i _ f a r 
 
                   *   `s^b~0g0n0ݍg0Y00XSMOo0m m 
 
                   * / 
 
                 p u b l i c   N y A R F r u s t u m ( N y A R P e r s p e c t i v e P r o j e c t i o n M a t r i x   i _ p e r s p e c t i v e _ m a t ,   i n t   i _ w i d t h ,   i n t   i _ h e i g h t ,   d o u b l e   i _ n e a r ,   d o u b l e   i _ f a r ) 
 
                 { 
 
                         t h i s . s e t V a l u e ( i _ p e r s p e c t i v e _ m a t ,   i _ w i d t h ,   i _ h e i g h t ,   i _ n e a r ,   i _ f a r ) ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00SLR0000000k0000W0~0Y00
 
                   *   @ p a r a m   i _ p r o j e c t i o n 
 
                   *   A R T o o l K i t 0000n0\q_	YcLR
 
                   *   @ p a r a m   i _ w i d t h 
 
                   *   00000000g0Y00
 
                   *   @ p a r a m   i _ h e i g h t 
 
                   *   00000000g0Y00
 
                   * / 
 
                 p u b l i c   v o i d   s e t V a l u e ( N y A R D o u b l e M a t r i x 4 4   i _ p r o j e c t i o n _ m a t ,   i n t   i _ w i d t h ,   i n t   i _ h e i g h t ) 
 
                 { 
 
                         t h i s . _ f r u s t u m _ r h . s e t V a l u e ( i _ p r o j e c t i o n _ m a t ) ; 
 
                         t h i s . _ i n v _ f r u s t u m _ r h . i n v e r s e ( t h i s . _ f r u s t u m _ r h ) ; 
 
                         t h i s . _ s c r e e n _ s i z e . s e t V a l u e ( i _ w i d t h ,   i _ h e i g h t ) ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00A R T o o l K i t 0000n0\q_	YcLRK00S0\ObW0f0000W0~0Y00
 
                   *   @ p a r a m   i _ a r t k _ p e r s p e c t i v e _ m a t 
 
                   *   A R T o o l K i t 0000n0\q_	YcLR
 
                   *   @ p a r a m   i _ w i d t h 
 
                   *   00000000g0Y00
 
                   *   @ p a r a m   i _ h e i g h t 
 
                   *   00000000g0Y00
 
                   *   @ p a r a m   i _ n e a r 
 
                   *   n e a r 00000m m XSMOg0c[W0~0Y00
 
                   *   @ p a r a m   i _ f a r 
 
                   *   f a r 00000m m XSMOg0c[W0~0Y00
 
                   * / 
 
                 p u b l i c   v o i d   s e t V a l u e ( N y A R P e r s p e c t i v e P r o j e c t i o n M a t r i x   i _ a r t k _ p e r s p e c t i v e _ m a t ,   i n t   i _ w i d t h ,   i n t   i _ h e i g h t ,   d o u b l e   i _ n e a r ,   d o u b l e   i _ f a r ) 
 
                 { 
 
                         i _ a r t k _ p e r s p e c t i v e _ m a t . m a k e C a m e r a F r u s t u m R H ( i _ w i d t h ,   i _ h e i g h t ,   i _ n e a r ,   i _ f a r ,   t h i s . _ f r u s t u m _ r h ) ; 
 
                         t h i s . _ i n v _ f r u s t u m _ r h . i n v e r s e ( t h i s . _ f r u s t u m _ r h ) ; 
 
                         t h i s . _ s c r e e n _ s i z e . s e t V a l u e ( i _ w i d t h ,   i _ h e i g h t ) ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo0000000^j0dPp^jk0	YcW0~0Y00
 
                   *   dPpn0^j|o00000^j|k0j00~0Y00
 
                   *   < p > lQ_  -   
 
                   *   S0n0peo00g l u U n p r o j e c t n0000000h0000000LR0V[W0_00n0g0Y00
 
                   *   lQ_o00NNn0irO(uW0~0W0_00
 
                   *   h t t p : / / w w w . o p e n g l . o r g / s d k / d o c s / m a n / x h t m l / g l u U n P r o j e c t . x m l 
 
                   *   A R T o o l K i t n0^j|k0T[0f0{Y00_000O p e n G L n0u n P r o j e c t h0o0i x , i y n0NH0eL0UD0~0Y00;ub
Nn0^j0]0n0~0~0NH0f0O0`0U0D00
 
                   *   < / p > 
 
                   *   @ p a r a m   i x 
 
                   *   00000
Nn0^j
 
                   *   @ p a r a m   i y 
 
                   *   ;uP
Nn0^j
 
                   *   @ p a r a m   o _ p o i n t _ o n _ s c r e e n 
 
                   *   dPp^j
 
                   * / 
 
                 p u b l i c   v o i d   u n P r o j e c t ( d o u b l e   i x ,   d o u b l e   i y ,   N y A R D o u b l e P o i n t 3 d   o _ p o i n t _ o n _ s c r e e n ) 
 
                 { 
 
                         d o u b l e   n   =   ( t h i s . _ f r u s t u m _ r h . m 2 3   /   ( t h i s . _ f r u s t u m _ r h . m 2 2   -   1 ) ) ; 
 
                         N y A R D o u b l e M a t r i x 4 4   m 4 4   =   t h i s . _ i n v _ f r u s t u m _ r h ; 
 
                         d o u b l e   v 1   =   ( t h i s . _ s c r e e n _ s i z e . w   -   i x   -   1 )   *   2   /   t h i s . _ s c r e e n _ s i z e . w   -   1 . 0 ; / / A R T o o l K i t n0F r u s t r a m k0T[0f000
 
                         d o u b l e   v 2   =   ( t h i s . _ s c r e e n _ s i z e . h   -   i y   -   1 )   *   2   /   t h i s . _ s c r e e n _ s i z e . h   -   1 . 0 ; 
 
                         d o u b l e   v 3   =   2   *   n   -   1 . 0 ; 
 
                         d o u b l e   b   =   1   /   ( m 4 4 . m 3 0   *   v 1   +   m 4 4 . m 3 1   *   v 2   +   m 4 4 . m 3 2   *   v 3   +   m 4 4 . m 3 3 ) ; 
 
                         o _ p o i n t _ o n _ s c r e e n . x   =   ( m 4 4 . m 0 0   *   v 1   +   m 4 4 . m 0 1   *   v 2   +   m 4 4 . m 0 2   *   v 3   +   m 4 4 . m 0 3 )   *   b ; 
 
                         o _ p o i n t _ o n _ s c r e e n . y   =   ( m 4 4 . m 1 0   *   v 1   +   m 4 4 . m 1 1   *   v 2   +   m 4 4 . m 1 2   *   v 3   +   m 4 4 . m 1 3 )   *   b ; 
 
                         o _ p o i n t _ o n _ s c r e e n . z   =   ( m 4 4 . m 2 0   *   v 1   +   m 4 4 . m 2 1   *   v 2   +   m 4 4 . m 2 2   *   v 3   +   m 4 4 . m 2 3 )   *   b ; 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo0000000
Nn0ph0Sp0P}v0v}h00NaYRn0s^bn0N]p00000n0^j|g0S_W0~0Y00
 
                   *   S0n0^jo00000^j|g0Y00
 
                   *   @ p a r a m   i x 
 
                   *   00000
Nn0^j
 
                   *   @ p a r a m   i y 
 
                   *   00000
Nn0^j
 
                   *   @ p a r a m   i _ m a t 
 
                   *   s^bn0YRLRg0Y00
 
                   *   @ p a r a m   o _ p o s 
 
                   *   P}g0SQ0S0000000g0Y00
 
                   * / 
 
                 p u b l i c   v o i d   u n P r o j e c t O n C a m e r a ( d o u b l e   i x ,   d o u b l e   i y ,   N y A R D o u b l e M a t r i x 4 4   i _ m a t ,   N y A R D o u b l e P o i n t 3 d   o _ p o s ) 
 
                 { 
 
                         / / ;ub!dPp
 
                         t h i s . u n P r o j e c t ( i x ,   i y ,   o _ p o s ) ; 
 
                         / / dPp!000^j|
 
                         d o u b l e   n x   =   i _ m a t . m 0 2 ; 
 
                         d o u b l e   n y   =   i _ m a t . m 1 2 ; 
 
                         d o u b l e   n z   =   i _ m a t . m 2 2 ; 
 
                         d o u b l e   m x   =   i _ m a t . m 0 3 ; 
 
                         d o u b l e   m y   =   i _ m a t . m 1 3 ; 
 
                         d o u b l e   m z   =   i _ m a t . m 2 3 ; 
 
                         d o u b l e   t   =   ( n x   *   m x   +   n y   *   m y   +   n z   *   m z )   /   ( n x   *   o _ p o s . x   +   n y   *   o _ p o s . y   +   n z   *   o _ p o s . z ) ; 
 
                         o _ p o s . x   =   t   *   o _ p o s . x ; 
 
                         o _ p o s . y   =   t   *   o _ p o s . y ; 
 
                         o _ p o s . z   =   t   *   o _ p o s . z ; 
 
                 } 
 
                 / * * 
 
                   *   ;ub
Nn0ph0Sp0P}v0v}h0NaYRn0s^bn0N]p00s^bn0^j|g0S_W0~0Y00
 
                   *   A R T o o l K i t n0,gP 1 7 5 hTn0[ňh0TX0g0Y00
 
                   *   < p > 
 
                   *   S0n0A P I o0p~0ԏW0O(uk0o0 giSU00f0D0~0[000T Nj0i _ m a t k0p~0ԏW00000Y00h0M0o00U\W0f0O0`0U0D00
 
                   *   < / p > 
 
                   *   @ p a r a m   i x 
 
                   *   00000
Nn0^j
 
                   *   @ p a r a m   i y 
 
                   *   00000
Nn0^j
 
                   *   @ p a r a m   i _ m a t 
 
                   *   s^bn0YRLRg0Y00
 
                   *   @ p a r a m   o _ p o s 
 
                   *   P}g0SQ0S0000000g0Y00
 
                   *   @ r e t u r n 
 
                   *   {k0bRY00h00t r u e 0ԏW0~0Y00
 
                   * / 
 
                 p u b l i c   b o o l   u n P r o j e c t O n M a t r i x ( d o u b l e   i x ,   d o u b l e   i y ,   N y A R D o u b l e M a t r i x 4 4   i _ m a t ,   N y A R D o u b l e P o i n t 3 d   o _ p o s ) 
 
                 { 
 
                         / / Np0000^j|g0{
 
                         u n P r o j e c t O n C a m e r a ( i x ,   i y ,   i _ m a t ,   o _ p o s ) ; 
 
                         / / ^j|n0	Yc
 
                         N y A R D o u b l e M a t r i x 4 4   m   =   n e w   N y A R D o u b l e M a t r i x 4 4 ( ) ; 
 
                         i f   ( ! m . i n v e r s e ( i _ m a t ) ) 
 
                         { 
 
                                 r e t u r n   f a l s e ; 
 
                         } 
 
                         m . t r a n s f o r m 3 d ( o _ p o s ,   o _ p o s ) ; 
 
                         r e t u r n   t r u e ; 
 
                 } 
 
                 / * * 
 
                   *   000^j|n0p0000000^jn0px0	YcW0~0Y00
 
                   *   @ p a r a m   i _ x 
 
                   *   000^j|n0p
 
                   *   @ p a r a m   i _ y 
 
                   *   000^j|n0p
 
                   *   @ p a r a m   i _ z 
 
                   *   000^j|n0p
 
                   *   @ p a r a m   o _ p o s 2 d 
 
                   *   P}g0SQ0S0000000g0Y00
 
                   * / 
 
                 p u b l i c   v o i d   p r o j e c t ( d o u b l e   i _ x ,   d o u b l e   i _ y ,   d o u b l e   i _ z ,   N y A R D o u b l e P o i n t 2 d   o _ p o s 2 d ) 
 
                 { 
 
                         N y A R D o u b l e M a t r i x 4 4   m   =   t h i s . _ f r u s t u m _ r h ; 
 
                         d o u b l e   v 3 _ 1   =   1   /   i _ z   *   m . m 3 2 ; 
 
                         d o u b l e   w   =   t h i s . _ s c r e e n _ s i z e . w ; 
 
                         d o u b l e   h   =   t h i s . _ s c r e e n _ s i z e . h ; 
 
                         o _ p o s 2 d . x   =   w   -   ( 1   +   ( i _ x   *   m . m 0 0   +   i _ z   *   m . m 0 2 )   *   v 3 _ 1 )   *   w   /   2 ; 
 
                         o _ p o s 2 d . y   =   h   -   ( 1   +   ( i _ y   *   m . m 1 1   +   i _ z   *   m . m 1 2 )   *   v 3 _ 1 )   *   h   /   2 ; 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   000^j|n0p0000000^jn0px0	YcW0~0Y00
 
                   *   @ p a r a m   i _ p o s 
 
                   *   000^j|n0p
 
                   *   @ p a r a m   o _ p o s 2 d 
 
                   *   P}g0SQ0S0000000g0Y00
 
                   * / 
 
                 p u b l i c   v o i d   p r o j e c t ( N y A R D o u b l e P o i n t 3 d   i _ p o s ,   N y A R D o u b l e P o i n t 2 d   o _ p o s 2 d ) 
 
                 { 
 
                         t h i s . p r o j e c t ( i _ p o s . x ,   i _ p o s . y ,   i _ p o s . z ,   o _ p o s 2 d ) ; 
 
                 } 
 
 
 
                 / * * 
 
                   *   	YcLRn0Sgq$P0ԏW0~0Y00
 
                   *   S0n0$Po0QW0\(ug0Y00	YfW0j0D0g0O0`0U0D00
 
                   *   @ r e t u r n 
 
                   *   [ r e a d   o n l y ] 	YcLR0<h
}W0_0000000
 
                   * / 
 
                 p u b l i c   N y A R D o u b l e M a t r i x 4 4   g e t M a t r i x ( ) 
 
                 { 
 
                         r e t u r n   t h i s . _ f r u s t u m _ r h ; 
 
                 } 
 
                 / * * 
 
                   *   	YcLRn0LR0ԏW0~0Y00
 
                   *   S0n0$Po0QW0\(ug0Y00	YfW0j0D0g0O0`0U0D00
 
                   *   @ r e t u r n 
 
                   *   [ r e a d   o n l y ] 	YcLRn0LR0<h
}W0_0000000
 
                   * / 
 
                 p u b l i c   N y A R D o u b l e M a t r i x 4 4   g e t I n v M a t r i x ( ) 
 
                 { 
 
                         r e t u r n   t h i s . _ i n v _ f r u s t u m _ r h ; 
 
                 } 
 
                 / * * 
 
                   *   	Yc000000LRK00_CQW0~0Y00
 
                   *   @ p a r a m   o _ v a l u e 
 
                   *   @ r e t u r n 
 
                   *   $P0000W0_0o _ v a l u e 0ԏW0~0Y00
 
                   * / 
 
                 p u b l i c   F r u s t u m P a r a m   g e t F r u s t u m P a r a m ( F r u s t u m P a r a m   o _ v a l u e ) 
 
                 { 
 
                         d o u b l e   n e a r ; 
 
                         N y A R D o u b l e M a t r i x 4 4   m a t   =   t h i s . _ f r u s t u m _ r h ; 
 
                         o _ v a l u e . f a r   =   m a t . m 2 3   /   ( m a t . m 2 2   +   1 ) ; 
 
                         o _ v a l u e . n e a r   =   n e a r   =   m a t . m 2 3   /   ( m a t . m 2 2   -   1 ) ; 
 
                         o _ v a l u e . l e f t   =   ( m a t . m 0 2   -   1 )   *   n e a r   /   m a t . m 0 0 ; 
 
                         o _ v a l u e . r i g h t   =   ( m a t . m 0 2   +   1 )   *   n e a r   /   m a t . m 0 0 ; 
 
                         o _ v a l u e . b o t t o m   =   ( m a t . m 1 2   -   1 )   *   n e a r   /   m a t . m 1 1 ; 
 
                         o _ v a l u e . t o p   =   ( m a t . m 1 2   +   1 )   *   n e a r   /   m a t . m 1 1 ; 
 
                         r e t u r n   o _ v a l u e ; 
 
                 } 
 
                 p u b l i c   c l a s s   F r u s t u m P a r a m 
 
                 { 
 
                         p u b l i c   d o u b l e   f a r ; 
 
                         p u b l i c   d o u b l e   n e a r ; 
 
                         p u b l i c   d o u b l e   l e f t ; 
 
                         p u b l i c   d o u b l e   r i g h t ; 
 
                         p u b l i c   d o u b l e   b o t t o m ; 
 
                         p u b l i c   d o u b l e   t o p ; 
 
                 } 
 
                 p u b l i c   P e r s p e c t i v e P a r a m   g e t P e r s p e c t i v e P a r a m ( P e r s p e c t i v e P a r a m   o _ v a l u e ) 
 
                 { 
 
                         N y A R D o u b l e M a t r i x 4 4   m a t   =   t h i s . _ f r u s t u m _ r h ; 
 
                         o _ v a l u e . f a r   =   m a t . m 2 3   /   ( m a t . m 2 2   +   1 ) ; 
 
                         o _ v a l u e . n e a r   =   m a t . m 2 3   /   ( m a t . m 2 2   -   1 ) ; 
 
                         o _ v a l u e . a s p e c t   =   m a t . m 1 1   /   m a t . m 0 0 ; 
 
                         o _ v a l u e . f o v y   =   2   *   M a t h . A t a n ( 1   /   ( m a t . m 0 0   *   o _ v a l u e . a s p e c t ) ) ; 
 
                         r e t u r n   o _ v a l u e ; 
 
                 } 
 
                 p u b l i c   c l a s s   P e r s p e c t i v e P a r a m 
 
                 { 
 
                         p u b l i c   d o u b l e   f a r ; 
 
                         p u b l i c   d o u b l e   n e a r ; 
 
                         p u b l i c   d o u b l e   a s p e c t ; 
 
                         p u b l i c   d o u b l e   f o v y ; 
 
                 } 
 
         } 
 
 } 