text
stringlengths
30
1.67M
<s> package net . java . joglutils . msg . math ; public class MathUtil { public static boolean makePerpendicular ( Vec3f src , Vec3f dest ) { if ( ( src . x ( ) == <NUM_LIT:0.0f> ) && ( src . y ( ) == <NUM_LIT:0.0f> ) && ( src . z ( ) == <NUM_LIT:0.0f> ) ) { return false ; } if ( src . x ( ) != <NUM_LIT:0.0f> ) { if ( src . y ( ) != <NUM_LIT:0.0f> ) { dest . set ( - src . y ( ) , src . x ( ) , <NUM_LIT:0.0f> ) ; } else { dest . set ( - src . z ( ) , <NUM_LIT:0.0f> , src . x ( ) ) ; } } else { dest . set ( <NUM_LIT:1.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> ) ; } return true ; } public static int sgn ( float f ) { if ( f > <NUM_LIT:0> ) { return <NUM_LIT:1> ; } else if ( f < <NUM_LIT:0> ) { return - <NUM_LIT:1> ; } return <NUM_LIT:0> ; } public static float clamp ( float val , float min , float max ) { if ( val < min ) return min ; if ( val > max ) return max ; return val ; } public static int clamp ( int val , int min , int max ) { if ( val < min ) return min ; if ( val > max ) return max ; return val ; } } </s>
<s> package net . java . joglutils . msg . math ; public class PlaneUV { private Vec3f origin = new Vec3f ( ) ; private Vec3f normal = new Vec3f ( ) ; private Vec3f uAxis = new Vec3f ( ) ; private Vec3f vAxis = new Vec3f ( ) ; public PlaneUV ( ) { setEverything ( new Vec3f ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) , new Vec3f ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , new Vec3f ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) , new Vec3f ( <NUM_LIT:0> , <NUM_LIT:0> , - <NUM_LIT:1> ) ) ; } public PlaneUV ( Vec3f normal , Vec3f origin ) { setOrigin ( origin ) ; setNormal ( normal ) ; } public PlaneUV ( Vec3f normal , Vec3f origin , Vec3f uAxis ) { setOrigin ( origin ) ; setNormalAndU ( normal , uAxis ) ; } public PlaneUV ( Vec3f normal , Vec3f origin , Vec3f uAxis , Vec3f vAxis ) { setEverything ( normal , origin , uAxis , vAxis ) ; } public void setOrigin ( Vec3f origin ) { this . origin . set ( origin ) ; } public Vec3f getOrigin ( ) { return new Vec3f ( origin ) ; } public void setNormalAndUV ( Vec3f normal , Vec3f uAxis , Vec3f vAxis ) { setEverything ( normal , origin , uAxis , vAxis ) ; } public void setNormal ( Vec3f normal ) { Vec3f uAxis = new Vec3f ( ) ; MathUtil . makePerpendicular ( normal , uAxis ) ; Vec3f vAxis = normal . cross ( uAxis ) ; setEverything ( normal , origin , uAxis , vAxis ) ; } public void setNormalAndU ( Vec3f normal , Vec3f uAxis ) { Vec3f vAxis = normal . cross ( uAxis ) ; setEverything ( normal , origin , uAxis , vAxis ) ; } public Vec3f getNormal ( ) { return normal ; } public Vec3f getUAxis ( ) { return uAxis ; } public Vec3f getVAxis ( ) { return vAxis ; } public void projectPoint ( Vec3f point , Vec3f projPt , Vec2f uvCoords ) { projPt . sub ( point , origin ) ; float dotp = normal . dot ( projPt ) ; Vec3f tmpDir = new Vec3f ( ) ; tmpDir . set ( normal ) ; tmpDir . scale ( dotp ) ; projPt . sub ( projPt , tmpDir ) ; uvCoords . set ( projPt . dot ( uAxis ) , projPt . dot ( vAxis ) ) ; projPt . add ( origin ) ; } public boolean intersectRay ( Vec3f rayStart , Vec3f rayDirection , IntersectionPoint intPt , Vec2f uvCoords ) { float denom = rayDirection . dot ( normal ) ; if ( denom == <NUM_LIT:0.0f> ) return false ; Vec3f tmpDir = new Vec3f ( ) ; tmpDir . sub ( origin , rayStart ) ; float t = tmpDir . dot ( normal ) / denom ; Vec3f tmpPt = new Vec3f ( ) ; tmpPt . set ( rayDirection ) ; tmpPt . scale ( t ) ; tmpPt . add ( rayStart ) ; intPt . setIntersectionPoint ( tmpPt ) ; intPt . setT ( t ) ; tmpDir . sub ( intPt . getIntersectionPoint ( ) , origin ) ; uvCoords . set ( tmpDir . dot ( uAxis ) , tmpDir . dot ( vAxis ) ) ; return true ; } private void setEverything ( Vec3f normal , Vec3f origin , Vec3f uAxis , Vec3f vAxis ) { this . normal . set ( normal ) ; this . origin . set ( origin ) ; this . uAxis . set ( uAxis ) ; this . vAxis . set ( vAxis ) ; this . normal . normalize ( ) ; this . uAxis . normalize ( ) ; this . vAxis . normalize ( ) ; } } </s>
<s> package net . java . joglutils . msg . math ; public class Vec2f { private float x ; private float y ; public Vec2f ( ) { } public Vec2f ( Vec2f arg ) { this ( arg . x , arg . y ) ; } public Vec2f ( float x , float y ) { set ( x , y ) ; } public Vec2f copy ( ) { return new Vec2f ( this ) ; } public void set ( Vec2f arg ) { set ( arg . x , arg . y ) ; } public void set ( float x , float y ) { this . x = x ; this . y = y ; } public void set ( int i , float val ) { switch ( i ) { case <NUM_LIT:0> : x = val ; break ; case <NUM_LIT:1> : y = val ; break ; default : throw new IndexOutOfBoundsException ( ) ; } } public float get ( int i ) { switch ( i ) { case <NUM_LIT:0> : return x ; case <NUM_LIT:1> : return y ; default : throw new IndexOutOfBoundsException ( ) ; } } public float x ( ) { return x ; } public float y ( ) { return y ; } public void setX ( float x ) { this . x = x ; } public void setY ( float y ) { this . y = y ; } public float dot ( Vec2f arg ) { return x * arg . x + y * arg . y ; } public float length ( ) { return ( float ) Math . sqrt ( lengthSquared ( ) ) ; } public float lengthSquared ( ) { return this . dot ( this ) ; } public void normalize ( ) { float len = length ( ) ; if ( len == <NUM_LIT:0.0f> ) return ; scale ( <NUM_LIT:1.0f> / len ) ; } public Vec2f times ( float val ) { Vec2f tmp = new Vec2f ( this ) ; tmp . scale ( val ) ; return tmp ; } public void scale ( float val ) { x *= val ; y *= val ; } public Vec2f plus ( Vec2f arg ) { Vec2f tmp = new Vec2f ( ) ; tmp . add ( this , arg ) ; return tmp ; } public void add ( Vec2f b ) { add ( this , b ) ; } public void add ( Vec2f a , Vec2f b ) { x = a . x + b . x ; y = a . y + b . y ; } public Vec2f addScaled ( float s , Vec2f arg ) { Vec2f tmp = new Vec2f ( ) ; tmp . addScaled ( this , s , arg ) ; return tmp ; } public void addScaled ( Vec2f a , float s , Vec2f b ) { x = a . x + s * b . x ; y = a . y + s * b . y ; } public Vec2f minus ( Vec2f arg ) { Vec2f tmp = new Vec2f ( ) ; tmp . sub ( this , arg ) ; return tmp ; } public void sub ( Vec2f b ) { sub ( this , b ) ; } public void sub ( Vec2f a , Vec2f b ) { x = a . x - b . x ; y = a . y - b . y ; } public Vecf toVecf ( ) { Vecf out = new Vecf ( <NUM_LIT:2> ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:2> ; i ++ ) { out . set ( i , get ( i ) ) ; } return out ; } public String toString ( ) { return "<STR_LIT:(>" + x + "<STR_LIT:U+002CU+0020>" + y + "<STR_LIT:)>" ; } } </s>
<s> package net . java . joglutils . msg . math ; public class DimensionMismatchException extends RuntimeException { public DimensionMismatchException ( ) { super ( ) ; } public DimensionMismatchException ( String msg ) { super ( msg ) ; } } </s>
<s> package net . java . joglutils . msg . math ; public class Vec3f { public static final Vec3f X_AXIS = new Vec3f ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ; public static final Vec3f Y_AXIS = new Vec3f ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) ; public static final Vec3f Z_AXIS = new Vec3f ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) ; public static final Vec3f NEG_X_AXIS = new Vec3f ( - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ; public static final Vec3f NEG_Y_AXIS = new Vec3f ( <NUM_LIT:0> , - <NUM_LIT:1> , <NUM_LIT:0> ) ; public static final Vec3f NEG_Z_AXIS = new Vec3f ( <NUM_LIT:0> , <NUM_LIT:0> , - <NUM_LIT:1> ) ; private float x ; private float y ; private float z ; public Vec3f ( ) { } public Vec3f ( Vec3f arg ) { set ( arg ) ; } public Vec3f ( float x , float y , float z ) { set ( x , y , z ) ; } public Vec3f copy ( ) { return new Vec3f ( this ) ; } public Vec3d toDouble ( ) { return new Vec3d ( x , y , z ) ; } public void set ( Vec3f arg ) { set ( arg . x , arg . y , arg . z ) ; } public void set ( float x , float y , float z ) { this . x = x ; this . y = y ; this . z = z ; } public void set ( int i , float val ) { switch ( i ) { case <NUM_LIT:0> : x = val ; break ; case <NUM_LIT:1> : y = val ; break ; case <NUM_LIT:2> : z = val ; break ; default : throw new IndexOutOfBoundsException ( ) ; } } public float get ( int i ) { switch ( i ) { case <NUM_LIT:0> : return x ; case <NUM_LIT:1> : return y ; case <NUM_LIT:2> : return z ; default : throw new IndexOutOfBoundsException ( ) ; } } public float x ( ) { return x ; } public float y ( ) { return y ; } public float z ( ) { return z ; } public void setX ( float x ) { this . x = x ; } public void setY ( float y ) { this . y = y ; } public void setZ ( float z ) { this . z = z ; } public float dot ( Vec3f arg ) { return x * arg . x + y * arg . y + z * arg . z ; } public float length ( ) { return ( float ) Math . sqrt ( lengthSquared ( ) ) ; } public float lengthSquared ( ) { return this . dot ( this ) ; } public void normalize ( ) { float len = length ( ) ; if ( len == <NUM_LIT:0.0f> ) return ; scale ( <NUM_LIT:1.0f> / len ) ; } public Vec3f times ( float val ) { Vec3f tmp = new Vec3f ( this ) ; tmp . scale ( val ) ; return tmp ; } public void scale ( float val ) { x *= val ; y *= val ; z *= val ; } public Vec3f plus ( Vec3f arg ) { Vec3f tmp = new Vec3f ( ) ; tmp . add ( this , arg ) ; return tmp ; } public void add ( Vec3f b ) { add ( this , b ) ; } public void add ( Vec3f a , Vec3f b ) { x = a . x + b . x ; y = a . y + b . y ; z = a . z + b . z ; } public Vec3f addScaled ( float s , Vec3f arg ) { Vec3f tmp = new Vec3f ( ) ; tmp . addScaled ( this , s , arg ) ; return tmp ; } public void addScaled ( Vec3f a , float s , Vec3f b ) { x = a . x + s * b . x ; y = a . y + s * b . y ; z = a . z + s * b . z ; } public Vec3f minus ( Vec3f arg ) { Vec3f tmp = new Vec3f ( ) ; tmp . sub ( this , arg ) ; return tmp ; } public void sub ( Vec3f b ) { sub ( this , b ) ; } public void sub ( Vec3f a , Vec3f b ) { x = a . x - b . x ; y = a . y - b . y ; z = a . z - b . z ; } public Vec3f cross ( Vec3f arg ) { Vec3f tmp = new Vec3f ( ) ; tmp . cross ( this , arg ) ; return tmp ; } public void cross ( Vec3f a , Vec3f b ) { x = a . y * b . z - a . z * b . y ; y = a . z * b . x - a . x * b . z ; z = a . x * b . y - a . y * b . x ; } public void componentMul ( Vec3f arg ) { x *= arg . x ; y *= arg . y ; z *= arg . z ; } public Vecf toVecf ( ) { Vecf out = new Vecf ( <NUM_LIT:3> ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:3> ; i ++ ) { out . set ( i , get ( i ) ) ; } return out ; } public String toString ( ) { return "<STR_LIT:(>" + x + "<STR_LIT:U+002CU+0020>" + y + "<STR_LIT:U+002CU+0020>" + z + "<STR_LIT:)>" ; } } </s>
<s> package net . java . joglutils . msg . math ; public class Matf { private float [ ] data ; private int nCol ; private int nRow ; public Matf ( int nRow , int nCol ) { data = new float [ nRow * nCol ] ; this . nCol = nCol ; this . nRow = nRow ; } public Matf ( Matf arg ) { nRow = arg . nRow ; nCol = arg . nCol ; data = new float [ nRow * nCol ] ; System . arraycopy ( arg . data , <NUM_LIT:0> , data , <NUM_LIT:0> , data . length ) ; } public int nRow ( ) { return nRow ; } public int nCol ( ) { return nCol ; } public float get ( int i , int j ) { return data [ nCol * i + j ] ; } public void set ( int i , int j , float val ) { data [ nCol * i + j ] = val ; } public Matf transpose ( ) { Matf tmp = new Matf ( nCol , nRow ) ; for ( int i = <NUM_LIT:0> ; i < nRow ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < nCol ; j ++ ) { tmp . set ( j , i , get ( i , j ) ) ; } } return tmp ; } public Matf mul ( Matf b ) throws DimensionMismatchException { if ( nCol ( ) != b . nRow ( ) ) throw new DimensionMismatchException ( ) ; Matf tmp = new Matf ( nRow ( ) , b . nCol ( ) ) ; for ( int i = <NUM_LIT:0> ; i < nRow ( ) ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < b . nCol ( ) ; j ++ ) { float val = <NUM_LIT:0> ; for ( int t = <NUM_LIT:0> ; t < nCol ( ) ; t ++ ) { val += get ( i , t ) * b . get ( t , j ) ; } tmp . set ( i , j , val ) ; } } return tmp ; } public Vecf mul ( Vecf v ) throws DimensionMismatchException { if ( nCol ( ) != v . length ( ) ) { throw new DimensionMismatchException ( ) ; } Vecf out = new Vecf ( nRow ( ) ) ; for ( int i = <NUM_LIT:0> ; i < nRow ( ) ; i ++ ) { float tmp = <NUM_LIT:0> ; for ( int j = <NUM_LIT:0> ; j < nCol ( ) ; j ++ ) { tmp += get ( i , j ) * v . get ( j ) ; } out . set ( i , tmp ) ; } return out ; } public Mat2f toMat2f ( ) throws DimensionMismatchException { if ( nRow ( ) != <NUM_LIT:2> || nCol ( ) != <NUM_LIT:2> ) { throw new DimensionMismatchException ( ) ; } Mat2f tmp = new Mat2f ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:2> ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:2> ; j ++ ) { tmp . set ( i , j , get ( i , j ) ) ; } } return tmp ; } public Mat3f toMat3f ( ) throws DimensionMismatchException { if ( nRow ( ) != <NUM_LIT:3> || nCol ( ) != <NUM_LIT:3> ) { throw new DimensionMismatchException ( ) ; } Mat3f tmp = new Mat3f ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:3> ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:3> ; j ++ ) { tmp . set ( i , j , get ( i , j ) ) ; } } return tmp ; } public Mat4f toMat4f ( ) throws DimensionMismatchException { if ( nRow ( ) != <NUM_LIT:4> || nCol ( ) != <NUM_LIT:4> ) { throw new DimensionMismatchException ( ) ; } Mat4f tmp = new Mat4f ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:4> ; j ++ ) { tmp . set ( i , j , get ( i , j ) ) ; } } return tmp ; } } </s>
<s> package net . java . joglutils . msg . math ; import java . nio . * ; public class Mat4f { private float [ ] data ; public Mat4f ( ) { data = new float [ <NUM_LIT:16> ] ; } public Mat4f ( Mat4f arg ) { this ( ) ; set ( arg ) ; } public void makeIdent ( ) { for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:4> ; j ++ ) { if ( i == j ) { set ( i , j , <NUM_LIT:1.0f> ) ; } else { set ( i , j , <NUM_LIT:0.0f> ) ; } } } } public void set ( Mat4f arg ) { float [ ] mine = data ; float [ ] yours = arg . data ; for ( int i = <NUM_LIT:0> ; i < mine . length ; i ++ ) { mine [ i ] = yours [ i ] ; } } public float get ( int i , int j ) { return data [ <NUM_LIT:4> * i + j ] ; } public void set ( int i , int j , float val ) { data [ <NUM_LIT:4> * i + j ] = val ; } public void setTranslation ( Vec3f trans ) { set ( <NUM_LIT:0> , <NUM_LIT:3> , trans . x ( ) ) ; set ( <NUM_LIT:1> , <NUM_LIT:3> , trans . y ( ) ) ; set ( <NUM_LIT:2> , <NUM_LIT:3> , trans . z ( ) ) ; } public void setRotation ( Rotf rot ) { rot . toMatrix ( this ) ; } public void setRotation ( Vec3f x , Vec3f y , Vec3f z ) { set ( <NUM_LIT:0> , <NUM_LIT:0> , x . x ( ) ) ; set ( <NUM_LIT:1> , <NUM_LIT:0> , x . y ( ) ) ; set ( <NUM_LIT:2> , <NUM_LIT:0> , x . z ( ) ) ; set ( <NUM_LIT:0> , <NUM_LIT:1> , y . x ( ) ) ; set ( <NUM_LIT:1> , <NUM_LIT:1> , y . y ( ) ) ; set ( <NUM_LIT:2> , <NUM_LIT:1> , y . z ( ) ) ; set ( <NUM_LIT:0> , <NUM_LIT:2> , z . x ( ) ) ; set ( <NUM_LIT:1> , <NUM_LIT:2> , z . y ( ) ) ; set ( <NUM_LIT:2> , <NUM_LIT:2> , z . z ( ) ) ; } public void getRotation ( Rotf rot ) { rot . fromMatrix ( this ) ; } public void setScale ( Vec3f scale ) { set ( <NUM_LIT:0> , <NUM_LIT:0> , scale . x ( ) ) ; set ( <NUM_LIT:1> , <NUM_LIT:1> , scale . y ( ) ) ; set ( <NUM_LIT:2> , <NUM_LIT:2> , scale . z ( ) ) ; } public void invertRigid ( ) { float t ; t = get ( <NUM_LIT:0> , <NUM_LIT:1> ) ; set ( <NUM_LIT:0> , <NUM_LIT:1> , get ( <NUM_LIT:1> , <NUM_LIT:0> ) ) ; set ( <NUM_LIT:1> , <NUM_LIT:0> , t ) ; t = get ( <NUM_LIT:0> , <NUM_LIT:2> ) ; set ( <NUM_LIT:0> , <NUM_LIT:2> , get ( <NUM_LIT:2> , <NUM_LIT:0> ) ) ; set ( <NUM_LIT:2> , <NUM_LIT:0> , t ) ; t = get ( <NUM_LIT:1> , <NUM_LIT:2> ) ; set ( <NUM_LIT:1> , <NUM_LIT:2> , get ( <NUM_LIT:2> , <NUM_LIT:1> ) ) ; set ( <NUM_LIT:2> , <NUM_LIT:1> , t ) ; Vec3f negTrans = new Vec3f ( - get ( <NUM_LIT:0> , <NUM_LIT:3> ) , - get ( <NUM_LIT:1> , <NUM_LIT:3> ) , - get ( <NUM_LIT:2> , <NUM_LIT:3> ) ) ; Vec3f trans = new Vec3f ( ) ; xformDir ( negTrans , trans ) ; set ( <NUM_LIT:0> , <NUM_LIT:3> , trans . x ( ) ) ; set ( <NUM_LIT:1> , <NUM_LIT:3> , trans . y ( ) ) ; set ( <NUM_LIT:2> , <NUM_LIT:3> , trans . z ( ) ) ; } public void invert ( ) throws SingularMatrixException { invertGeneral ( this ) ; } public Mat4f mul ( Mat4f b ) { Mat4f tmp = new Mat4f ( ) ; tmp . mul ( this , b ) ; return tmp ; } public void mul ( Mat4f a , Mat4f b ) { for ( int rc = <NUM_LIT:0> ; rc < <NUM_LIT:4> ; rc ++ ) for ( int cc = <NUM_LIT:0> ; cc < <NUM_LIT:4> ; cc ++ ) { float tmp = <NUM_LIT:0.0f> ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) tmp += a . get ( rc , i ) * b . get ( i , cc ) ; set ( rc , cc , tmp ) ; } } public void transpose ( ) { float t ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < i ; j ++ ) { t = get ( i , j ) ; set ( i , j , get ( j , i ) ) ; set ( j , i , t ) ; } } } public void xformVec ( Vec4f src , Vec4f dest ) { for ( int rc = <NUM_LIT:0> ; rc < <NUM_LIT:4> ; rc ++ ) { float tmp = <NUM_LIT:0.0f> ; for ( int cc = <NUM_LIT:0> ; cc < <NUM_LIT:4> ; cc ++ ) { tmp += get ( rc , cc ) * src . get ( cc ) ; } dest . set ( rc , tmp ) ; } } public void xformPt ( Vec3f src , Vec3f dest ) { for ( int rc = <NUM_LIT:0> ; rc < <NUM_LIT:3> ; rc ++ ) { float tmp = <NUM_LIT:0.0f> ; for ( int cc = <NUM_LIT:0> ; cc < <NUM_LIT:3> ; cc ++ ) { tmp += get ( rc , cc ) * src . get ( cc ) ; } tmp += get ( rc , <NUM_LIT:3> ) ; dest . set ( rc , tmp ) ; } } public void xformDir ( Vec3f src , Vec3f dest ) { for ( int rc = <NUM_LIT:0> ; rc < <NUM_LIT:3> ; rc ++ ) { float tmp = <NUM_LIT:0.0f> ; for ( int cc = <NUM_LIT:0> ; cc < <NUM_LIT:3> ; cc ++ ) { tmp += get ( rc , cc ) * src . get ( cc ) ; } dest . set ( rc , tmp ) ; } } public Line xformLine ( Line line ) { Vec3f pt = new Vec3f ( ) ; Vec3f dir = new Vec3f ( ) ; xformPt ( line . getPoint ( ) , pt ) ; xformDir ( line . getDirection ( ) , dir ) ; return new Line ( dir , pt ) ; } public void getColumnMajorData ( float [ ] out ) { for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:4> ; j ++ ) { out [ <NUM_LIT:4> * j + i ] = get ( i , j ) ; } } } public void getColumnMajorData ( FloatBuffer out ) { for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:4> ; j ++ ) { out . put ( <NUM_LIT:4> * j + i , get ( i , j ) ) ; } } } public float [ ] getRowMajorData ( ) { return data ; } public void getRowMajorData ( FloatBuffer out ) { for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:16> ; i ++ ) { out . put ( i , data [ i ] ) ; } } public Matf toMatf ( ) { Matf out = new Matf ( <NUM_LIT:4> , <NUM_LIT:4> ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:4> ; j ++ ) { out . set ( i , j , get ( i , j ) ) ; } } return out ; } public String toString ( ) { String endl = System . getProperty ( "<STR_LIT>" ) ; return "<STR_LIT:(>" + get ( <NUM_LIT:0> , <NUM_LIT:0> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:0> , <NUM_LIT:1> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:0> , <NUM_LIT:2> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:0> , <NUM_LIT:3> ) + endl + get ( <NUM_LIT:1> , <NUM_LIT:0> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:1> , <NUM_LIT:1> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:1> , <NUM_LIT:2> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:1> , <NUM_LIT:3> ) + endl + get ( <NUM_LIT:2> , <NUM_LIT:0> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:2> , <NUM_LIT:1> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:2> , <NUM_LIT:2> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:2> , <NUM_LIT:3> ) + endl + get ( <NUM_LIT:3> , <NUM_LIT:0> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:3> , <NUM_LIT:1> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:3> , <NUM_LIT:2> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:3> , <NUM_LIT:3> ) + "<STR_LIT:)>" ; } private void invertGeneral ( Mat4f m1 ) { double temp [ ] = new double [ <NUM_LIT:16> ] ; double result [ ] = new double [ <NUM_LIT:16> ] ; int row_perm [ ] = new int [ <NUM_LIT:4> ] ; int i , r , c ; temp [ <NUM_LIT:0> ] = m1 . get ( <NUM_LIT:0> , <NUM_LIT:0> ) ; temp [ <NUM_LIT:1> ] = m1 . get ( <NUM_LIT:0> , <NUM_LIT:1> ) ; temp [ <NUM_LIT:2> ] = m1 . get ( <NUM_LIT:0> , <NUM_LIT:2> ) ; temp [ <NUM_LIT:3> ] = m1 . get ( <NUM_LIT:0> , <NUM_LIT:3> ) ; temp [ <NUM_LIT:4> ] = m1 . get ( <NUM_LIT:1> , <NUM_LIT:0> ) ; temp [ <NUM_LIT:5> ] = m1 . get ( <NUM_LIT:1> , <NUM_LIT:1> ) ; temp [ <NUM_LIT:6> ] = m1 . get ( <NUM_LIT:1> , <NUM_LIT:2> ) ; temp [ <NUM_LIT:7> ] = m1 . get ( <NUM_LIT:1> , <NUM_LIT:3> ) ; temp [ <NUM_LIT:8> ] = m1 . get ( <NUM_LIT:2> , <NUM_LIT:0> ) ; temp [ <NUM_LIT:9> ] = m1 . get ( <NUM_LIT:2> , <NUM_LIT:1> ) ; temp [ <NUM_LIT:10> ] = m1 . get ( <NUM_LIT:2> , <NUM_LIT:2> ) ; temp [ <NUM_LIT:11> ] = m1 . get ( <NUM_LIT:2> , <NUM_LIT:3> ) ; temp [ <NUM_LIT:12> ] = m1 . get ( <NUM_LIT:3> , <NUM_LIT:0> ) ; temp [ <NUM_LIT> ] = m1 . get ( <NUM_LIT:3> , <NUM_LIT:1> ) ; temp [ <NUM_LIT> ] = m1 . get ( <NUM_LIT:3> , <NUM_LIT:2> ) ; temp [ <NUM_LIT:15> ] = m1 . get ( <NUM_LIT:3> , <NUM_LIT:3> ) ; if ( ! luDecomposition ( temp , row_perm ) ) { throw new SingularMatrixException ( ) ; } for ( i = <NUM_LIT:0> ; i < <NUM_LIT:16> ; i ++ ) result [ i ] = <NUM_LIT:0.0> ; result [ <NUM_LIT:0> ] = <NUM_LIT:1.0> ; result [ <NUM_LIT:5> ] = <NUM_LIT:1.0> ; result [ <NUM_LIT:10> ] = <NUM_LIT:1.0> ; result [ <NUM_LIT:15> ] = <NUM_LIT:1.0> ; luBacksubstitution ( temp , row_perm , result ) ; set ( <NUM_LIT:0> , <NUM_LIT:0> , ( float ) result [ <NUM_LIT:0> ] ) ; set ( <NUM_LIT:0> , <NUM_LIT:1> , ( float ) result [ <NUM_LIT:1> ] ) ; set ( <NUM_LIT:0> , <NUM_LIT:2> , ( float ) result [ <NUM_LIT:2> ] ) ; set ( <NUM_LIT:0> , <NUM_LIT:3> , ( float ) result [ <NUM_LIT:3> ] ) ; set ( <NUM_LIT:1> , <NUM_LIT:0> , ( float ) result [ <NUM_LIT:4> ] ) ; set ( <NUM_LIT:1> , <NUM_LIT:1> , ( float ) result [ <NUM_LIT:5> ] ) ; set ( <NUM_LIT:1> , <NUM_LIT:2> , ( float ) result [ <NUM_LIT:6> ] ) ; set ( <NUM_LIT:1> , <NUM_LIT:3> , ( float ) result [ <NUM_LIT:7> ] ) ; set ( <NUM_LIT:2> , <NUM_LIT:0> , ( float ) result [ <NUM_LIT:8> ] ) ; set ( <NUM_LIT:2> , <NUM_LIT:1> , ( float ) result [ <NUM_LIT:9> ] ) ; set ( <NUM_LIT:2> , <NUM_LIT:2> , ( float ) result [ <NUM_LIT:10> ] ) ; set ( <NUM_LIT:2> , <NUM_LIT:3> , ( float ) result [ <NUM_LIT:11> ] ) ; set ( <NUM_LIT:3> , <NUM_LIT:0> , ( float ) result [ <NUM_LIT:12> ] ) ; set ( <NUM_LIT:3> , <NUM_LIT:1> , ( float ) result [ <NUM_LIT> ] ) ; set ( <NUM_LIT:3> , <NUM_LIT:2> , ( float ) result [ <NUM_LIT> ] ) ; set ( <NUM_LIT:3> , <NUM_LIT:3> , ( float ) result [ <NUM_LIT:15> ] ) ; } static boolean luDecomposition ( double [ ] matrix0 , int [ ] row_perm ) { double row_scale [ ] = new double [ <NUM_LIT:4> ] ; { int i , j ; int ptr , rs ; double big , temp ; ptr = <NUM_LIT:0> ; rs = <NUM_LIT:0> ; i = <NUM_LIT:4> ; while ( i -- != <NUM_LIT:0> ) { big = <NUM_LIT:0.0> ; j = <NUM_LIT:4> ; while ( j -- != <NUM_LIT:0> ) { temp = matrix0 [ ptr ++ ] ; temp = Math . abs ( temp ) ; if ( temp > big ) { big = temp ; } } if ( big == <NUM_LIT:0.0> ) { return false ; } row_scale [ rs ++ ] = <NUM_LIT:1.0> / big ; } } { int j ; int mtx ; mtx = <NUM_LIT:0> ; for ( j = <NUM_LIT:0> ; j < <NUM_LIT:4> ; j ++ ) { int i , imax , k ; int target , p1 , p2 ; double sum , big , temp ; for ( i = <NUM_LIT:0> ; i < j ; i ++ ) { target = mtx + ( <NUM_LIT:4> * i ) + j ; sum = matrix0 [ target ] ; k = i ; p1 = mtx + ( <NUM_LIT:4> * i ) ; p2 = mtx + j ; while ( k -- != <NUM_LIT:0> ) { sum -= matrix0 [ p1 ] * matrix0 [ p2 ] ; p1 ++ ; p2 += <NUM_LIT:4> ; } matrix0 [ target ] = sum ; } big = <NUM_LIT:0.0> ; imax = - <NUM_LIT:1> ; for ( i = j ; i < <NUM_LIT:4> ; i ++ ) { target = mtx + ( <NUM_LIT:4> * i ) + j ; sum = matrix0 [ target ] ; k = j ; p1 = mtx + ( <NUM_LIT:4> * i ) ; p2 = mtx + j ; while ( k -- != <NUM_LIT:0> ) { sum -= matrix0 [ p1 ] * matrix0 [ p2 ] ; p1 ++ ; p2 += <NUM_LIT:4> ; } matrix0 [ target ] = sum ; if ( ( temp = row_scale [ i ] * Math . abs ( sum ) ) >= big ) { big = temp ; imax = i ; } } if ( imax < <NUM_LIT:0> ) { throw new RuntimeException ( "<STR_LIT>" ) ; } if ( j != imax ) { k = <NUM_LIT:4> ; p1 = mtx + ( <NUM_LIT:4> * imax ) ; p2 = mtx + ( <NUM_LIT:4> * j ) ; while ( k -- != <NUM_LIT:0> ) { temp = matrix0 [ p1 ] ; matrix0 [ p1 ++ ] = matrix0 [ p2 ] ; matrix0 [ p2 ++ ] = temp ; } row_scale [ imax ] = row_scale [ j ] ; } row_perm [ j ] = imax ; if ( matrix0 [ ( mtx + ( <NUM_LIT:4> * j ) + j ) ] == <NUM_LIT:0.0> ) { return false ; } if ( j != ( <NUM_LIT:4> - <NUM_LIT:1> ) ) { temp = <NUM_LIT:1.0> / ( matrix0 [ ( mtx + ( <NUM_LIT:4> * j ) + j ) ] ) ; target = mtx + ( <NUM_LIT:4> * ( j + <NUM_LIT:1> ) ) + j ; i = <NUM_LIT:3> - j ; while ( i -- != <NUM_LIT:0> ) { matrix0 [ target ] *= temp ; target += <NUM_LIT:4> ; } } } } return true ; } static void luBacksubstitution ( double [ ] matrix1 , int [ ] row_perm , double [ ] matrix2 ) { int i , ii , ip , j , k ; int rp ; int cv , rv ; rp = <NUM_LIT:0> ; for ( k = <NUM_LIT:0> ; k < <NUM_LIT:4> ; k ++ ) { cv = k ; ii = - <NUM_LIT:1> ; for ( i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { double sum ; ip = row_perm [ rp + i ] ; sum = matrix2 [ cv + <NUM_LIT:4> * ip ] ; matrix2 [ cv + <NUM_LIT:4> * ip ] = matrix2 [ cv + <NUM_LIT:4> * i ] ; if ( ii >= <NUM_LIT:0> ) { rv = i * <NUM_LIT:4> ; for ( j = ii ; j <= i - <NUM_LIT:1> ; j ++ ) { sum -= matrix1 [ rv + j ] * matrix2 [ cv + <NUM_LIT:4> * j ] ; } } else if ( sum != <NUM_LIT:0.0> ) { ii = i ; } matrix2 [ cv + <NUM_LIT:4> * i ] = sum ; } rv = <NUM_LIT:3> * <NUM_LIT:4> ; matrix2 [ cv + <NUM_LIT:4> * <NUM_LIT:3> ] /= matrix1 [ rv + <NUM_LIT:3> ] ; rv -= <NUM_LIT:4> ; matrix2 [ cv + <NUM_LIT:4> * <NUM_LIT:2> ] = ( matrix2 [ cv + <NUM_LIT:4> * <NUM_LIT:2> ] - matrix1 [ rv + <NUM_LIT:3> ] * matrix2 [ cv + <NUM_LIT:4> * <NUM_LIT:3> ] ) / matrix1 [ rv + <NUM_LIT:2> ] ; rv -= <NUM_LIT:4> ; matrix2 [ cv + <NUM_LIT:4> * <NUM_LIT:1> ] = ( matrix2 [ cv + <NUM_LIT:4> * <NUM_LIT:1> ] - matrix1 [ rv + <NUM_LIT:2> ] * matrix2 [ cv + <NUM_LIT:4> * <NUM_LIT:2> ] - matrix1 [ rv + <NUM_LIT:3> ] * matrix2 [ cv + <NUM_LIT:4> * <NUM_LIT:3> ] ) / matrix1 [ rv + <NUM_LIT:1> ] ; rv -= <NUM_LIT:4> ; matrix2 [ cv + <NUM_LIT:4> * <NUM_LIT:0> ] = ( matrix2 [ cv + <NUM_LIT:4> * <NUM_LIT:0> ] - matrix1 [ rv + <NUM_LIT:1> ] * matrix2 [ cv + <NUM_LIT:4> * <NUM_LIT:1> ] - matrix1 [ rv + <NUM_LIT:2> ] * matrix2 [ cv + <NUM_LIT:4> * <NUM_LIT:2> ] - matrix1 [ rv + <NUM_LIT:3> ] * matrix2 [ cv + <NUM_LIT:4> * <NUM_LIT:3> ] ) / matrix1 [ rv + <NUM_LIT:0> ] ; } } } </s>
<s> package net . java . joglutils . msg . math ; public class Sphere { private Vec3f center = new Vec3f ( ) ; private float radius ; private float radSq ; public Sphere ( ) { makeEmpty ( ) ; } public Sphere ( Vec3f center , float radius ) { set ( center , radius ) ; } public Sphere ( Sphere other ) { set ( other ) ; } public Sphere ( Box3f box ) { set ( box ) ; } public void makeEmpty ( ) { center . set ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ; radius = radSq = <NUM_LIT:0> ; } public void setCenter ( Vec3f center ) { this . center . set ( center ) ; } public Vec3f getCenter ( ) { return center ; } public void setRadius ( float radius ) { this . radius = radius ; radSq = radius * radius ; } public float getRadius ( ) { return radius ; } public void set ( Vec3f center , float radius ) { setCenter ( center ) ; setRadius ( radius ) ; } float get ( Vec3f center ) { center . set ( this . center ) ; return radius ; } public void set ( Sphere other ) { set ( other . center , other . radius ) ; } public void set ( Box3f box ) { Vec3f max = box . getMax ( ) ; Vec3f ctr = box . getCenter ( ) ; Vec3f diff = max . minus ( ctr ) ; set ( ctr , diff . length ( ) ) ; } public void extendBy ( Sphere arg ) { if ( ( radius == <NUM_LIT:0.0f> ) || ( arg . radius == <NUM_LIT:0.0f> ) ) return ; Vec3f diff = arg . center . minus ( center ) ; if ( diff . lengthSquared ( ) == <NUM_LIT:0.0f> ) { setRadius ( Math . max ( radius , arg . radius ) ) ; return ; } IntersectionPoint [ ] intPt = new IntersectionPoint [ <NUM_LIT:4> ] ; for ( int i = <NUM_LIT:0> ; i < intPt . length ; i ++ ) { intPt [ i ] = new IntersectionPoint ( ) ; } int numIntersections ; numIntersections = intersectRay ( center , diff , intPt [ <NUM_LIT:0> ] , intPt [ <NUM_LIT:1> ] ) ; assert numIntersections == <NUM_LIT:2> ; numIntersections = intersectRay ( center , diff , intPt [ <NUM_LIT:2> ] , intPt [ <NUM_LIT:3> ] ) ; assert numIntersections == <NUM_LIT:2> ; IntersectionPoint minIntPt = intPt [ <NUM_LIT:0> ] ; IntersectionPoint maxIntPt = intPt [ <NUM_LIT:0> ] ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { if ( intPt [ i ] . getT ( ) < minIntPt . getT ( ) ) { minIntPt = intPt [ i ] ; } else if ( intPt [ i ] . getT ( ) > maxIntPt . getT ( ) ) { maxIntPt = intPt [ i ] ; } } center . add ( minIntPt . getIntersectionPoint ( ) , maxIntPt . getIntersectionPoint ( ) ) ; center . scale ( <NUM_LIT> ) ; setRadius ( <NUM_LIT> * minIntPt . getIntersectionPoint ( ) . minus ( maxIntPt . getIntersectionPoint ( ) ) . length ( ) ) ; } int intersectRay ( Vec3f rayStart , Vec3f rayDirection , IntersectionPoint intPt0 , IntersectionPoint intPt1 ) { float a = rayDirection . lengthSquared ( ) ; if ( a == <NUM_LIT:0.0> ) return <NUM_LIT:0> ; float b = <NUM_LIT> * ( rayStart . dot ( rayDirection ) - rayDirection . dot ( center ) ) ; Vec3f tempDiff = center . minus ( rayStart ) ; float c = tempDiff . lengthSquared ( ) - radSq ; float disc = b * b - <NUM_LIT:4> * a * c ; if ( disc < <NUM_LIT:0.0f> ) return <NUM_LIT:0> ; int numIntersections ; if ( disc == <NUM_LIT:0.0f> ) numIntersections = <NUM_LIT:1> ; else numIntersections = <NUM_LIT:2> ; intPt0 . setT ( ( <NUM_LIT> * ( - <NUM_LIT:1.0f> * b + ( float ) Math . sqrt ( disc ) ) ) / a ) ; if ( numIntersections == <NUM_LIT:2> ) intPt1 . setT ( ( <NUM_LIT> * ( - <NUM_LIT:1.0f> * b - ( float ) Math . sqrt ( disc ) ) ) / a ) ; Vec3f tmp = new Vec3f ( rayDirection ) ; tmp . scale ( intPt0 . getT ( ) ) ; tmp . add ( tmp , rayStart ) ; intPt0 . setIntersectionPoint ( tmp ) ; if ( numIntersections == <NUM_LIT:2> ) { tmp . set ( rayDirection ) ; tmp . scale ( intPt1 . getT ( ) ) ; tmp . add ( tmp , rayStart ) ; intPt1 . setIntersectionPoint ( tmp ) ; } return numIntersections ; } } </s>
<s> package net . java . joglutils . msg . math ; public class Mat3f { private float [ ] data ; public Mat3f ( ) { data = new float [ <NUM_LIT:9> ] ; } public void makeIdent ( ) { for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:3> ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:3> ; j ++ ) { if ( i == j ) { set ( i , j , <NUM_LIT:1.0f> ) ; } else { set ( i , j , <NUM_LIT:0.0f> ) ; } } } } public float get ( int i , int j ) { return data [ <NUM_LIT:3> * i + j ] ; } public void set ( int i , int j , float val ) { data [ <NUM_LIT:3> * i + j ] = val ; } public void setCol ( int i , Vec3f v ) { set ( <NUM_LIT:0> , i , v . x ( ) ) ; set ( <NUM_LIT:1> , i , v . y ( ) ) ; set ( <NUM_LIT:2> , i , v . z ( ) ) ; } public void setRow ( int i , Vec3f v ) { set ( i , <NUM_LIT:0> , v . x ( ) ) ; set ( i , <NUM_LIT:1> , v . y ( ) ) ; set ( i , <NUM_LIT:2> , v . z ( ) ) ; } public void transpose ( ) { float t ; t = get ( <NUM_LIT:0> , <NUM_LIT:1> ) ; set ( <NUM_LIT:0> , <NUM_LIT:1> , get ( <NUM_LIT:1> , <NUM_LIT:0> ) ) ; set ( <NUM_LIT:1> , <NUM_LIT:0> , t ) ; t = get ( <NUM_LIT:0> , <NUM_LIT:2> ) ; set ( <NUM_LIT:0> , <NUM_LIT:2> , get ( <NUM_LIT:2> , <NUM_LIT:0> ) ) ; set ( <NUM_LIT:2> , <NUM_LIT:0> , t ) ; t = get ( <NUM_LIT:1> , <NUM_LIT:2> ) ; set ( <NUM_LIT:1> , <NUM_LIT:2> , get ( <NUM_LIT:2> , <NUM_LIT:1> ) ) ; set ( <NUM_LIT:2> , <NUM_LIT:1> , t ) ; } public float determinant ( ) { return ( get ( <NUM_LIT:0> , <NUM_LIT:0> ) * ( get ( <NUM_LIT:1> , <NUM_LIT:1> ) * get ( <NUM_LIT:2> , <NUM_LIT:2> ) - get ( <NUM_LIT:2> , <NUM_LIT:1> ) * get ( <NUM_LIT:1> , <NUM_LIT:2> ) ) + get ( <NUM_LIT:0> , <NUM_LIT:1> ) * ( get ( <NUM_LIT:2> , <NUM_LIT:0> ) * get ( <NUM_LIT:1> , <NUM_LIT:2> ) - get ( <NUM_LIT:1> , <NUM_LIT:0> ) * get ( <NUM_LIT:2> , <NUM_LIT:2> ) ) + get ( <NUM_LIT:0> , <NUM_LIT:2> ) * ( get ( <NUM_LIT:1> , <NUM_LIT:0> ) * get ( <NUM_LIT:2> , <NUM_LIT:1> ) - get ( <NUM_LIT:2> , <NUM_LIT:0> ) * get ( <NUM_LIT:1> , <NUM_LIT:1> ) ) ) ; } public void invert ( ) throws SingularMatrixException { float det = determinant ( ) ; if ( det == <NUM_LIT:0.0f> ) throw new SingularMatrixException ( ) ; Mat3f cf = new Mat3f ( ) ; cf . set ( <NUM_LIT:0> , <NUM_LIT:0> , get ( <NUM_LIT:1> , <NUM_LIT:1> ) * get ( <NUM_LIT:2> , <NUM_LIT:2> ) - get ( <NUM_LIT:2> , <NUM_LIT:1> ) * get ( <NUM_LIT:1> , <NUM_LIT:2> ) ) ; cf . set ( <NUM_LIT:0> , <NUM_LIT:1> , get ( <NUM_LIT:2> , <NUM_LIT:0> ) * get ( <NUM_LIT:1> , <NUM_LIT:2> ) - get ( <NUM_LIT:1> , <NUM_LIT:0> ) * get ( <NUM_LIT:2> , <NUM_LIT:2> ) ) ; cf . set ( <NUM_LIT:0> , <NUM_LIT:2> , get ( <NUM_LIT:1> , <NUM_LIT:0> ) * get ( <NUM_LIT:2> , <NUM_LIT:1> ) - get ( <NUM_LIT:2> , <NUM_LIT:0> ) * get ( <NUM_LIT:1> , <NUM_LIT:1> ) ) ; cf . set ( <NUM_LIT:1> , <NUM_LIT:0> , get ( <NUM_LIT:2> , <NUM_LIT:1> ) * get ( <NUM_LIT:0> , <NUM_LIT:2> ) - get ( <NUM_LIT:0> , <NUM_LIT:1> ) * get ( <NUM_LIT:2> , <NUM_LIT:2> ) ) ; cf . set ( <NUM_LIT:1> , <NUM_LIT:1> , get ( <NUM_LIT:0> , <NUM_LIT:0> ) * get ( <NUM_LIT:2> , <NUM_LIT:2> ) - get ( <NUM_LIT:2> , <NUM_LIT:0> ) * get ( <NUM_LIT:0> , <NUM_LIT:2> ) ) ; cf . set ( <NUM_LIT:1> , <NUM_LIT:2> , get ( <NUM_LIT:2> , <NUM_LIT:0> ) * get ( <NUM_LIT:0> , <NUM_LIT:1> ) - get ( <NUM_LIT:0> , <NUM_LIT:0> ) * get ( <NUM_LIT:2> , <NUM_LIT:1> ) ) ; cf . set ( <NUM_LIT:2> , <NUM_LIT:0> , get ( <NUM_LIT:0> , <NUM_LIT:1> ) * get ( <NUM_LIT:1> , <NUM_LIT:2> ) - get ( <NUM_LIT:1> , <NUM_LIT:1> ) * get ( <NUM_LIT:0> , <NUM_LIT:2> ) ) ; cf . set ( <NUM_LIT:2> , <NUM_LIT:1> , get ( <NUM_LIT:1> , <NUM_LIT:0> ) * get ( <NUM_LIT:0> , <NUM_LIT:2> ) - get ( <NUM_LIT:0> , <NUM_LIT:0> ) * get ( <NUM_LIT:1> , <NUM_LIT:2> ) ) ; cf . set ( <NUM_LIT:2> , <NUM_LIT:2> , get ( <NUM_LIT:0> , <NUM_LIT:0> ) * get ( <NUM_LIT:1> , <NUM_LIT:1> ) - get ( <NUM_LIT:1> , <NUM_LIT:0> ) * get ( <NUM_LIT:0> , <NUM_LIT:1> ) ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:3> ; i ++ ) for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:3> ; j ++ ) set ( i , j , cf . get ( j , i ) / det ) ; } public void xformVec ( Vec3f src , Vec3f dest ) { dest . set ( get ( <NUM_LIT:0> , <NUM_LIT:0> ) * src . x ( ) + get ( <NUM_LIT:0> , <NUM_LIT:1> ) * src . y ( ) + get ( <NUM_LIT:0> , <NUM_LIT:2> ) * src . z ( ) , get ( <NUM_LIT:1> , <NUM_LIT:0> ) * src . x ( ) + get ( <NUM_LIT:1> , <NUM_LIT:1> ) * src . y ( ) + get ( <NUM_LIT:1> , <NUM_LIT:2> ) * src . z ( ) , get ( <NUM_LIT:2> , <NUM_LIT:0> ) * src . x ( ) + get ( <NUM_LIT:2> , <NUM_LIT:1> ) * src . y ( ) + get ( <NUM_LIT:2> , <NUM_LIT:2> ) * src . z ( ) ) ; } public Mat3f mul ( Mat3f b ) { Mat3f tmp = new Mat3f ( ) ; tmp . mul ( this , b ) ; return tmp ; } public void mul ( Mat3f a , Mat3f b ) { for ( int rc = <NUM_LIT:0> ; rc < <NUM_LIT:3> ; rc ++ ) for ( int cc = <NUM_LIT:0> ; cc < <NUM_LIT:3> ; cc ++ ) { float tmp = <NUM_LIT:0.0f> ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:3> ; i ++ ) tmp += a . get ( rc , i ) * b . get ( i , cc ) ; set ( rc , cc , tmp ) ; } } public Matf toMatf ( ) { Matf out = new Matf ( <NUM_LIT:3> , <NUM_LIT:3> ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:3> ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:3> ; j ++ ) { out . set ( i , j , get ( i , j ) ) ; } } return out ; } public String toString ( ) { String endl = System . getProperty ( "<STR_LIT>" ) ; return "<STR_LIT:(>" + get ( <NUM_LIT:0> , <NUM_LIT:0> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:0> , <NUM_LIT:1> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:0> , <NUM_LIT:2> ) + endl + get ( <NUM_LIT:1> , <NUM_LIT:0> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:1> , <NUM_LIT:1> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:1> , <NUM_LIT:2> ) + endl + get ( <NUM_LIT:2> , <NUM_LIT:0> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:2> , <NUM_LIT:1> ) + "<STR_LIT:U+002CU+0020>" + get ( <NUM_LIT:2> , <NUM_LIT:2> ) + "<STR_LIT:)>" ; } } </s>
<s> package net . java . joglutils . msg . math ; public class Veci { private int [ ] data ; public Veci ( int n ) { data = new int [ n ] ; } public Veci ( Veci arg ) { data = new int [ arg . data . length ] ; System . arraycopy ( arg . data , <NUM_LIT:0> , data , <NUM_LIT:0> , data . length ) ; } public int length ( ) { return data . length ; } public int get ( int i ) { return data [ i ] ; } public void set ( int i , int val ) { data [ i ] = val ; } public Vec2f toVec2f ( ) throws DimensionMismatchException { if ( length ( ) != <NUM_LIT:2> ) throw new DimensionMismatchException ( ) ; Vec2f out = new Vec2f ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:2> ; i ++ ) { out . set ( i , get ( i ) ) ; } return out ; } public Vec3f toVec3f ( ) throws DimensionMismatchException { if ( length ( ) != <NUM_LIT:3> ) throw new DimensionMismatchException ( ) ; Vec3f out = new Vec3f ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:3> ; i ++ ) { out . set ( i , get ( i ) ) ; } return out ; } public Vecf toVecf ( ) { Vecf out = new Vecf ( length ( ) ) ; for ( int i = <NUM_LIT:0> ; i < length ( ) ; i ++ ) { out . set ( i , get ( i ) ) ; } return out ; } } </s>
<s> package net . java . joglutils . msg . math ; public class Line { private Vec3f point ; private Vec3f direction ; private Vec3f alongVec ; public Line ( ) { point = new Vec3f ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ; direction = new Vec3f ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ; alongVec = new Vec3f ( ) ; recalc ( ) ; } public Line ( Vec3f direction , Vec3f point ) { this . direction = new Vec3f ( direction ) ; this . direction . normalize ( ) ; this . point = new Vec3f ( point ) ; alongVec = new Vec3f ( ) ; recalc ( ) ; } public void setDirection ( Vec3f direction ) { this . direction . set ( direction ) ; this . direction . normalize ( ) ; recalc ( ) ; } public Vec3f getDirection ( ) { return direction ; } public void setPoint ( Vec3f point ) { this . point . set ( point ) ; recalc ( ) ; } public Vec3f getPoint ( ) { return point ; } public void projectPoint ( Vec3f pt , Vec3f projPt ) { float dotp = direction . dot ( pt ) ; projPt . set ( direction ) ; projPt . scale ( dotp ) ; projPt . add ( alongVec ) ; } public boolean closestPointToRay ( Vec3f rayStart , Vec3f rayDirection , Vec3f closestPoint ) { Mat2f A = new Mat2f ( ) ; A . set ( <NUM_LIT:0> , <NUM_LIT:0> , - direction . lengthSquared ( ) ) ; A . set ( <NUM_LIT:1> , <NUM_LIT:1> , - rayDirection . lengthSquared ( ) ) ; A . set ( <NUM_LIT:0> , <NUM_LIT:1> , direction . dot ( rayDirection ) ) ; A . set ( <NUM_LIT:1> , <NUM_LIT:0> , A . get ( <NUM_LIT:0> , <NUM_LIT:1> ) ) ; if ( Math . abs ( A . determinant ( ) ) == <NUM_LIT:0.0f> ) { return false ; } if ( ! A . invert ( ) ) { return false ; } Vec2f b = new Vec2f ( ) ; b . setX ( point . dot ( direction ) - rayStart . dot ( direction ) ) ; b . setY ( rayStart . dot ( rayDirection ) - point . dot ( rayDirection ) ) ; Vec2f x = new Vec2f ( ) ; A . xformVec ( b , x ) ; if ( x . y ( ) < <NUM_LIT:0> ) { closestPoint . set ( rayStart ) ; } else { closestPoint . set ( direction ) ; closestPoint . scale ( x . x ( ) ) ; closestPoint . add ( point ) ; } return true ; } private void recalc ( ) { float denom = direction . lengthSquared ( ) ; if ( denom == <NUM_LIT:0.0f> ) { throw new RuntimeException ( "<STR_LIT>" + "<STR_LIT>" ) ; } alongVec . set ( point . minus ( direction . times ( point . dot ( direction ) ) ) ) ; } } </s>
<s> package net . java . joglutils . msg . test ; import java . awt . BorderLayout ; import java . awt . DisplayMode ; import java . awt . Frame ; import java . awt . GraphicsDevice ; import java . awt . GraphicsEnvironment ; import java . awt . event . * ; import java . net . * ; import javax . swing . * ; import javax . media . opengl . * ; import javax . media . opengl . awt . * ; public class DisplayShelf { public static void main ( String [ ] args ) { Frame f = new Frame ( "<STR_LIT>" ) ; f . setLayout ( new BorderLayout ( ) ) ; f . addWindowListener ( new WindowAdapter ( ) { public void windowClosing ( WindowEvent e ) { new Thread ( new Runnable ( ) { public void run ( ) { System . exit ( <NUM_LIT:0> ) ; } } ) . start ( ) ; } } ) ; String [ ] images = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; DefaultListModel model = new DefaultListModel ( ) ; for ( String str : images ) { try { model . addElement ( new URL ( str ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } DisplayShelfRenderer renderer = new DisplayShelfRenderer ( model ) ; GLCanvas canvas = new GLCanvas ( new GLCapabilities ( GLProfile . getDefault ( ) ) , null , renderer . getSharedContext ( ) , null ) ; canvas . setFocusable ( true ) ; canvas . addGLEventListener ( renderer ) ; f . add ( canvas ) ; GraphicsDevice dev = GraphicsEnvironment . getLocalGraphicsEnvironment ( ) . getDefaultScreenDevice ( ) ; DisplayMode curMode = dev . getDisplayMode ( ) ; int height = ( int ) ( <NUM_LIT> * curMode . getWidth ( ) ) ; f . setSize ( curMode . getWidth ( ) , height ) ; f . setLocation ( <NUM_LIT:0> , ( curMode . getHeight ( ) - height ) / <NUM_LIT:2> ) ; f . setVisible ( true ) ; } } </s>
<s> package net . java . joglutils . msg . test ; import java . awt . Frame ; import java . awt . event . * ; import java . io . * ; import javax . media . opengl . * ; import javax . media . opengl . awt . * ; import com . sun . opengl . util . texture . * ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . collections . * ; import net . java . joglutils . msg . math . * ; import net . java . joglutils . msg . nodes . * ; public class Test { public static void main ( String [ ] args ) { Frame frame = new Frame ( "<STR_LIT>" ) ; GLCanvas canvas = new GLCanvas ( ) ; canvas . addGLEventListener ( new Listener ( ) ) ; frame . add ( canvas ) ; frame . setSize ( <NUM_LIT> , <NUM_LIT> ) ; frame . setVisible ( true ) ; frame . addWindowListener ( new WindowAdapter ( ) { public void windowClosing ( WindowEvent e ) { new Thread ( new Runnable ( ) { public void run ( ) { System . exit ( <NUM_LIT:0> ) ; } } ) . start ( ) ; } } ) ; } static class Listener implements GLEventListener { private Separator root ; private GLRenderAction renderAction ; public void init ( GLAutoDrawable drawable ) { root = new Separator ( ) ; PerspectiveCamera cam = new PerspectiveCamera ( ) ; cam . setPosition ( new Vec3f ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:2> ) ) ; root . addChild ( cam ) ; Coordinate3 coordNode = new Coordinate3 ( ) ; Vec3fCollection coords = new Vec3fCollection ( ) ; coords . add ( new Vec3f ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> ) ) ; coords . add ( new Vec3f ( - <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> ) ) ; coords . add ( new Vec3f ( - <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:0> ) ) ; coords . add ( new Vec3f ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> ) ) ; coords . add ( new Vec3f ( - <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:0> ) ) ; coords . add ( new Vec3f ( <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:0> ) ) ; coordNode . setData ( coords ) ; root . addChild ( coordNode ) ; TextureCoordinate2 texCoordNode = new TextureCoordinate2 ( ) ; Vec2fCollection texCoords = new Vec2fCollection ( ) ; texCoords . add ( new Vec2f ( <NUM_LIT:1> , <NUM_LIT:1> ) ) ; texCoords . add ( new Vec2f ( <NUM_LIT:0> , <NUM_LIT:1> ) ) ; texCoords . add ( new Vec2f ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ; texCoords . add ( new Vec2f ( <NUM_LIT:1> , <NUM_LIT:1> ) ) ; texCoords . add ( new Vec2f ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ; texCoords . add ( new Vec2f ( <NUM_LIT:1> , <NUM_LIT:0> ) ) ; texCoordNode . setData ( texCoords ) ; root . addChild ( texCoordNode ) ; Color4 colorNode = new Color4 ( ) ; Vec4fCollection colors = new Vec4fCollection ( ) ; colors . add ( new Vec4f ( <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> ) ) ; colors . add ( new Vec4f ( <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> ) ) ; colors . add ( new Vec4f ( <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> ) ) ; colors . add ( new Vec4f ( <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> ) ) ; colors . add ( new Vec4f ( <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> ) ) ; colors . add ( new Vec4f ( <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> ) ) ; colorNode . setData ( colors ) ; root . addChild ( colorNode ) ; TriangleSet tris = new TriangleSet ( ) ; tris . setNumTriangles ( <NUM_LIT:2> ) ; root . addChild ( tris ) ; Transform xform = new Transform ( ) ; xform . getTransform ( ) . setTranslation ( new Vec3f ( <NUM_LIT:2> , - <NUM_LIT:2> , <NUM_LIT:0> ) ) ; root . addChild ( xform ) ; root . addChild ( tris ) ; GL gl = drawable . getGL ( ) ; gl . glEnable ( GL . GL_DEPTH_TEST ) ; renderAction = new GLRenderAction ( ) ; } public void display ( GLAutoDrawable drawable ) { GL gl = drawable . getGL ( ) ; gl . glClear ( GL . GL_COLOR_BUFFER_BIT | GL . GL_DEPTH_BUFFER_BIT ) ; renderAction . apply ( root ) ; } public void reshape ( GLAutoDrawable drawable , int x , int y , int w , int h ) { } public void dispose ( GLAutoDrawable drawable ) { } } } </s>
<s> package net . java . joglutils . msg . test ; public interface ProgressListener < IDENT > { public void progressStart ( ProgressEvent < IDENT > evt ) ; public void progressUpdate ( ProgressEvent < IDENT > evt ) ; public void progressEnd ( ProgressEvent < IDENT > evt ) ; } </s>
<s> package net . java . joglutils . msg . test ; import java . awt . BasicStroke ; import java . awt . Color ; import java . awt . Graphics2D ; import java . awt . event . * ; import java . awt . image . * ; import java . net . * ; import java . util . * ; import javax . swing . * ; import javax . swing . event . * ; import javax . media . opengl . * ; import javax . media . opengl . awt . * ; import com . sun . opengl . util . awt . * ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . collections . * ; import net . java . joglutils . msg . math . * ; import net . java . joglutils . msg . misc . * ; import net . java . joglutils . msg . nodes . * ; public class DisplayShelfRenderer implements GLEventListener { private float DEFAULT_ASPECT_RATIO = <NUM_LIT> ; private float DEFAULT_HEIGHT = <NUM_LIT> ; private float DEFAULT_ON_SCREEN_FRAC = <NUM_LIT> ; private float EDITING_ON_SCREEN_FRAC = <NUM_LIT> ; private float offsetFrac ; private float STACKED_SPACING_FRAC = <NUM_LIT> ; private float SELECTED_SPACING_FRAC = <NUM_LIT> ; private float EDITED_SPACING_FRAC = <NUM_LIT> ; private float SINGLE_IMAGE_MODE_RAISE_FRAC = <NUM_LIT> ; private PerspectiveCamera camera ; static class TitleGraph { Object imageDescriptor ; Separator sep = new Separator ( ) ; Transform xform = new Transform ( ) ; Texture2 texture = new Texture2 ( ) ; Coordinate3 coords = new Coordinate3 ( ) ; TitleGraph ( Object imageDescriptor ) { this . imageDescriptor = imageDescriptor ; } } private GLPbuffer sharedPbuffer ; private boolean firstInit = true ; private AWTGLAutoDrawable drawable ; private Separator root ; private Separator imageRoot ; private Fetcher < Integer > fetcher ; private ListModel model ; private List < TitleGraph > titles = new ArrayList < TitleGraph > ( ) ; private GLRenderAction ra = new GLRenderAction ( ) ; private int targetIndex ; private float currentIndex ; private float currentZ ; private float targetZ ; private float viewingZ ; private float editingZ ; private float currentY ; private float targetY ; private static final float EPSILON = <NUM_LIT> ; private SystemTime time ; private boolean animating ; private boolean forceRecompute ; private boolean singleImageMode ; private static final float ANIM_SCALE_FACTOR = <NUM_LIT> ; private static final float ROT_ANGLE = ( float ) Math . toRadians ( <NUM_LIT> ) ; private Texture2 clockTexture ; private volatile boolean doneLoading ; class DownloadListener implements ProgressListener < Integer > { public void progressStart ( ProgressEvent < Integer > evt ) { } public void progressUpdate ( ProgressEvent < Integer > evt ) { } public void progressEnd ( ProgressEvent < Integer > evt ) { updateImage ( evt . getClientIdentifier ( ) ) ; } } public DisplayShelfRenderer ( ListModel model ) { sharedPbuffer = GLDrawableFactory . getFactory ( GLProfile . getDefault ( ) ) . createGLPbuffer ( new GLCapabilities ( GLProfile . getDefault ( ) ) , null , <NUM_LIT:1> , <NUM_LIT:1> , null ) ; sharedPbuffer . display ( ) ; this . fetcher = new BasicFetcher < Integer > ( ) ; fetcher . addProgressListener ( new DownloadListener ( ) ) ; this . model = model ; root = new Separator ( ) ; time = new SystemTime ( ) ; time . rebase ( ) ; camera = new PerspectiveCamera ( ) ; camera . setNearDistance ( <NUM_LIT:1.0f> ) ; camera . setFarDistance ( <NUM_LIT> ) ; camera . setHeightAngle ( ( float ) Math . PI / <NUM_LIT:8> ) ; viewingZ = <NUM_LIT> * DEFAULT_HEIGHT / ( DEFAULT_ON_SCREEN_FRAC * ( float ) Math . tan ( camera . getHeightAngle ( ) ) ) ; offsetFrac = ( float ) ( ( ( <NUM_LIT:3> * Math . PI / <NUM_LIT> ) / camera . getHeightAngle ( ) ) + <NUM_LIT> ) ; } public GLContext getSharedContext ( ) { return sharedPbuffer . getContext ( ) ; } public void setSingleImageMode ( boolean singleImageMode , boolean animateTransition ) { this . singleImageMode = singleImageMode ; if ( ! animating ) { time . rebase ( ) ; } recomputeTargetYZ ( animateTransition ) ; forceRecompute = ! animateTransition ; if ( drawable != null ) { drawable . repaint ( ) ; } } public boolean getSingleImageMode ( ) { return singleImageMode ; } public int getNumImages ( ) { return titles . size ( ) ; } public void setTargetIndex ( int index ) { if ( targetIndex == index ) return ; this . targetIndex = index ; if ( ! animating ) { time . rebase ( ) ; } recomputeTargetYZ ( true ) ; if ( drawable != null ) { drawable . repaint ( ) ; } } public int getTargetIndex ( ) { return targetIndex ; } public void init ( GLAutoDrawable d ) { this . drawable = ( AWTGLAutoDrawable ) d ; GL gl = drawable . getGL ( ) ; if ( firstInit ) { firstInit = false ; clockTexture = new Texture2 ( ) ; clockTexture . initTextureRenderer ( ( int ) ( <NUM_LIT> * DEFAULT_HEIGHT * DEFAULT_ASPECT_RATIO ) , ( int ) ( <NUM_LIT> * DEFAULT_HEIGHT ) , false ) ; imageRoot = new Separator ( ) ; Separator mirrorRoot = new Separator ( ) ; Transform mirrorXform = new Transform ( ) ; mirrorXform . getTransform ( ) . set ( <NUM_LIT:1> , <NUM_LIT:1> , - <NUM_LIT:1.0f> ) ; mirrorRoot . addChild ( mirrorXform ) ; Color4 colorNode = new Color4 ( ) ; Vec4fCollection colors = new Vec4fCollection ( ) ; Vec4f fadeTop = new Vec4f ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; Vec4f fadeBot = new Vec4f ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; colors . add ( fadeTop ) ; colors . add ( fadeTop ) ; colors . add ( fadeBot ) ; colors . add ( fadeTop ) ; colors . add ( fadeBot ) ; colors . add ( fadeBot ) ; colorNode . setData ( colors ) ; mirrorRoot . addChild ( colorNode ) ; TriangleSet tris = new TriangleSet ( ) ; tris . setNumTriangles ( <NUM_LIT:2> ) ; for ( int i = <NUM_LIT:0> ; i < model . getSize ( ) ; i ++ ) { Object obj = model . getElementAt ( i ) ; TitleGraph graph = new TitleGraph ( obj ) ; titles . add ( graph ) ; computeCoords ( graph . coords , DEFAULT_ASPECT_RATIO ) ; graph . xform . getTransform ( ) . setTranslation ( new Vec3f ( i , <NUM_LIT:0> , <NUM_LIT:0> ) ) ; Separator sep = graph . sep ; sep . addChild ( graph . xform ) ; sep . addChild ( graph . coords ) ; sep . addChild ( clockTexture ) ; TextureCoordinate2 texCoordNode = new TextureCoordinate2 ( ) ; Vec2fCollection texCoords = new Vec2fCollection ( ) ; texCoords . add ( new Vec2f ( <NUM_LIT:1> , <NUM_LIT:1> ) ) ; texCoords . add ( new Vec2f ( <NUM_LIT:0> , <NUM_LIT:1> ) ) ; texCoords . add ( new Vec2f ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ; texCoords . add ( new Vec2f ( <NUM_LIT:1> , <NUM_LIT:1> ) ) ; texCoords . add ( new Vec2f ( <NUM_LIT:0> , <NUM_LIT:0> ) ) ; texCoords . add ( new Vec2f ( <NUM_LIT:1> , <NUM_LIT:0> ) ) ; texCoordNode . setData ( texCoords ) ; sep . addChild ( texCoordNode ) ; sep . addChild ( tris ) ; imageRoot . addChild ( sep ) ; mirrorRoot . addChild ( sep ) ; } float maxSpacing = DEFAULT_HEIGHT * Math . max ( STACKED_SPACING_FRAC , Math . max ( SELECTED_SPACING_FRAC , EDITED_SPACING_FRAC ) ) ; int i = model . getSize ( ) ; float minx = - i * maxSpacing ; float maxx = <NUM_LIT:2> * i * maxSpacing ; float minz = - <NUM_LIT:2> * DEFAULT_HEIGHT ; float maxz = DEFAULT_HEIGHT ; Separator floorRoot = new Separator ( ) ; Blend blend = new Blend ( ) ; blend . setEnabled ( true ) ; blend . setSourceFunc ( Blend . ONE ) ; blend . setDestFunc ( Blend . ONE_MINUS_SRC_ALPHA ) ; floorRoot . addChild ( blend ) ; Coordinate3 floorCoords = new Coordinate3 ( ) ; floorCoords . setData ( new Vec3fCollection ( ) ) ; floorCoords . getData ( ) . add ( new Vec3f ( maxx , <NUM_LIT:0> , minz ) ) ; floorCoords . getData ( ) . add ( new Vec3f ( minx , <NUM_LIT:0> , minz ) ) ; floorCoords . getData ( ) . add ( new Vec3f ( minx , <NUM_LIT:0> , maxz ) ) ; floorCoords . getData ( ) . add ( new Vec3f ( maxx , <NUM_LIT:0> , minz ) ) ; floorCoords . getData ( ) . add ( new Vec3f ( minx , <NUM_LIT:0> , maxz ) ) ; floorCoords . getData ( ) . add ( new Vec3f ( maxx , <NUM_LIT:0> , maxz ) ) ; floorRoot . addChild ( floorCoords ) ; Vec4f gray = new Vec4f ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; Vec4f clearGray = new Vec4f ( <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> ) ; Color4 floorColors = new Color4 ( ) ; floorColors . setData ( new Vec4fCollection ( ) ) ; floorColors . getData ( ) . add ( gray ) ; floorColors . getData ( ) . add ( gray ) ; floorColors . getData ( ) . add ( clearGray ) ; floorColors . getData ( ) . add ( gray ) ; floorColors . getData ( ) . add ( clearGray ) ; floorColors . getData ( ) . add ( clearGray ) ; floorRoot . addChild ( floorColors ) ; floorRoot . addChild ( tris ) ; root . addChild ( camera ) ; root . addChild ( imageRoot ) ; root . addChild ( mirrorRoot ) ; root . addChild ( floorRoot ) ; drawable . addMouseListener ( new MListener ( ) ) ; drawable . addKeyListener ( new KeyAdapter ( ) { public void keyPressed ( KeyEvent e ) { switch ( e . getKeyCode ( ) ) { case KeyEvent . VK_SPACE : setSingleImageMode ( ! getSingleImageMode ( ) , true ) ; break ; case KeyEvent . VK_ENTER : setSingleImageMode ( ! getSingleImageMode ( ) , false ) ; break ; case KeyEvent . VK_LEFT : setTargetIndex ( Math . max ( <NUM_LIT:0> , targetIndex - <NUM_LIT:1> ) ) ; break ; case KeyEvent . VK_RIGHT : setTargetIndex ( Math . min ( titles . size ( ) - <NUM_LIT:1> , targetIndex + <NUM_LIT:1> ) ) ; break ; } } } ) ; startClockAnimation ( ) ; recomputeTargetYZ ( false ) ; forceRecompute = true ; recompute ( ) ; for ( int j = <NUM_LIT:0> ; j < titles . size ( ) ; j ++ ) { updateImage ( j ) ; } } } public void display ( GLAutoDrawable drawable ) { boolean repaintAgain = recompute ( ) ; if ( ! doneLoading ) { if ( ! repaintAgain ) { time . update ( ) ; } TextureRenderer rend = clockTexture . getTextureRenderer ( ) ; Graphics2D g = rend . createGraphics ( ) ; drawClock ( g , ( int ) ( time . time ( ) * <NUM_LIT:30> ) , <NUM_LIT:0> , <NUM_LIT:0> , rend . getWidth ( ) , rend . getHeight ( ) ) ; g . dispose ( ) ; rend . markDirty ( <NUM_LIT:0> , <NUM_LIT:0> , rend . getWidth ( ) , rend . getHeight ( ) ) ; } GL gl = drawable . getGL ( ) ; gl . glClear ( GL . GL_COLOR_BUFFER_BIT | GL . GL_DEPTH_BUFFER_BIT ) ; ra . apply ( root ) ; if ( repaintAgain ) { animating = true ; ( ( AWTGLAutoDrawable ) drawable ) . repaint ( ) ; } else { animating = false ; } } public void reshape ( GLAutoDrawable drawable , int x , int y , int width , int height ) { } public void dispose ( GLAutoDrawable drawable ) { } private void computeCoords ( Coordinate3 coordNode , float aspectRatio ) { Vec3fCollection coords = coordNode . getData ( ) ; if ( coords == null ) { coords = new Vec3fCollection ( ) ; Vec3f zero = new Vec3f ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:6> ; i ++ ) { coords . add ( zero ) ; } coordNode . setData ( coords ) ; } Vec3f lowerLeft = new Vec3f ( - <NUM_LIT> * DEFAULT_HEIGHT * aspectRatio , <NUM_LIT:0> , <NUM_LIT:0> ) ; Vec3f lowerRight = new Vec3f ( <NUM_LIT> * DEFAULT_HEIGHT * aspectRatio , <NUM_LIT:0> , <NUM_LIT:0> ) ; Vec3f upperLeft = new Vec3f ( - <NUM_LIT> * DEFAULT_HEIGHT * aspectRatio , DEFAULT_HEIGHT , <NUM_LIT:0> ) ; Vec3f upperRight = new Vec3f ( <NUM_LIT> * DEFAULT_HEIGHT * aspectRatio , DEFAULT_HEIGHT , <NUM_LIT:0> ) ; coords . set ( <NUM_LIT:0> , upperRight ) ; coords . set ( <NUM_LIT:1> , upperLeft ) ; coords . set ( <NUM_LIT:2> , lowerLeft ) ; coords . set ( <NUM_LIT:3> , upperRight ) ; coords . set ( <NUM_LIT:4> , lowerLeft ) ; coords . set ( <NUM_LIT:5> , lowerRight ) ; } private static void drawClock ( Graphics2D g , int minsPastMidnight , int x , int y , int width , int height ) { g . setColor ( Color . DARK_GRAY ) ; g . fillRect ( x , y , width , height ) ; g . setColor ( Color . GRAY ) ; int midx = ( int ) ( x + ( width / <NUM_LIT> ) ) ; int midy = ( int ) ( y + ( height / <NUM_LIT> ) ) ; int sz = ( int ) ( <NUM_LIT> * Math . min ( width , height ) ) ; g . setStroke ( new BasicStroke ( sz / <NUM_LIT> , BasicStroke . CAP_ROUND , BasicStroke . JOIN_MITER ) ) ; int arcSz = ( int ) ( <NUM_LIT> * sz ) ; int smallHandSz = ( int ) ( <NUM_LIT> * sz ) ; int bigHandSz = ( int ) ( <NUM_LIT> * sz ) ; g . drawRoundRect ( midx - ( sz / <NUM_LIT:2> ) , midy - ( sz / <NUM_LIT:2> ) , sz , sz , arcSz , arcSz ) ; float hour = minsPastMidnight / <NUM_LIT> ; int min = minsPastMidnight % <NUM_LIT> ; float hourAngle = hour * <NUM_LIT> * ( float ) Math . PI / <NUM_LIT:12> ; float minAngle = min * <NUM_LIT> * ( float ) Math . PI / <NUM_LIT> ; g . drawLine ( midx , midy , midx + ( int ) ( smallHandSz * Math . cos ( hourAngle ) ) , midy + ( int ) ( smallHandSz * Math . sin ( hourAngle ) ) ) ; g . drawLine ( midx , midy , midx + ( int ) ( bigHandSz * Math . cos ( minAngle ) ) , midy + ( int ) ( bigHandSz * Math . sin ( minAngle ) ) ) ; } private void startClockAnimation ( ) { Thread clockAnimThread = new Thread ( new Runnable ( ) { public void run ( ) { while ( ! doneLoading ) { drawable . repaint ( ) ; try { Thread . sleep ( <NUM_LIT:100> ) ; } catch ( InterruptedException e ) { } } } } ) ; clockAnimThread . start ( ) ; } private void updateImage ( int id ) { TitleGraph graph = titles . get ( id ) ; BufferedImage img = fetcher . getImage ( graph . imageDescriptor , Integer . valueOf ( id ) , - <NUM_LIT:1> ) ; if ( img != null ) { graph . imageDescriptor = null ; graph . sep . replaceChild ( clockTexture , graph . texture ) ; graph . texture . setTexture ( img , false ) ; float aspectRatio = ( float ) img . getWidth ( ) / ( float ) img . getHeight ( ) ; computeCoords ( graph . coords , aspectRatio ) ; drawable . repaint ( ) ; } boolean done = true ; for ( TitleGraph cur : titles ) { if ( cur . imageDescriptor != null ) { done = false ; break ; } } if ( done ) { doneLoading = true ; } } private void recomputeTargetYZ ( boolean animate ) { if ( singleImageMode ) { targetY = ( <NUM_LIT> + SINGLE_IMAGE_MODE_RAISE_FRAC ) * DEFAULT_HEIGHT ; editingZ = <NUM_LIT> * DEFAULT_HEIGHT / ( EDITING_ON_SCREEN_FRAC * ( float ) Math . tan ( camera . getHeightAngle ( ) ) ) ; targetZ = editingZ ; } else { targetY = <NUM_LIT> * DEFAULT_HEIGHT ; targetZ = viewingZ ; } if ( ! animate ) { currentY = targetY ; currentZ = targetZ ; currentIndex = targetIndex ; } } private boolean recompute ( ) { if ( ! forceRecompute ) { if ( Math . abs ( targetIndex - currentIndex ) < EPSILON && Math . abs ( targetZ - currentZ ) < EPSILON && Math . abs ( targetY - currentY ) < EPSILON ) return false ; } forceRecompute = false ; time . update ( ) ; float deltaT = ( float ) time . deltaT ( ) ; currentIndex = currentIndex + ( targetIndex - currentIndex ) * deltaT * ANIM_SCALE_FACTOR ; currentZ = currentZ + ( targetZ - currentZ ) * deltaT * ANIM_SCALE_FACTOR ; currentY = currentY + ( targetY - currentY ) * deltaT * ANIM_SCALE_FACTOR ; float zAlpha = ( currentZ - viewingZ ) / ( editingZ - viewingZ ) ; int firstIndex = ( int ) Math . floor ( currentIndex ) ; int secondIndex = ( int ) Math . ceil ( currentIndex ) ; if ( secondIndex == firstIndex ) { secondIndex = firstIndex + <NUM_LIT:1> ; } float alpha = currentIndex - firstIndex ; int idx = <NUM_LIT:0> ; float curPos = <NUM_LIT:0.0f> ; float stackedSpacing = DEFAULT_HEIGHT * ( zAlpha * EDITED_SPACING_FRAC + ( <NUM_LIT:1.0f> - zAlpha ) * STACKED_SPACING_FRAC ) ; float selectedSpacing = DEFAULT_HEIGHT * ( zAlpha * EDITED_SPACING_FRAC + ( <NUM_LIT:1.0f> - zAlpha ) * SELECTED_SPACING_FRAC ) ; float angle = ( <NUM_LIT:1.0f> - zAlpha ) * ROT_ANGLE ; float y = zAlpha * DEFAULT_HEIGHT * SINGLE_IMAGE_MODE_RAISE_FRAC ; Rotf posAngle = new Rotf ( Vec3f . Y_AXIS , angle ) ; Rotf negAngle = new Rotf ( Vec3f . Y_AXIS , - angle ) ; float offset = <NUM_LIT:0> ; if ( Math . abs ( targetIndex - currentIndex ) < <NUM_LIT> ) { offset = ( <NUM_LIT:1.0f> - zAlpha ) * offsetFrac * DEFAULT_HEIGHT ; } for ( TitleGraph graph : titles ) { if ( idx < firstIndex ) { graph . xform . getTransform ( ) . setRotation ( posAngle ) ; graph . xform . getTransform ( ) . setTranslation ( new Vec3f ( curPos , y , <NUM_LIT:0> ) ) ; curPos += stackedSpacing ; } else if ( idx > secondIndex ) { graph . xform . getTransform ( ) . setRotation ( negAngle ) ; graph . xform . getTransform ( ) . setTranslation ( new Vec3f ( curPos , y , <NUM_LIT:0> ) ) ; curPos += stackedSpacing ; } else if ( idx == firstIndex ) { curPos += ( <NUM_LIT:1.0f> - alpha ) * ( selectedSpacing - stackedSpacing ) ; float cameraPos = curPos + alpha * selectedSpacing ; graph . xform . getTransform ( ) . setRotation ( new Rotf ( Vec3f . Y_AXIS , alpha * angle ) ) ; graph . xform . getTransform ( ) . setTranslation ( new Vec3f ( curPos , y , ( <NUM_LIT:1.0f> - alpha ) * offset ) ) ; camera . setPosition ( new Vec3f ( cameraPos , currentY , currentZ ) ) ; curPos += selectedSpacing ; } else { graph . xform . getTransform ( ) . setRotation ( new Rotf ( Vec3f . Y_AXIS , ( <NUM_LIT:1.0f> - alpha ) * - angle ) ) ; graph . xform . getTransform ( ) . setTranslation ( new Vec3f ( curPos , y , alpha * offset ) ) ; curPos += stackedSpacing + alpha * ( selectedSpacing - stackedSpacing ) ; } ++ idx ; } return true ; } class MListener extends MouseAdapter { RayPickAction ra = new RayPickAction ( ) ; public void mousePressed ( MouseEvent e ) { ra . setPoint ( e . getX ( ) , e . getY ( ) , e . getComponent ( ) ) ; ra . apply ( root ) ; List < PickedPoint > pickedPoints = ra . getPickedPoints ( ) ; Path p = null ; if ( ! pickedPoints . isEmpty ( ) ) p = pickedPoints . get ( <NUM_LIT:0> ) . getPath ( ) ; if ( p != null && p . size ( ) > <NUM_LIT:1> ) { int idx = imageRoot . findChild ( p . get ( p . size ( ) - <NUM_LIT:2> ) ) ; if ( idx >= <NUM_LIT:0> ) { setTargetIndex ( idx ) ; } } } } } </s>
<s> package net . java . joglutils . msg . test ; import java . awt . EventQueue ; import java . awt . image . * ; import java . io . * ; import java . net . * ; import java . util . * ; import java . util . concurrent . * ; import javax . imageio . * ; public class BasicFetcher < IDENT > implements Fetcher < IDENT > { private volatile ArrayList < ProgressListener > listeners = new ArrayList < ProgressListener > ( ) ; private Map < FetchKey , Future < BufferedImage > > activeTasks = new HashMap < FetchKey , Future < BufferedImage > > ( ) ; private ExecutorService threadPool ; public BasicFetcher ( ) { threadPool = Executors . newSingleThreadExecutor ( new ThreadFactory ( ) { public Thread newThread ( Runnable r ) { Thread t = Executors . defaultThreadFactory ( ) . newThread ( r ) ; t . setPriority ( Thread . NORM_PRIORITY - <NUM_LIT:2> ) ; return t ; } } ) ; } public synchronized BufferedImage getImage ( final Object imageDescriptor , final IDENT clientIdentifier , final int requestedImageSize ) { FetchKey key = new FetchKey ( imageDescriptor , clientIdentifier , requestedImageSize ) ; Future < BufferedImage > result = activeTasks . get ( key ) ; if ( result != null ) { try { return result . get ( <NUM_LIT:1> , TimeUnit . MILLISECONDS ) ; } catch ( Exception e ) { return null ; } } FutureTask < BufferedImage > task = new FutureTask < BufferedImage > ( new Callable < BufferedImage > ( ) { public BufferedImage call ( ) { try { if ( imageDescriptor instanceof File ) { return ImageIO . read ( ( File ) imageDescriptor ) ; } else if ( imageDescriptor instanceof URL ) { return ImageIO . read ( ( URL ) imageDescriptor ) ; } else { throw new RuntimeException ( "<STR_LIT>" + imageDescriptor . getClass ( ) . getName ( ) ) ; } } catch ( Exception e ) { System . out . println ( "<STR_LIT>" + imageDescriptor + "<STR_LIT::>" ) ; e . printStackTrace ( ) ; return null ; } finally { fireProgressEnd ( new ProgressEvent ( BasicFetcher . this , imageDescriptor , clientIdentifier , <NUM_LIT:1.0f> , true ) ) ; } } } ) ; activeTasks . put ( key , task ) ; threadPool . execute ( task ) ; return null ; } public void cancelDownload ( Object imageDescriptor , IDENT clientIdentifier , int requestedImageSize ) { } public synchronized void addProgressListener ( ProgressListener listener ) { ArrayList < ProgressListener > newListeners = ( ArrayList < ProgressListener > ) listeners . clone ( ) ; newListeners . add ( listener ) ; listeners = newListeners ; } public synchronized void removeProgressListener ( ProgressListener listener ) { ArrayList < ProgressListener > newListeners = ( ArrayList < ProgressListener > ) listeners . clone ( ) ; newListeners . remove ( listener ) ; listeners = newListeners ; } class FetchKey { private Object imageDescriptor ; private IDENT clientIdentifier ; private int requestedImageSize ; public FetchKey ( Object imageDescriptor , IDENT clientIdentifier , int requestedImageSize ) { this . imageDescriptor = imageDescriptor ; this . clientIdentifier = clientIdentifier ; this . requestedImageSize = requestedImageSize ; } public Object getImageDescriptor ( ) { return imageDescriptor ; } public IDENT getClientIdentifier ( ) { return clientIdentifier ; } public int getRequestedImageSize ( ) { return requestedImageSize ; } public boolean equals ( Object o ) { if ( this == o ) return true ; if ( o == null ) return false ; if ( getClass ( ) != o . getClass ( ) ) return false ; FetchKey other = ( FetchKey ) o ; return ( requestedImageSize == other . requestedImageSize && imageDescriptor . equals ( other . imageDescriptor ) && clientIdentifier . equals ( other . clientIdentifier ) ) ; } public int hashCode ( ) { int result ; result = clientIdentifier . hashCode ( ) ; result = <NUM_LIT> * result + imageDescriptor . hashCode ( ) ; result = <NUM_LIT> * result + requestedImageSize ; return result ; } } private synchronized void fireProgressStart ( final ProgressEvent e ) { List < ProgressListener > curListeners = listeners ; for ( ProgressListener listener : curListeners ) { final ProgressListener finalListener = listener ; invokeLaterOnEDT ( new Runnable ( ) { public void run ( ) { finalListener . progressStart ( e ) ; } } ) ; } } private synchronized void fireProgressUpdate ( final ProgressEvent e ) { List < ProgressListener > curListeners = listeners ; for ( ProgressListener listener : curListeners ) { final ProgressListener finalListener = listener ; invokeLaterOnEDT ( new Runnable ( ) { public void run ( ) { finalListener . progressUpdate ( e ) ; } } ) ; } } private synchronized void fireProgressEnd ( final ProgressEvent e ) { List < ProgressListener > curListeners = listeners ; for ( ProgressListener listener : curListeners ) { final ProgressListener finalListener = listener ; invokeLaterOnEDT ( new Runnable ( ) { public void run ( ) { finalListener . progressEnd ( e ) ; } } ) ; } } private void invokeLaterOnEDT ( Runnable runnable ) { if ( EventQueue . isDispatchThread ( ) ) { runnable . run ( ) ; } else { EventQueue . invokeLater ( runnable ) ; } } } </s>
<s> package net . java . joglutils . msg . test ; import java . awt . image . * ; public interface Fetcher < IDENT > { public BufferedImage getImage ( Object imageDescriptor , IDENT clientIdentifier , int requestedImageSize ) ; public void cancelDownload ( Object imageDescriptor , IDENT clientIdentifier , int requestedImageSize ) ; public void addProgressListener ( ProgressListener listener ) ; public void removeProgressListener ( ProgressListener listener ) ; } </s>
<s> package net . java . joglutils . msg . test ; import java . util . EventObject ; public class ProgressEvent < IDENT > extends EventObject { private Object imageDescriptor ; private IDENT clientIdentifier ; private float fractionCompleted ; private boolean isDownload ; public ProgressEvent ( Fetcher < IDENT > source , Object imageDescriptor , IDENT clientIdentifier , float fractionCompleted , boolean isDownload ) { super ( source ) ; this . imageDescriptor = imageDescriptor ; this . clientIdentifier = clientIdentifier ; this . fractionCompleted = fractionCompleted ; this . isDownload = isDownload ; } public Object getImageDescriptor ( ) { return imageDescriptor ; } public IDENT getClientIdentifier ( ) { return clientIdentifier ; } public float getFractionCompleted ( ) { return fractionCompleted ; } public boolean isDownload ( ) { return isDownload ; } } </s>
<s> package net . java . joglutils . msg . nodes ; import net . java . joglutils . msg . actions . * ; public class Node { public void doAction ( Action action ) { } public void render ( GLRenderAction action ) { doAction ( action ) ; } public void rayPick ( RayPickAction action ) { doAction ( action ) ; } } </s>
<s> package net . java . joglutils . msg . nodes ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . elements . * ; import net . java . joglutils . msg . math . * ; public abstract class Camera extends Node { private Vec3f position ; private Rotf orientation ; private float aspectRatio = <NUM_LIT:1.0f> ; private float nearDistance = <NUM_LIT:1.0f> ; private float farDistance = <NUM_LIT> ; private float focalDistance = <NUM_LIT> ; protected boolean projDirty ; protected boolean viewDirty ; protected Mat4f projMatrix ; protected Mat4f viewMatrix ; static { GLModelMatrixElement . enable ( GLRenderAction . getDefaultState ( ) ) ; GLProjectionMatrixElement . enable ( GLRenderAction . getDefaultState ( ) ) ; GLViewingMatrixElement . enable ( GLRenderAction . getDefaultState ( ) ) ; ModelMatrixElement . enable ( RayPickAction . getDefaultState ( ) ) ; ProjectionMatrixElement . enable ( RayPickAction . getDefaultState ( ) ) ; ViewingMatrixElement . enable ( RayPickAction . getDefaultState ( ) ) ; } public Camera ( ) { position = new Vec3f ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) ; orientation = new Rotf ( ) ; projMatrix = new Mat4f ( ) ; viewMatrix = new Mat4f ( ) ; projDirty = true ; viewDirty = true ; } public void setPosition ( Vec3f position ) { this . position . set ( position ) ; viewDirty = true ; } public Vec3f getPosition ( ) { return position ; } public void setOrientation ( Rotf orientation ) { this . orientation . set ( orientation ) ; viewDirty = true ; } public Rotf getOrientation ( ) { return orientation ; } public void setAspectRatio ( float aspectRatio ) { if ( aspectRatio == this . aspectRatio ) return ; this . aspectRatio = aspectRatio ; projDirty = true ; } public float getAspectRatio ( ) { return aspectRatio ; } public void setNearDistance ( float nearDistance ) { this . nearDistance = nearDistance ; projDirty = true ; } public float getNearDistance ( ) { return nearDistance ; } public void setFarDistance ( float farDistance ) { this . farDistance = farDistance ; projDirty = true ; } public float getFarDistance ( ) { return farDistance ; } public void setFocalDistance ( float focalDistance ) { this . focalDistance = focalDistance ; projDirty = true ; } public float getFocalDistance ( ) { return focalDistance ; } public Mat4f getViewingMatrix ( ) { if ( viewDirty ) { viewMatrix . makeIdent ( ) ; viewDirty = false ; viewMatrix . setRotation ( getOrientation ( ) ) ; viewMatrix . setTranslation ( getPosition ( ) ) ; viewMatrix . invertRigid ( ) ; } return viewMatrix ; } public abstract Mat4f getProjectionMatrix ( ) ; public Line unproject ( Vec2f point ) { Line line = new Line ( ) ; unproject ( point , line ) ; return line ; } public void unproject ( Vec2f point , Line line ) throws SingularMatrixException { Vec4f pt3d = new Vec4f ( <NUM_LIT:2> * point . x ( ) - <NUM_LIT:1> , <NUM_LIT:2> * point . y ( ) - <NUM_LIT:1> , - getNearDistance ( ) , <NUM_LIT:1> ) ; Mat4f mat = new Mat4f ( ) ; mat . mul ( getProjectionMatrix ( ) , getViewingMatrix ( ) ) ; mat . invert ( ) ; Vec4f unproj = new Vec4f ( ) ; mat . xformVec ( pt3d , unproj ) ; if ( unproj . w ( ) == <NUM_LIT:0> ) { throw new SingularMatrixException ( ) ; } float ooW = <NUM_LIT:1.0f> / unproj . w ( ) ; Vec3f to = new Vec3f ( unproj . x ( ) * ooW , unproj . y ( ) * ooW , unproj . z ( ) * ooW ) ; Vec3f from = getRayStartPoint ( point , to ) ; Vec3f dir = to . minus ( from ) ; line . setPoint ( from ) ; line . setDirection ( dir ) ; } protected abstract Vec3f getRayStartPoint ( Vec2f point , Vec3f unprojectedPoint ) ; public void doAction ( Action action ) { if ( ViewingMatrixElement . isEnabled ( action . getState ( ) ) ) { ViewingMatrixElement . set ( action . getState ( ) , getViewingMatrix ( ) ) ; } if ( ProjectionMatrixElement . isEnabled ( action . getState ( ) ) ) { ProjectionMatrixElement . set ( action . getState ( ) , getProjectionMatrix ( ) ) ; } } public void rayPick ( RayPickAction action ) { doAction ( action ) ; action . recomputeRay ( this ) ; } } </s>
<s> package net . java . joglutils . msg . nodes ; import java . awt . image . * ; import java . io . * ; import java . net . * ; import java . util . * ; import javax . media . opengl . * ; import com . sun . opengl . util . awt . * ; import com . sun . opengl . util . texture . * ; import com . sun . opengl . util . texture . awt . * ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . elements . * ; public class Texture2 extends Node { private TextureData data ; private Texture texture ; private int texEnvMode = MODULATE ; private boolean dirty ; private TextureData subImageData ; private int subImageMipmapLevel ; private int subImageDstX ; private int subImageDstY ; private int subImageSrcX ; private int subImageSrcY ; private int subImageWidth ; private int subImageHeight ; private boolean subImageDirty ; private TextureRenderer textureRenderer ; private List < Texture > disposedTextures = new ArrayList < Texture > ( ) ; private List < TextureRenderer > disposedRenderers = new ArrayList < TextureRenderer > ( ) ; static { GLTextureElement . enable ( GLRenderAction . getDefaultState ( ) ) ; TextureElement . enable ( RayPickAction . getDefaultState ( ) ) ; } public static final int MODULATE = <NUM_LIT:1> ; public static final int DECAL = <NUM_LIT:2> ; public static final int BLEND = <NUM_LIT:3> ; public static final int REPLACE = <NUM_LIT:4> ; public void setTexture ( File file , boolean mipmap , String fileSuffix ) throws IOException { disposeTextureRenderer ( ) ; data = TextureIO . newTextureData ( file , mipmap , fileSuffix ) ; dirty = true ; } public void setTexture ( InputStream stream , boolean mipmap , String fileSuffix ) throws IOException { disposeTextureRenderer ( ) ; data = TextureIO . newTextureData ( stream , mipmap , fileSuffix ) ; dirty = true ; } public void setTexture ( URL url , boolean mipmap , String fileSuffix ) throws IOException { disposeTextureRenderer ( ) ; data = TextureIO . newTextureData ( url , mipmap , fileSuffix ) ; dirty = true ; } public void setTexture ( BufferedImage image , boolean mipmap ) { disposeTextureRenderer ( ) ; data = AWTTextureIO . newTextureData ( image , mipmap ) ; dirty = true ; } public void setTexture ( TextureData data ) { disposeTextureRenderer ( ) ; this . data = data ; dirty = true ; } public int getWidth ( ) { if ( data != null ) { return data . getWidth ( ) ; } if ( texture != null ) { return texture . getWidth ( ) ; } if ( textureRenderer != null ) { return textureRenderer . getWidth ( ) ; } return <NUM_LIT:0> ; } public int getHeight ( ) { if ( data != null ) { return data . getHeight ( ) ; } if ( texture != null ) { return texture . getHeight ( ) ; } if ( textureRenderer != null ) { return textureRenderer . getHeight ( ) ; } return <NUM_LIT:0> ; } public void updateSubImage ( TextureData data , int mipmapLevel , int dstx , int dsty , int srcx , int srcy , int width , int height ) { if ( textureRenderer != null ) { throw new IllegalStateException ( "<STR_LIT>" ) ; } subImageData = data ; subImageMipmapLevel = mipmapLevel ; subImageDstX = dstx ; subImageDstY = dsty ; subImageSrcX = srcx ; subImageSrcY = srcy ; subImageWidth = width ; subImageHeight = height ; subImageDirty = true ; } public void initTextureRenderer ( int width , int height , boolean alpha ) { disposeTexture ( ) ; textureRenderer = new TextureRenderer ( width , height , alpha ) ; } public TextureRenderer getTextureRenderer ( ) { return textureRenderer ; } public Texture getTexture ( ) throws GLException { lazyDispose ( ) ; if ( textureRenderer != null ) { return textureRenderer . getTexture ( ) ; } if ( dirty ) { if ( texture != null ) { texture . dispose ( ) ; texture = null ; } texture = TextureIO . newTexture ( data ) ; data = null ; dirty = false ; } if ( subImageDirty ) { texture . updateSubImage ( subImageData , subImageMipmapLevel , subImageDstX , subImageDstY , subImageSrcX , subImageSrcY , subImageWidth , subImageHeight ) ; subImageDirty = false ; } return texture ; } public void setTexEnvMode ( int mode ) { if ( mode < MODULATE || mode > REPLACE ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } this . texEnvMode = mode ; } public int getTexEnvMode ( ) { return texEnvMode ; } public void doAction ( Action action ) { if ( TextureElement . isEnabled ( action . getState ( ) ) ) { TextureElement . set ( action . getState ( ) , this ) ; } } public void dispose ( ) throws GLException { disposeTexture ( ) ; disposeTextureRenderer ( ) ; lazyDispose ( ) ; data = null ; subImageData = null ; dirty = false ; subImageDirty = false ; } public void resetGL ( GLResetAction action ) { disposeTexture ( ) ; disposeTextureRenderer ( ) ; synchronized ( this ) { disposedTextures . clear ( ) ; disposedRenderers . clear ( ) ; } data = null ; subImageData = null ; dirty = false ; subImageDirty = false ; } private synchronized void disposeTextureRenderer ( ) { if ( textureRenderer != null ) { disposedRenderers . add ( textureRenderer ) ; textureRenderer = null ; } } private synchronized void disposeTexture ( ) { if ( texture != null ) { disposedTextures . add ( texture ) ; texture = null ; data = null ; subImageData = null ; dirty = false ; subImageDirty = false ; } } private void lazyDispose ( ) { while ( ! disposedTextures . isEmpty ( ) ) { Texture t = null ; synchronized ( this ) { t = disposedTextures . remove ( disposedTextures . size ( ) - <NUM_LIT:1> ) ; } t . dispose ( ) ; } while ( ! disposedRenderers . isEmpty ( ) ) { TextureRenderer r = null ; synchronized ( this ) { r = disposedRenderers . remove ( disposedRenderers . size ( ) - <NUM_LIT:1> ) ; } r . dispose ( ) ; } } } </s>
<s> package net . java . joglutils . msg . nodes ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . math . * ; public class PerspectiveCamera extends Camera { private static final float DEFAULT_HEIGHT_ANGLE = ( float ) ( Math . PI / <NUM_LIT:4> ) ; private float vertFOVScale = <NUM_LIT:1.0f> ; public Mat4f getProjectionMatrix ( ) { if ( projDirty ) { projMatrix . makeIdent ( ) ; projDirty = false ; float zNear = getNearDistance ( ) ; float zFar = getFarDistance ( ) ; float deltaZ = zFar - zNear ; float aspect = getAspectRatio ( ) ; float radians = vertFOVScale * DEFAULT_HEIGHT_ANGLE ; float sine = ( float ) Math . sin ( radians ) ; if ( ( deltaZ == <NUM_LIT:0> ) || ( sine == <NUM_LIT:0> ) || ( aspect == <NUM_LIT:0> ) ) { return projMatrix ; } float cotangent = ( float ) Math . cos ( radians ) / sine ; projMatrix . set ( <NUM_LIT:0> , <NUM_LIT:0> , cotangent / aspect ) ; projMatrix . set ( <NUM_LIT:1> , <NUM_LIT:1> , cotangent ) ; projMatrix . set ( <NUM_LIT:2> , <NUM_LIT:2> , - ( zFar + zNear ) / deltaZ ) ; projMatrix . set ( <NUM_LIT:3> , <NUM_LIT:2> , - <NUM_LIT:1> ) ; projMatrix . set ( <NUM_LIT:2> , <NUM_LIT:3> , - <NUM_LIT:2> * zNear * zFar / deltaZ ) ; projMatrix . set ( <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:0> ) ; } return projMatrix ; } public void setHeightAngle ( float heightAngle ) { vertFOVScale = heightAngle / DEFAULT_HEIGHT_ANGLE ; projDirty = true ; } public float getHeightAngle ( ) { return vertFOVScale * DEFAULT_HEIGHT_ANGLE ; } public float getWidthAngle ( float aspectRatio ) { return ( float ) Math . atan ( aspectRatio * Math . tan ( getHeightAngle ( ) ) ) ; } public float getWidthAngle ( ) { return getWidthAngle ( getAspectRatio ( ) ) ; } protected Vec3f getRayStartPoint ( Vec2f point , Vec3f unprojectedPoint ) { return getPosition ( ) ; } public void render ( GLRenderAction action ) { setAspectRatio ( action . getCurAspectRatio ( ) ) ; doAction ( action ) ; } } </s>
<s> package net . java . joglutils . msg . nodes ; public abstract class Shape extends Node { } </s>
<s> package net . java . joglutils . msg . nodes ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . elements . * ; import net . java . joglutils . msg . collections . * ; public class Coordinate3 extends Node { private Vec3fCollection data ; static { GLCoordinateElement . enable ( GLRenderAction . getDefaultState ( ) ) ; CoordinateElement . enable ( RayPickAction . getDefaultState ( ) ) ; } public void setData ( Vec3fCollection data ) { this . data = data ; } public Vec3fCollection getData ( ) { return data ; } public void doAction ( Action action ) { if ( CoordinateElement . isEnabled ( action . getState ( ) ) ) { CoordinateElement . set ( action . getState ( ) , getData ( ) . getData ( ) ) ; } } } </s>
<s> package net . java . joglutils . msg . nodes ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . misc . * ; public class Separator extends Group { public void doAction ( Action action ) { State state = action . getState ( ) ; state . push ( ) ; try { super . doAction ( action ) ; } finally { state . pop ( ) ; } } } </s>
<s> package net . java . joglutils . msg . nodes ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . math . * ; public class OrthographicCamera extends Camera { private static final float DEFAULT_HEIGHT = <NUM_LIT> ; private float heightScale = <NUM_LIT:1.0f> ; public Mat4f getProjectionMatrix ( ) { if ( projDirty ) { projMatrix . makeIdent ( ) ; projDirty = false ; float zNear = getNearDistance ( ) ; float zFar = getFarDistance ( ) ; float deltaZ = zFar - zNear ; float aspect = getAspectRatio ( ) ; float height = heightScale * DEFAULT_HEIGHT ; float width = height * aspect ; if ( ( height == <NUM_LIT:0> ) || ( width == <NUM_LIT:0> ) || ( deltaZ == <NUM_LIT:0> ) ) return projMatrix ; projMatrix . set ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> / width ) ; projMatrix . set ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT> / height ) ; projMatrix . set ( <NUM_LIT:2> , <NUM_LIT:2> , - <NUM_LIT> / deltaZ ) ; projMatrix . set ( <NUM_LIT:2> , <NUM_LIT:3> , - ( zFar + zNear ) / deltaZ ) ; } return projMatrix ; } public void setHeight ( float height ) { heightScale = height / DEFAULT_HEIGHT ; } public float getHeight ( ) { return heightScale * DEFAULT_HEIGHT ; } public float getWidth ( float aspectRatio ) { return getHeight ( ) * aspectRatio ; } public float getWidth ( ) { return getWidth ( getAspectRatio ( ) ) ; } protected Vec3f getRayStartPoint ( Vec2f point , Vec3f unprojectedPoint ) { Vec3f backward = Vec3f . Z_AXIS . times ( getNearDistance ( ) ) ; backward = getOrientation ( ) . rotateVector ( backward ) ; return unprojectedPoint . plus ( backward ) ; } public void render ( GLRenderAction action ) { setAspectRatio ( action . getCurAspectRatio ( ) ) ; doAction ( action ) ; } } </s>
<s> package net . java . joglutils . msg . nodes ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . elements . * ; import net . java . joglutils . msg . collections . * ; public class Color4 extends Node { private Vec4fCollection data ; static { GLColorElement . enable ( GLRenderAction . getDefaultState ( ) ) ; } public void setData ( Vec4fCollection data ) { this . data = data ; } public Vec4fCollection getData ( ) { return data ; } public void doAction ( Action action ) { if ( ColorElement . isEnabled ( action . getState ( ) ) ) { ColorElement . set ( action . getState ( ) , getData ( ) . getData ( ) ) ; } } } </s>
<s> package net . java . joglutils . msg . nodes ; import javax . media . opengl . * ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . elements . * ; public class DepthTest extends Node { private boolean enabled = true ; static { GLDepthTestElement . enable ( GLRenderAction . getDefaultState ( ) ) ; } public void setEnabled ( boolean enabled ) { this . enabled = enabled ; } public boolean getEnabled ( ) { return enabled ; } public void doAction ( Action action ) { if ( DepthTestElement . isEnabled ( action . getState ( ) ) ) { DepthTestElement . set ( action . getState ( ) , getEnabled ( ) ) ; } } } </s>
<s> package net . java . joglutils . msg . nodes ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . elements . * ; import net . java . joglutils . msg . math . * ; public class Transform extends Node { private Mat4f transform ; static { GLModelMatrixElement . enable ( GLRenderAction . getDefaultState ( ) ) ; GLProjectionMatrixElement . enable ( GLRenderAction . getDefaultState ( ) ) ; GLViewingMatrixElement . enable ( GLRenderAction . getDefaultState ( ) ) ; ModelMatrixElement . enable ( RayPickAction . getDefaultState ( ) ) ; ProjectionMatrixElement . enable ( RayPickAction . getDefaultState ( ) ) ; ViewingMatrixElement . enable ( RayPickAction . getDefaultState ( ) ) ; } public Transform ( ) { transform = new Mat4f ( ) ; transform . makeIdent ( ) ; } public void setTransform ( Mat4f transform ) { this . transform . set ( transform ) ; } public Mat4f getTransform ( ) { return transform ; } public void doAction ( Action action ) { if ( ModelMatrixElement . isEnabled ( action . getState ( ) ) ) { ModelMatrixElement . mult ( action . getState ( ) , getTransform ( ) ) ; } } } </s>
<s> package net . java . joglutils . msg . nodes ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . collections . * ; import net . java . joglutils . msg . elements . * ; public class TextureCoordinate2 extends Node { private Vec2fCollection data ; static { GLTextureCoordinateElement . enable ( GLRenderAction . getDefaultState ( ) ) ; TextureCoordinateElement . enable ( RayPickAction . getDefaultState ( ) ) ; } public void setData ( Vec2fCollection data ) { this . data = data ; } public Vec2fCollection getData ( ) { return data ; } public void doAction ( Action action ) { if ( TextureCoordinateElement . isEnabled ( action . getState ( ) ) ) { TextureCoordinateElement . set ( action . getState ( ) , getData ( ) . getData ( ) ) ; } } } </s>
<s> package net . java . joglutils . msg . nodes ; import java . util . * ; import net . java . joglutils . msg . actions . * ; public class Group extends Node implements Iterable < Node > { private List < Node > children = new ArrayList < Node > ( ) ; public void addChild ( Node child ) { if ( child == null ) throw new IllegalArgumentException ( "<STR_LIT>" ) ; children . add ( child ) ; } public void insertChild ( int index , Node child ) { if ( child == null ) throw new IllegalArgumentException ( "<STR_LIT>" ) ; children . add ( index , child ) ; } public Node getChild ( int index ) { return children . get ( index ) ; } public int findChild ( Node node ) { return children . indexOf ( node ) ; } public int getNumChildren ( ) { return children . size ( ) ; } public void removeChild ( int index ) throws IndexOutOfBoundsException { children . remove ( index ) ; } public void removeChild ( Node node ) { int idx = findChild ( node ) ; if ( idx >= <NUM_LIT:0> ) removeChild ( idx ) ; } public void removeAllChildren ( ) { children . clear ( ) ; } public void replaceChild ( int index , Node newChild ) throws IndexOutOfBoundsException { if ( newChild == null ) throw new IllegalArgumentException ( "<STR_LIT>" ) ; removeChild ( index ) ; insertChild ( index , newChild ) ; } public void replaceChild ( Node oldChild , Node newChild ) { if ( newChild == null ) throw new IllegalArgumentException ( "<STR_LIT>" ) ; int idx = findChild ( oldChild ) ; if ( idx >= <NUM_LIT:0> ) replaceChild ( idx , newChild ) ; } public Iterator < Node > iterator ( ) { return children . iterator ( ) ; } public void doAction ( Action action ) { for ( int i = <NUM_LIT:0> ; i < getNumChildren ( ) ; i ++ ) { action . apply ( getChild ( i ) ) ; } } } </s>
<s> package net . java . joglutils . msg . nodes ; import java . nio . * ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . misc . * ; public class IndexedTriangleSet extends TriangleBasedShape { private IntBuffer indices ; public void setIndices ( IntBuffer indices ) { this . indices = indices ; } public IntBuffer getIndices ( ) { return indices ; } public void doAction ( Action action ) { throw new RuntimeException ( "<STR_LIT>" ) ; } public void generateTriangles ( Action action , TriangleCallback cb ) { throw new RuntimeException ( "<STR_LIT>" ) ; } } </s>
<s> package net . java . joglutils . msg . nodes ; import java . awt . image . * ; import java . io . * ; import java . net . * ; import java . util . * ; import javax . media . opengl . * ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . elements . * ; import net . java . joglutils . msg . math . * ; import net . java . joglutils . msg . misc . * ; public class ShaderNode extends Node { private String vertexShaderCode ; private String fragmentShaderCode ; private Shader shader ; private List < Shader > disposedShaders = new ArrayList < Shader > ( ) ; private Map < String , Params > paramMap = new HashMap < String , Params > ( ) ; static { GLShaderElement . enable ( GLRenderAction . getDefaultState ( ) ) ; } public void setShader ( String fragmentShaderCode ) { disposeShader ( ) ; this . vertexShaderCode = null ; this . fragmentShaderCode = fragmentShaderCode ; } public void setShader ( String vertexShaderCode , String fragmentShaderCode ) { disposeShader ( ) ; this . vertexShaderCode = vertexShaderCode ; this . fragmentShaderCode = fragmentShaderCode ; } public void setUniform ( String name , int i0 ) { int [ ] iArr = new int [ ] { i0 } ; paramMap . put ( name , new Params ( iArr , <NUM_LIT:1> ) ) ; } public void setUniform ( String name , int i0 , int i1 ) { int [ ] iArr = new int [ ] { i0 , i1 } ; paramMap . put ( name , new Params ( iArr , <NUM_LIT:2> ) ) ; } public void setUniform ( String name , int i0 , int i1 , int i2 ) { int [ ] iArr = new int [ ] { i0 , i1 , i2 } ; paramMap . put ( name , new Params ( iArr , <NUM_LIT:3> ) ) ; } public void setUniform ( String name , int i0 , int i1 , int i2 , int i3 ) { int [ ] iArr = new int [ ] { i0 , i1 , i2 , i3 } ; paramMap . put ( name , new Params ( iArr , <NUM_LIT:4> ) ) ; } public void setUniform ( String name , float f0 ) { float [ ] fArr = new float [ ] { f0 } ; paramMap . put ( name , new Params ( fArr , <NUM_LIT:1> ) ) ; } public void setUniform ( String name , float f0 , float f1 ) { float [ ] fArr = new float [ ] { f0 , f1 } ; paramMap . put ( name , new Params ( fArr , <NUM_LIT:2> ) ) ; } public void setUniform ( String name , float f0 , float f1 , float f2 ) { float [ ] fArr = new float [ ] { f0 , f1 , f2 } ; paramMap . put ( name , new Params ( fArr , <NUM_LIT:3> ) ) ; } public void setUniform ( String name , float f0 , float f1 , float f2 , float f3 ) { float [ ] fArr = new float [ ] { f0 , f1 , f2 , f3 } ; paramMap . put ( name , new Params ( fArr , <NUM_LIT:4> ) ) ; } public void setUniformArray1i ( String name , int count , int [ ] vals , int off ) { paramMap . put ( name , new Params ( vals , <NUM_LIT:1> , count , off ) ) ; } public void setUniformArray2i ( String name , int count , int [ ] vals , int off ) { paramMap . put ( name , new Params ( vals , <NUM_LIT:2> , count , off ) ) ; } public void setUniformArray3i ( String name , int count , int [ ] vals , int off ) { paramMap . put ( name , new Params ( vals , <NUM_LIT:3> , count , off ) ) ; } public void setUniformArray4i ( String name , int count , int [ ] vals , int off ) { paramMap . put ( name , new Params ( vals , <NUM_LIT:4> , count , off ) ) ; } public void setUniformArray1f ( String name , int count , float [ ] vals , int off ) { paramMap . put ( name , new Params ( vals , <NUM_LIT:1> , count , off ) ) ; } public void setUniformArray2f ( String name , int count , float [ ] vals , int off ) { paramMap . put ( name , new Params ( vals , <NUM_LIT:2> , count , off ) ) ; } public void setUniformArray3f ( String name , int count , float [ ] vals , int off ) { paramMap . put ( name , new Params ( vals , <NUM_LIT:3> , count , off ) ) ; } public void setUniformArray4f ( String name , int count , float [ ] vals , int off ) { paramMap . put ( name , new Params ( vals , <NUM_LIT:4> , count , off ) ) ; } public void setUniformMatrices2f ( String name , int count , boolean transpose , float [ ] vals , int off ) { paramMap . put ( name , new Params ( vals , <NUM_LIT:2> , count , off , true , transpose ) ) ; } public void setUniformMatrices3f ( String name , int count , boolean transpose , float [ ] vals , int off ) { paramMap . put ( name , new Params ( vals , <NUM_LIT:3> , count , off , true , transpose ) ) ; } public void setUniformMatrices4f ( String name , int count , boolean transpose , float [ ] vals , int off ) { paramMap . put ( name , new Params ( vals , <NUM_LIT:4> , count , off , true , transpose ) ) ; } public Shader getShader ( ) throws GLException { lazyDispose ( ) ; if ( shader == null ) { this . shader = new Shader ( vertexShaderCode , fragmentShaderCode ) ; } sendParams ( ) ; return shader ; } public void doAction ( Action action ) { if ( ShaderElement . isEnabled ( action . getState ( ) ) ) { ShaderElement . set ( action . getState ( ) , this ) ; } } public void resetGL ( GLResetAction action ) { disposeShader ( ) ; synchronized ( this ) { disposedShaders . clear ( ) ; } } private synchronized void disposeShader ( ) { if ( shader != null ) { disposedShaders . add ( shader ) ; shader = null ; } } private void lazyDispose ( ) { while ( ! disposedShaders . isEmpty ( ) ) { Shader s = null ; synchronized ( this ) { s = disposedShaders . remove ( disposedShaders . size ( ) - <NUM_LIT:1> ) ; } s . dispose ( ) ; } } private void sendParams ( ) { if ( ! paramMap . isEmpty ( ) ) { shader . enable ( ) ; for ( String name : paramMap . keySet ( ) ) { Params params = paramMap . get ( name ) ; if ( params . isMatrix ) { switch ( params . vecSize ) { case <NUM_LIT:2> : shader . setUniformMatrices2f ( name , params . numElems , params . transpose , params . fArr , params . offset ) ; break ; case <NUM_LIT:3> : shader . setUniformMatrices3f ( name , params . numElems , params . transpose , params . fArr , params . offset ) ; break ; case <NUM_LIT:4> : shader . setUniformMatrices4f ( name , params . numElems , params . transpose , params . fArr , params . offset ) ; break ; default : continue ; } } else if ( params . fArr != null ) { switch ( params . vecSize ) { case <NUM_LIT:1> : shader . setUniformArray1f ( name , params . numElems , params . fArr , params . offset ) ; break ; case <NUM_LIT:2> : shader . setUniformArray2f ( name , params . numElems , params . fArr , params . offset ) ; break ; case <NUM_LIT:3> : shader . setUniformArray3f ( name , params . numElems , params . fArr , params . offset ) ; break ; case <NUM_LIT:4> : shader . setUniformArray4f ( name , params . numElems , params . fArr , params . offset ) ; break ; default : continue ; } } else if ( params . iArr != null ) { switch ( params . vecSize ) { case <NUM_LIT:1> : shader . setUniformArray1i ( name , params . numElems , params . iArr , params . offset ) ; break ; case <NUM_LIT:2> : shader . setUniformArray2i ( name , params . numElems , params . iArr , params . offset ) ; break ; case <NUM_LIT:3> : shader . setUniformArray3i ( name , params . numElems , params . iArr , params . offset ) ; break ; case <NUM_LIT:4> : shader . setUniformArray4i ( name , params . numElems , params . iArr , params . offset ) ; break ; default : continue ; } } } shader . disable ( ) ; paramMap . clear ( ) ; } } private static class Params { private float [ ] fArr ; private int [ ] iArr ; private int vecSize ; private int numElems ; private int offset ; private boolean isMatrix ; private boolean transpose ; Params ( float [ ] fArr , int vecSize ) { this ( fArr , vecSize , <NUM_LIT:1> , <NUM_LIT:0> ) ; } Params ( float [ ] fArr , int vecSize , int numElems , int offset ) { this ( fArr , vecSize , numElems , offset , false , false ) ; } Params ( float [ ] fArr , int vecSize , int numElems , int offset , boolean isMatrix , boolean transpose ) { this . fArr = fArr ; this . vecSize = vecSize ; this . numElems = numElems ; this . offset = offset ; this . isMatrix = isMatrix ; this . transpose = transpose ; } Params ( int [ ] iArr , int vecSize ) { this ( iArr , vecSize , <NUM_LIT:1> , <NUM_LIT:0> ) ; } Params ( int [ ] iArr , int vecSize , int numElems , int offset ) { this . iArr = iArr ; this . vecSize = vecSize ; this . numElems = numElems ; this . offset = offset ; this . isMatrix = false ; this . transpose = false ; } } } </s>
<s> package net . java . joglutils . msg . nodes ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . elements . * ; import net . java . joglutils . msg . math . * ; public class Blend extends Node { private boolean enabled ; private Vec4f blendColor = new Vec4f ( ) ; private int srcFunc = ONE ; private int destFunc = ZERO ; private int blendEquation = FUNC_ADD ; static { GLBlendElement . enable ( GLRenderAction . getDefaultState ( ) ) ; } public static final int ZERO = <NUM_LIT:1> ; public static final int ONE = <NUM_LIT:2> ; public static final int SRC_COLOR = <NUM_LIT:3> ; public static final int ONE_MINUS_SRC_COLOR = <NUM_LIT:4> ; public static final int DST_COLOR = <NUM_LIT:5> ; public static final int ONE_MINUS_DST_COLOR = <NUM_LIT:6> ; public static final int SRC_ALPHA = <NUM_LIT:7> ; public static final int ONE_MINUS_SRC_ALPHA = <NUM_LIT:8> ; public static final int DST_ALPHA = <NUM_LIT:9> ; public static final int ONE_MINUS_DST_ALPHA = <NUM_LIT:10> ; public static final int SRC_ALPHA_SATURATE = <NUM_LIT:11> ; public static final int CONSTANT_COLOR = <NUM_LIT:12> ; public static final int ONE_MINUS_CONSTANT_COLOR = <NUM_LIT> ; public static final int CONSTANT_ALPHA = <NUM_LIT> ; public static final int ONE_MINUS_CONSTANT_ALPHA = <NUM_LIT:15> ; public static final int FUNC_ADD = <NUM_LIT:1> ; public static final int FUNC_SUBTRACT = <NUM_LIT:2> ; public static final int FUNC_REVERSE_SUBTRACT = <NUM_LIT:3> ; public static final int MIN = <NUM_LIT:4> ; public static final int MAX = <NUM_LIT:5> ; public void setEnabled ( boolean enabled ) { this . enabled = enabled ; } public boolean getEnabled ( ) { return enabled ; } public void setSourceFunc ( int func ) { if ( func < ZERO || func > ONE_MINUS_CONSTANT_ALPHA ) { throw new IllegalArgumentException ( "<STR_LIT>" + func ) ; } srcFunc = func ; } public int getSourceFunc ( ) { return srcFunc ; } public void setDestFunc ( int func ) { if ( func < ZERO || func > ONE_MINUS_CONSTANT_ALPHA ) { throw new IllegalArgumentException ( "<STR_LIT>" + func ) ; } destFunc = func ; } public int getDestFunc ( ) { return destFunc ; } public void setBlendEquation ( int equation ) { if ( equation < FUNC_ADD || equation > MAX ) { throw new IllegalArgumentException ( "<STR_LIT>" + equation ) ; } this . blendEquation = equation ; } public int getBlendEquation ( ) { return blendEquation ; } public void setBlendColor ( Vec4f color ) { blendColor . set ( color ) ; } public Vec4f getBlendColor ( ) { return blendColor ; } public void doAction ( Action action ) { if ( BlendElement . isEnabled ( action . getState ( ) ) ) { BlendElement . set ( action . getState ( ) , getEnabled ( ) , getBlendColor ( ) , getSourceFunc ( ) , getDestFunc ( ) , getBlendEquation ( ) ) ; } } } </s>
<s> package net . java . joglutils . msg . nodes ; import java . nio . * ; import java . util . * ; import javax . media . opengl . * ; import com . sun . opengl . util . texture . * ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . elements . * ; import net . java . joglutils . msg . math . * ; import net . java . joglutils . msg . misc . * ; public class TriangleSet extends TriangleBasedShape { private int numTriangles ; public void setNumTriangles ( int numTriangles ) { this . numTriangles = numTriangles ; } public int getNumTriangles ( ) { return numTriangles ; } public void render ( GLRenderAction action ) { State state = action . getState ( ) ; if ( ! CoordinateElement . isEnabled ( state ) ) return ; if ( CoordinateElement . get ( state ) != null ) { GL2 gl = action . getGL ( ) ; Texture tex = null ; boolean haveTexCoords = false ; if ( GLTextureElement . isEnabled ( state ) && GLTextureCoordinateElement . isEnabled ( state ) ) { Texture2 texNode = GLTextureElement . get ( state ) ; if ( texNode != null ) { tex = texNode . getTexture ( ) ; } haveTexCoords = ( GLTextureCoordinateElement . get ( state ) != null ) ; } if ( tex != null ) { gl . glMatrixMode ( GL2 . GL_TEXTURE ) ; gl . glPushMatrix ( ) ; if ( gl . isExtensionAvailable ( "<STR_LIT>" ) ) { gl . glLoadTransposeMatrixf ( getTextureMatrix ( tex ) . getRowMajorData ( ) , <NUM_LIT:0> ) ; } else { float [ ] tmp = new float [ <NUM_LIT:16> ] ; getTextureMatrix ( tex ) . getColumnMajorData ( tmp ) ; gl . glLoadMatrixf ( tmp , <NUM_LIT:0> ) ; } gl . glMatrixMode ( GL2 . GL_MODELVIEW ) ; } else if ( haveTexCoords ) { gl . glDisableClientState ( GL2 . GL_TEXTURE_COORD_ARRAY ) ; } gl . glDrawArrays ( GL2 . GL_TRIANGLES , <NUM_LIT:0> , <NUM_LIT:3> * getNumTriangles ( ) ) ; if ( tex != null ) { gl . glMatrixMode ( GL2 . GL_TEXTURE ) ; gl . glPopMatrix ( ) ; gl . glMatrixMode ( GL2 . GL_MODELVIEW ) ; } else if ( haveTexCoords ) { gl . glEnableClientState ( GL2 . GL_TEXTURE_COORD_ARRAY ) ; } } } public void generateTriangles ( Action action , TriangleCallback cb ) { State state = action . getState ( ) ; FloatBuffer coords = null ; FloatBuffer texCoords = null ; FloatBuffer colors = null ; if ( CoordinateElement . isEnabled ( state ) ) { coords = CoordinateElement . get ( state ) ; } if ( coords == null ) return ; if ( TextureCoordinateElement . isEnabled ( state ) ) { texCoords = TextureCoordinateElement . get ( state ) ; } if ( ColorElement . isEnabled ( state ) ) { colors = ColorElement . get ( state ) ; } PrimitiveVertex v0 = new PrimitiveVertex ( ) ; PrimitiveVertex v1 = new PrimitiveVertex ( ) ; PrimitiveVertex v2 = new PrimitiveVertex ( ) ; v0 . setCoord ( new Vec3f ( ) ) ; v1 . setCoord ( new Vec3f ( ) ) ; v2 . setCoord ( new Vec3f ( ) ) ; if ( texCoords != null ) { v0 . setTexCoord ( new Vec2f ( ) ) ; v1 . setTexCoord ( new Vec2f ( ) ) ; v2 . setTexCoord ( new Vec2f ( ) ) ; } if ( colors != null ) { v0 . setColor ( new Vec4f ( ) ) ; v1 . setColor ( new Vec4f ( ) ) ; v2 . setColor ( new Vec4f ( ) ) ; } int coordIdx = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < numTriangles ; i ++ ) { v0 . getCoord ( ) . set ( coords . get ( <NUM_LIT:3> * coordIdx + <NUM_LIT:0> ) , coords . get ( <NUM_LIT:3> * coordIdx + <NUM_LIT:1> ) , coords . get ( <NUM_LIT:3> * coordIdx + <NUM_LIT:2> ) ) ; if ( texCoords != null ) { v0 . getTexCoord ( ) . set ( texCoords . get ( <NUM_LIT:2> * coordIdx + <NUM_LIT:0> ) , texCoords . get ( <NUM_LIT:2> * coordIdx + <NUM_LIT:1> ) ) ; } if ( colors != null ) { v0 . getColor ( ) . set ( colors . get ( <NUM_LIT:4> * coordIdx + <NUM_LIT:0> ) , colors . get ( <NUM_LIT:4> * coordIdx + <NUM_LIT:1> ) , colors . get ( <NUM_LIT:4> * coordIdx + <NUM_LIT:2> ) , colors . get ( <NUM_LIT:4> * coordIdx + <NUM_LIT:3> ) ) ; } v1 . getCoord ( ) . set ( coords . get ( <NUM_LIT:3> * ( coordIdx + <NUM_LIT:1> ) + <NUM_LIT:0> ) , coords . get ( <NUM_LIT:3> * ( coordIdx + <NUM_LIT:1> ) + <NUM_LIT:1> ) , coords . get ( <NUM_LIT:3> * ( coordIdx + <NUM_LIT:1> ) + <NUM_LIT:2> ) ) ; if ( texCoords != null ) { v1 . getTexCoord ( ) . set ( texCoords . get ( <NUM_LIT:2> * ( coordIdx + <NUM_LIT:1> ) + <NUM_LIT:0> ) , texCoords . get ( <NUM_LIT:2> * ( coordIdx + <NUM_LIT:1> ) + <NUM_LIT:1> ) ) ; } if ( colors != null ) { v1 . getColor ( ) . set ( colors . get ( <NUM_LIT:4> * ( coordIdx + <NUM_LIT:1> ) + <NUM_LIT:0> ) , colors . get ( <NUM_LIT:4> * ( coordIdx + <NUM_LIT:1> ) + <NUM_LIT:1> ) , colors . get ( <NUM_LIT:4> * ( coordIdx + <NUM_LIT:1> ) + <NUM_LIT:2> ) , colors . get ( <NUM_LIT:4> * ( coordIdx + <NUM_LIT:1> ) + <NUM_LIT:3> ) ) ; } v2 . getCoord ( ) . set ( coords . get ( <NUM_LIT:3> * ( coordIdx + <NUM_LIT:2> ) + <NUM_LIT:0> ) , coords . get ( <NUM_LIT:3> * ( coordIdx + <NUM_LIT:2> ) + <NUM_LIT:1> ) , coords . get ( <NUM_LIT:3> * ( coordIdx + <NUM_LIT:2> ) + <NUM_LIT:2> ) ) ; if ( texCoords != null ) { v2 . getTexCoord ( ) . set ( texCoords . get ( <NUM_LIT:2> * ( coordIdx + <NUM_LIT:2> ) + <NUM_LIT:0> ) , texCoords . get ( <NUM_LIT:2> * ( coordIdx + <NUM_LIT:2> ) + <NUM_LIT:1> ) ) ; } if ( colors != null ) { v2 . getColor ( ) . set ( colors . get ( <NUM_LIT:4> * ( coordIdx + <NUM_LIT:2> ) + <NUM_LIT:0> ) , colors . get ( <NUM_LIT:4> * ( coordIdx + <NUM_LIT:2> ) + <NUM_LIT:1> ) , colors . get ( <NUM_LIT:4> * ( coordIdx + <NUM_LIT:2> ) + <NUM_LIT:2> ) , colors . get ( <NUM_LIT:4> * ( coordIdx + <NUM_LIT:2> ) + <NUM_LIT:3> ) ) ; } cb . triangleCB ( i , v0 , <NUM_LIT:3> * i + <NUM_LIT:0> , v1 , <NUM_LIT:3> * i + <NUM_LIT:1> , v2 , <NUM_LIT:3> * i + <NUM_LIT:2> ) ; coordIdx += <NUM_LIT:3> ; } } private Mat4f textureMatrix = new Mat4f ( ) ; private Mat4f getTextureMatrix ( Texture texture ) { textureMatrix . makeIdent ( ) ; TextureCoords coords = texture . getImageTexCoords ( ) ; textureMatrix . set ( <NUM_LIT:0> , <NUM_LIT:0> , coords . right ( ) - coords . left ( ) ) ; float vertScale = coords . top ( ) - coords . bottom ( ) ; textureMatrix . set ( <NUM_LIT:1> , <NUM_LIT:1> , vertScale ) ; textureMatrix . set ( <NUM_LIT:0> , <NUM_LIT:3> , coords . left ( ) ) ; textureMatrix . set ( <NUM_LIT:1> , <NUM_LIT:3> , coords . bottom ( ) ) ; return textureMatrix ; } } </s>
<s> package net . java . joglutils . msg . nodes ; import java . util . * ; import net . java . joglutils . msg . actions . * ; import net . java . joglutils . msg . elements . * ; import net . java . joglutils . msg . impl . * ; import net . java . joglutils . msg . math . * ; import net . java . joglutils . msg . misc . * ; public abstract class TriangleBasedShape extends Shape { public abstract void generateTriangles ( Action action , TriangleCallback cb ) ; public void rayPick ( final RayPickAction action ) { Mat4f mat = new Mat4f ( ModelMatrixElement . getInstance ( action . getState ( ) ) . getMatrix ( ) ) ; mat . invert ( ) ; final Line ray = mat . xformLine ( action . getComputedRay ( ) ) ; final RayTriangleIntersection rti = new RayTriangleIntersection ( ) ; final Vec3f tuv = new Vec3f ( ) ; generateTriangles ( action , new TriangleCallback ( ) { public void triangleCB ( int triangleIndex , PrimitiveVertex v0 , int i0 , PrimitiveVertex v1 , int i1 , PrimitiveVertex v2 , int i2 ) { if ( rti . intersectTriangle ( ray , v0 . getCoord ( ) , v1 . getCoord ( ) , v2 . getCoord ( ) , tuv ) ) { PickedPoint p = new PickedPoint ( ) ; float a = <NUM_LIT:1.0f> - tuv . y ( ) - tuv . z ( ) ; float b = tuv . y ( ) ; float c = tuv . z ( ) ; Vec3f loc = v0 . getCoord ( ) . times ( a ) . plus ( v1 . getCoord ( ) . times ( b ) ) . plus ( v2 . getCoord ( ) . times ( c ) ) ; p . setCoord ( loc ) ; p . setPath ( action . getPath ( ) . copy ( ) ) ; action . addPickedPoint ( p , tuv . x ( ) ) ; } } } ) ; } } </s>
<s> package net . java . joglutils . msg . elements ; import net . java . joglutils . msg . math . * ; import net . java . joglutils . msg . misc . * ; public class ProjectionMatrixElement extends Element { private static StateIndex index = State . registerElementType ( ) ; public StateIndex getStateIndex ( ) { return index ; } public Element newInstance ( ) { return new ProjectionMatrixElement ( ) ; } public static ProjectionMatrixElement getInstance ( State state ) { return ( ProjectionMatrixElement ) state . getElement ( index ) ; } public static void enable ( State defaultState ) { Element tmp = new ProjectionMatrixElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } public static boolean isEnabled ( State state ) { return ( state . getDefaults ( ) . getElement ( index ) != null ) ; } protected Mat4f matrix ; public ProjectionMatrixElement ( ) { matrix = new Mat4f ( ) ; matrix . makeIdent ( ) ; } public Mat4f getMatrix ( ) { return matrix ; } public void push ( State state ) { ProjectionMatrixElement prev = ( ProjectionMatrixElement ) getNextInStack ( ) ; if ( prev != null ) { matrix . set ( prev . matrix ) ; } } public static void set ( State state , Mat4f matrix ) { ProjectionMatrixElement elt = getInstance ( state ) ; elt . setElt ( matrix ) ; } public void setElt ( Mat4f matrix ) { this . matrix . set ( matrix ) ; } } </s>
<s> package net . java . joglutils . msg . elements ; import net . java . joglutils . msg . math . * ; import net . java . joglutils . msg . misc . * ; public class ViewingMatrixElement extends Element { private static StateIndex index = State . registerElementType ( ) ; public StateIndex getStateIndex ( ) { return index ; } public Element newInstance ( ) { return new ViewingMatrixElement ( ) ; } public static ViewingMatrixElement getInstance ( State state ) { return ( ViewingMatrixElement ) state . getElement ( index ) ; } public static void enable ( State defaultState ) { Element tmp = new ViewingMatrixElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } public static boolean isEnabled ( State state ) { return ( state . getDefaults ( ) . getElement ( index ) != null ) ; } protected Mat4f matrix ; public ViewingMatrixElement ( ) { matrix = new Mat4f ( ) ; matrix . makeIdent ( ) ; } public Mat4f getMatrix ( ) { return matrix ; } public void push ( State state ) { ViewingMatrixElement prev = ( ViewingMatrixElement ) getNextInStack ( ) ; if ( prev != null ) { matrix . set ( prev . matrix ) ; } } public static void set ( State state , Mat4f matrix ) { ViewingMatrixElement elt = getInstance ( state ) ; elt . setElt ( matrix ) ; } public void setElt ( Mat4f matrix ) { this . matrix . set ( matrix ) ; } } </s>
<s> package net . java . joglutils . msg . elements ; import java . nio . * ; import javax . media . opengl . * ; import javax . media . opengl . glu . * ; import net . java . joglutils . msg . math . * ; import net . java . joglutils . msg . misc . * ; import net . java . joglutils . msg . nodes . * ; public class GLBlendElement extends BlendElement { public Element newInstance ( ) { return new GLBlendElement ( ) ; } public static GLBlendElement getInstance ( State state ) { return ( GLBlendElement ) BlendElement . getInstance ( state ) ; } public static void enable ( State defaultState ) { Element tmp = new GLBlendElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } public void pop ( State state , Element previousTopElement ) { send ( ) ; } public void setElt ( boolean enabled , Vec4f blendColor , int srcFunc , int destFunc , int blendEquation ) { super . setElt ( enabled , blendColor , srcFunc , destFunc , blendEquation ) ; send ( ) ; } private static int oglBlendFunc ( int func ) { switch ( func ) { case Blend . ZERO : return GL2 . GL_ZERO ; case Blend . ONE : return GL2 . GL_ONE ; case Blend . SRC_COLOR : return GL2 . GL_SRC_COLOR ; case Blend . ONE_MINUS_SRC_COLOR : return GL2 . GL_ONE_MINUS_SRC_COLOR ; case Blend . DST_COLOR : return GL2 . GL_DST_COLOR ; case Blend . ONE_MINUS_DST_COLOR : return GL2 . GL_ONE_MINUS_DST_COLOR ; case Blend . SRC_ALPHA : return GL2 . GL_SRC_ALPHA ; case Blend . ONE_MINUS_SRC_ALPHA : return GL2 . GL_ONE_MINUS_SRC_ALPHA ; case Blend . DST_ALPHA : return GL2 . GL_DST_ALPHA ; case Blend . ONE_MINUS_DST_ALPHA : return GL2 . GL_ONE_MINUS_DST_ALPHA ; case Blend . SRC_ALPHA_SATURATE : return GL2 . GL_SRC_ALPHA_SATURATE ; case Blend . CONSTANT_COLOR : return GL2 . GL_CONSTANT_COLOR ; case Blend . ONE_MINUS_CONSTANT_COLOR : return GL2 . GL_ONE_MINUS_CONSTANT_COLOR ; case Blend . CONSTANT_ALPHA : return GL2 . GL_CONSTANT_ALPHA ; case Blend . ONE_MINUS_CONSTANT_ALPHA : return GL2 . GL_ONE_MINUS_CONSTANT_ALPHA ; } throw new InternalError ( "<STR_LIT>" + func ) ; } private int oglBlendEquation ( int equation ) { switch ( equation ) { case Blend . FUNC_ADD : return GL2 . GL_FUNC_ADD ; case Blend . FUNC_SUBTRACT : return GL2 . GL_FUNC_SUBTRACT ; case Blend . FUNC_REVERSE_SUBTRACT : return GL2 . GL_FUNC_REVERSE_SUBTRACT ; case Blend . MIN : return GL2 . GL_MIN ; case Blend . MAX : return GL2 . GL_MAX ; } throw new InternalError ( "<STR_LIT>" + equation ) ; } private static void validateFunc ( GL2 gl , int func ) { if ( func == GL2 . GL_CONSTANT_COLOR || func == GL2 . GL_ONE_MINUS_CONSTANT_COLOR || func == GL2 . GL_CONSTANT_ALPHA || func == GL2 . GL_ONE_MINUS_CONSTANT_ALPHA ) { if ( ! gl . isExtensionAvailable ( "<STR_LIT>" ) ) { throw new RuntimeException ( "<STR_LIT>" ) ; } } } private void send ( ) { GL2 gl = GLU . getCurrentGL ( ) . getGL2 ( ) ; if ( enabled ) { gl . glEnable ( GL2 . GL_BLEND ) ; int oglSrcFunc = oglBlendFunc ( srcFunc ) ; int oglDestFunc = oglBlendFunc ( destFunc ) ; validateFunc ( gl , oglSrcFunc ) ; validateFunc ( gl , oglDestFunc ) ; gl . glBlendFunc ( oglSrcFunc , oglDestFunc ) ; if ( gl . isExtensionAvailable ( "<STR_LIT>" ) ) { gl . glBlendEquation ( oglBlendEquation ( blendEquation ) ) ; gl . glBlendColor ( blendColor . x ( ) , blendColor . y ( ) , blendColor . z ( ) , blendColor . w ( ) ) ; } } else { gl . glDisable ( GL2 . GL_BLEND ) ; } } } </s>
<s> package net . java . joglutils . msg . elements ; import net . java . joglutils . msg . misc . * ; public abstract class Element { private Element nextInStack ; private Element next ; private int depth ; protected Element ( ) { } public abstract Element newInstance ( ) ; public Element getNextInStack ( ) { return nextInStack ; } public void setNextInStack ( Element nextInStack ) { this . nextInStack = nextInStack ; } public Element getNext ( ) { return next ; } public void setNext ( Element next ) { this . next = next ; } public int getDepth ( ) { return depth ; } public void setDepth ( int depth ) { this . depth = depth ; } public void push ( State state ) { } public void pop ( State state , Element previousTopElement ) { } public abstract StateIndex getStateIndex ( ) ; } </s>
<s> package net . java . joglutils . msg . elements ; import java . nio . * ; import javax . media . opengl . * ; import javax . media . opengl . glu . * ; import net . java . joglutils . msg . math . * ; import net . java . joglutils . msg . misc . * ; import net . java . joglutils . msg . nodes . * ; public class GLDepthTestElement extends DepthTestElement { public Element newInstance ( ) { return new GLDepthTestElement ( ) ; } public static GLDepthTestElement getInstance ( State state ) { return ( GLDepthTestElement ) DepthTestElement . getInstance ( state ) ; } public static void enable ( State defaultState ) { Element tmp = new GLDepthTestElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } public void pop ( State state , Element previousTopElement ) { send ( ) ; } public void setElt ( boolean enabled ) { super . setElt ( enabled ) ; send ( ) ; } private void send ( ) { GL gl = GLU . getCurrentGL ( ) ; if ( enabled ) { gl . glEnable ( GL . GL_DEPTH_TEST ) ; } else { gl . glDisable ( GL . GL_DEPTH_TEST ) ; } } } </s>
<s> package net . java . joglutils . msg . elements ; import java . nio . * ; import javax . media . opengl . * ; import javax . media . opengl . glu . * ; import net . java . joglutils . msg . math . * ; import net . java . joglutils . msg . misc . * ; public class GLProjectionMatrixElement extends ProjectionMatrixElement { public Element newInstance ( ) { return new GLProjectionMatrixElement ( ) ; } public static GLProjectionMatrixElement getInstance ( State state ) { return ( GLProjectionMatrixElement ) ProjectionMatrixElement . getInstance ( state ) ; } public static void enable ( State defaultState ) { Element tmp = new GLProjectionMatrixElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } public void push ( State state ) { super . push ( state ) ; } public void setElt ( Mat4f matrix ) { super . setElt ( matrix ) ; GL2 gl = GLU . getCurrentGL ( ) . getGL2 ( ) ; gl . glMatrixMode ( GL2 . GL_PROJECTION ) ; if ( gl . isExtensionAvailable ( "<STR_LIT>" ) ) { gl . glLoadTransposeMatrixf ( matrix . getRowMajorData ( ) , <NUM_LIT:0> ) ; } else { float [ ] tmp = new float [ <NUM_LIT:16> ] ; matrix . getColumnMajorData ( tmp ) ; gl . glLoadMatrixf ( tmp , <NUM_LIT:0> ) ; } gl . glMatrixMode ( GL2 . GL_MODELVIEW ) ; } } </s>
<s> package net . java . joglutils . msg . elements ; import java . nio . * ; import javax . media . opengl . * ; import net . java . joglutils . msg . misc . * ; import net . java . joglutils . msg . nodes . * ; public class TextureElement extends Element { private static StateIndex index = State . registerElementType ( ) ; public StateIndex getStateIndex ( ) { return index ; } public Element newInstance ( ) { return new TextureElement ( ) ; } public static TextureElement getInstance ( State state ) { return ( TextureElement ) state . getElement ( index ) ; } public static void enable ( State defaultState ) { TextureElement tmp = new TextureElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } public static boolean isEnabled ( State state ) { return ( state . getDefaults ( ) . getElement ( index ) != null ) ; } protected Texture2 texture ; public static void set ( State state , Texture2 texture ) { getInstance ( state ) . setElt ( texture ) ; } public static Texture2 get ( State state ) { return getInstance ( state ) . texture ; } public void push ( State state ) { TextureElement prev = ( TextureElement ) getNextInStack ( ) ; if ( prev != null ) { texture = prev . texture ; } } public void setElt ( Texture2 texture ) { this . texture = texture ; } } </s>
<s> package net . java . joglutils . msg . elements ; import java . util . * ; import javax . media . opengl . * ; import javax . media . opengl . glu . * ; import net . java . joglutils . msg . math . * ; import net . java . joglutils . msg . misc . * ; import net . java . joglutils . msg . nodes . * ; public class GLShaderElement extends ShaderElement { public Element newInstance ( ) { return new GLShaderElement ( ) ; } public static GLShaderElement getInstance ( State state ) { return ( GLShaderElement ) ShaderElement . getInstance ( state ) ; } public static void enable ( State defaultState ) { Element tmp = new GLShaderElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } public void pop ( State state , Element previousTopElement ) { switchShaders ( ( ( GLShaderElement ) previousTopElement ) . shader , shader ) ; } public void setElt ( ShaderNode shader ) { ShaderNode prev = this . shader ; super . setElt ( shader ) ; switchShaders ( prev , shader ) ; } private void switchShaders ( ShaderNode prev , ShaderNode shader ) { GL gl = GLU . getCurrentGL ( ) ; Shader prevShader = null ; Shader curShader = null ; if ( prev != null ) { prevShader = prev . getShader ( ) ; } if ( shader != null ) { curShader = shader . getShader ( ) ; } if ( prevShader != null ) { prevShader . disable ( ) ; } if ( curShader != null ) { curShader . enable ( ) ; } } } </s>
<s> package net . java . joglutils . msg . elements ; import java . nio . * ; import javax . media . opengl . * ; import net . java . joglutils . msg . misc . * ; public class TextureCoordinateElement extends Element { private static StateIndex index = State . registerElementType ( ) ; public StateIndex getStateIndex ( ) { return index ; } public Element newInstance ( ) { return new TextureCoordinateElement ( ) ; } public static TextureCoordinateElement getInstance ( State state ) { return ( TextureCoordinateElement ) state . getElement ( index ) ; } public static void enable ( State defaultState ) { TextureCoordinateElement tmp = new TextureCoordinateElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } public static boolean isEnabled ( State state ) { return ( state . getDefaults ( ) . getElement ( index ) != null ) ; } protected FloatBuffer coords ; public static void set ( State state , FloatBuffer coords ) { getInstance ( state ) . setElt ( coords ) ; } public static FloatBuffer get ( State state ) { return getInstance ( state ) . coords ; } public void push ( State state ) { TextureCoordinateElement prev = ( TextureCoordinateElement ) getNextInStack ( ) ; if ( prev != null ) { coords = prev . coords ; } } public void setElt ( FloatBuffer coords ) { this . coords = coords ; } } </s>
<s> package net . java . joglutils . msg . elements ; import java . nio . * ; import javax . media . opengl . * ; import net . java . joglutils . msg . misc . * ; public class CoordinateElement extends Element { private static StateIndex index = State . registerElementType ( ) ; public StateIndex getStateIndex ( ) { return index ; } public Element newInstance ( ) { return new CoordinateElement ( ) ; } public static CoordinateElement getInstance ( State state ) { return ( CoordinateElement ) state . getElement ( index ) ; } public static void enable ( State defaultState ) { CoordinateElement tmp = new CoordinateElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } public static boolean isEnabled ( State state ) { return ( state . getDefaults ( ) . getElement ( index ) != null ) ; } protected FloatBuffer coords ; public static void set ( State state , FloatBuffer coords ) { getInstance ( state ) . setElt ( coords ) ; } public static FloatBuffer get ( State state ) { return getInstance ( state ) . coords ; } public void push ( State state ) { CoordinateElement prev = ( CoordinateElement ) getNextInStack ( ) ; if ( prev != null ) { coords = prev . coords ; } } public void setElt ( FloatBuffer coords ) { this . coords = coords ; } } </s>
<s> package net . java . joglutils . msg . elements ; import net . java . joglutils . msg . math . * ; import net . java . joglutils . msg . misc . * ; public class ModelMatrixElement extends Element { private static StateIndex index = State . registerElementType ( ) ; public StateIndex getStateIndex ( ) { return index ; } public Element newInstance ( ) { return new ModelMatrixElement ( ) ; } public static ModelMatrixElement getInstance ( State state ) { return ( ModelMatrixElement ) state . getElement ( index ) ; } public static void enable ( State defaultState ) { Element tmp = new ModelMatrixElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } public static boolean isEnabled ( State state ) { return ( state . getDefaults ( ) . getElement ( index ) != null ) ; } protected Mat4f matrix ; protected Mat4f temp = new Mat4f ( ) ; public ModelMatrixElement ( ) { matrix = new Mat4f ( ) ; matrix . makeIdent ( ) ; } public void push ( State state ) { ModelMatrixElement prev = ( ModelMatrixElement ) getNextInStack ( ) ; if ( prev != null ) { matrix . set ( prev . matrix ) ; } } public Mat4f getMatrix ( ) { return matrix ; } public static void makeIdent ( State state ) { ModelMatrixElement elt = getInstance ( state ) ; elt . makeEltIdent ( ) ; } public void makeEltIdent ( ) { matrix . makeIdent ( ) ; } public static void mult ( State state , Mat4f matrix ) { ModelMatrixElement elt = getInstance ( state ) ; elt . multElt ( matrix ) ; } public void multElt ( Mat4f matrix ) { temp . set ( this . matrix ) ; this . matrix . mul ( temp , matrix ) ; } } </s>
<s> package net . java . joglutils . msg . elements ; import net . java . joglutils . msg . misc . * ; import net . java . joglutils . msg . nodes . * ; public class ShaderElement extends Element { private static StateIndex index = State . registerElementType ( ) ; public StateIndex getStateIndex ( ) { return index ; } public Element newInstance ( ) { return new ShaderElement ( ) ; } public static ShaderElement getInstance ( State state ) { return ( ShaderElement ) state . getElement ( index ) ; } public static void enable ( State defaultState ) { ShaderElement tmp = new ShaderElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } public static boolean isEnabled ( State state ) { return ( state . getDefaults ( ) . getElement ( index ) != null ) ; } protected ShaderNode shader ; public static void set ( State state , ShaderNode shader ) { getInstance ( state ) . setElt ( shader ) ; } public static ShaderNode get ( State state ) { return getInstance ( state ) . shader ; } public void push ( State state ) { ShaderElement prev = ( ShaderElement ) getNextInStack ( ) ; if ( prev != null ) { shader = prev . shader ; } } public void setElt ( ShaderNode shader ) { this . shader = shader ; } } </s>
<s> package net . java . joglutils . msg . elements ; import java . nio . * ; import javax . media . opengl . * ; import javax . media . opengl . glu . * ; import net . java . joglutils . msg . math . * ; import net . java . joglutils . msg . misc . * ; public class GLModelMatrixElement extends ModelMatrixElement { public Element newInstance ( ) { return new GLModelMatrixElement ( ) ; } public static GLModelMatrixElement getInstance ( State state ) { return ( GLModelMatrixElement ) ModelMatrixElement . getInstance ( state ) ; } public static void enable ( State defaultState ) { Element tmp = new GLModelMatrixElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } private State state ; public void push ( State state ) { super . push ( state ) ; this . state = state ; GL2 gl = GLU . getCurrentGL ( ) . getGL2 ( ) ; gl . glPushMatrix ( ) ; } public void pop ( State state , Element previousTopElement ) { super . pop ( state , previousTopElement ) ; GL2 gl = GLU . getCurrentGL ( ) . getGL2 ( ) ; gl . glPopMatrix ( ) ; } public void makeEltIdent ( ) { super . makeEltIdent ( ) ; Mat4f mat = ViewingMatrixElement . getInstance ( state ) . getMatrix ( ) ; GL2 gl = GLU . getCurrentGL ( ) . getGL2 ( ) ; if ( gl . isExtensionAvailable ( "<STR_LIT>" ) ) { gl . glLoadTransposeMatrixf ( mat . getRowMajorData ( ) , <NUM_LIT:0> ) ; } else { float [ ] tmp = new float [ <NUM_LIT:16> ] ; mat . getColumnMajorData ( tmp ) ; gl . glLoadMatrixf ( tmp , <NUM_LIT:0> ) ; } } public void multElt ( Mat4f matrix ) { super . multElt ( matrix ) ; GL2 gl = GLU . getCurrentGL ( ) . getGL2 ( ) ; if ( gl . isExtensionAvailable ( "<STR_LIT>" ) ) { gl . glMultTransposeMatrixf ( matrix . getRowMajorData ( ) , <NUM_LIT:0> ) ; } else { float [ ] tmp = new float [ <NUM_LIT:16> ] ; matrix . getColumnMajorData ( tmp ) ; gl . glMultMatrixf ( tmp , <NUM_LIT:0> ) ; } } } </s>
<s> package net . java . joglutils . msg . elements ; import java . nio . * ; import javax . media . opengl . * ; import javax . media . opengl . glu . * ; import net . java . joglutils . msg . math . * ; import net . java . joglutils . msg . misc . * ; public class GLViewingMatrixElement extends ViewingMatrixElement { public Element newInstance ( ) { return new GLViewingMatrixElement ( ) ; } public static GLViewingMatrixElement getInstance ( State state ) { return ( GLViewingMatrixElement ) ViewingMatrixElement . getInstance ( state ) ; } public static void enable ( State defaultState ) { Element tmp = new GLViewingMatrixElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } private State state ; protected Mat4f temp = new Mat4f ( ) ; public void push ( State state ) { super . push ( state ) ; this . state = state ; } public void setElt ( Mat4f matrix ) { super . setElt ( matrix ) ; Mat4f mdl = ModelMatrixElement . getInstance ( state ) . getMatrix ( ) ; temp . mul ( matrix , mdl ) ; GL2 gl = GLU . getCurrentGL ( ) . getGL2 ( ) ; if ( gl . isExtensionAvailable ( "<STR_LIT>" ) ) { gl . glLoadTransposeMatrixf ( temp . getRowMajorData ( ) , <NUM_LIT:0> ) ; } else { float [ ] tmp = new float [ <NUM_LIT:16> ] ; temp . getColumnMajorData ( tmp ) ; gl . glLoadMatrixf ( tmp , <NUM_LIT:0> ) ; } } } </s>
<s> package net . java . joglutils . msg . elements ; import java . nio . * ; import javax . media . opengl . * ; import javax . media . opengl . glu . * ; import net . java . joglutils . msg . misc . * ; public class GLColorElement extends ColorElement { public Element newInstance ( ) { return new GLColorElement ( ) ; } public static GLColorElement getInstance ( State state ) { return ( GLColorElement ) ColorElement . getInstance ( state ) ; } public static void enable ( State defaultState ) { Element tmp = new GLColorElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } private boolean enabled ; public void push ( State state ) { super . push ( state ) ; GLColorElement prev = ( GLColorElement ) getNextInStack ( ) ; if ( prev != null ) { enabled = prev . enabled ; } } public void pop ( State state , Element previousTopElement ) { GLColorElement prev = ( GLColorElement ) previousTopElement ; boolean shouldBeEnabled = enabled ; enabled = prev . enabled ; setEnabled ( shouldBeEnabled ) ; } public void setElt ( FloatBuffer colors ) { super . setElt ( colors ) ; setEnabled ( colors != null ) ; } private void setEnabled ( boolean enabled ) { if ( this . enabled == enabled ) return ; this . enabled = enabled ; GL2 gl = GLU . getCurrentGL ( ) . getGL2 ( ) ; if ( enabled ) { gl . glColorPointer ( <NUM_LIT:4> , GL2 . GL_FLOAT , <NUM_LIT:0> , colors ) ; gl . glEnableClientState ( GL2 . GL_COLOR_ARRAY ) ; } else { gl . glDisableClientState ( GL2 . GL_COLOR_ARRAY ) ; gl . glColor4f ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) ; } } } </s>
<s> package net . java . joglutils . msg . elements ; import java . nio . * ; import javax . media . opengl . * ; import javax . media . opengl . glu . * ; import net . java . joglutils . msg . misc . * ; public class GLTextureCoordinateElement extends TextureCoordinateElement { public Element newInstance ( ) { return new GLTextureCoordinateElement ( ) ; } public static GLTextureCoordinateElement getInstance ( State state ) { return ( GLTextureCoordinateElement ) TextureCoordinateElement . getInstance ( state ) ; } public static void enable ( State defaultState ) { Element tmp = new GLTextureCoordinateElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } private boolean enabled ; public void push ( State state ) { super . push ( state ) ; GLTextureCoordinateElement prev = ( GLTextureCoordinateElement ) getNextInStack ( ) ; if ( prev != null ) { enabled = prev . enabled ; } } public void pop ( State state , Element previousTopElement ) { GLTextureCoordinateElement prev = ( GLTextureCoordinateElement ) previousTopElement ; boolean shouldBeEnabled = enabled ; enabled = prev . enabled ; setEnabled ( shouldBeEnabled ) ; } public void setElt ( FloatBuffer coords ) { super . setElt ( coords ) ; setEnabled ( coords != null ) ; } private void setEnabled ( boolean enabled ) { if ( this . enabled == enabled ) return ; this . enabled = enabled ; GL2 gl = GLU . getCurrentGL ( ) . getGL2 ( ) ; if ( enabled ) { gl . glTexCoordPointer ( <NUM_LIT:2> , GL2 . GL_FLOAT , <NUM_LIT:0> , coords ) ; gl . glEnableClientState ( GL2 . GL_TEXTURE_COORD_ARRAY ) ; } else { gl . glDisableClientState ( GL2 . GL_TEXTURE_COORD_ARRAY ) ; } } } </s>
<s> package net . java . joglutils . msg . elements ; import java . nio . * ; import javax . media . opengl . * ; import javax . media . opengl . glu . * ; import com . sun . opengl . util . texture . * ; import net . java . joglutils . msg . misc . * ; import net . java . joglutils . msg . nodes . * ; public class GLTextureElement extends TextureElement { public Element newInstance ( ) { return new GLTextureElement ( ) ; } public static GLTextureElement getInstance ( State state ) { return ( GLTextureElement ) TextureElement . getInstance ( state ) ; } public static void enable ( State defaultState ) { Element tmp = new GLTextureElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } public void pop ( State state , Element previousTopElement ) { switchTextures ( ( ( GLTextureElement ) previousTopElement ) . texture , texture ) ; } public void setElt ( Texture2 texture ) { Texture2 prev = this . texture ; super . setElt ( texture ) ; switchTextures ( prev , texture ) ; } private void switchTextures ( Texture2 prev , Texture2 texture ) { GL2 gl = GLU . getCurrentGL ( ) . getGL2 ( ) ; Texture prevTexture = null ; Texture curTexture = null ; int texEnvMode = <NUM_LIT:0> ; if ( prev != null ) { prevTexture = prev . getTexture ( ) ; } if ( texture != null ) { curTexture = texture . getTexture ( ) ; texEnvMode = texture . getTexEnvMode ( ) ; } if ( prevTexture != null ) { prevTexture . disable ( ) ; } if ( curTexture != null ) { curTexture . enable ( ) ; curTexture . bind ( ) ; int glEnvMode = <NUM_LIT:0> ; switch ( texEnvMode ) { case Texture2 . MODULATE : glEnvMode = GL2 . GL_MODULATE ; break ; case Texture2 . DECAL : glEnvMode = GL2 . GL_DECAL ; break ; case Texture2 . BLEND : glEnvMode = GL2 . GL_BLEND ; break ; case Texture2 . REPLACE : glEnvMode = GL2 . GL_REPLACE ; break ; } gl . glTexEnvi ( GL2 . GL_TEXTURE_ENV , GL2 . GL_TEXTURE_ENV_MODE , glEnvMode ) ; } } } </s>
<s> package net . java . joglutils . msg . elements ; import java . nio . * ; import javax . media . opengl . * ; import net . java . joglutils . msg . misc . * ; public class ColorElement extends Element { private static StateIndex index = State . registerElementType ( ) ; public StateIndex getStateIndex ( ) { return index ; } public Element newInstance ( ) { return new ColorElement ( ) ; } public static ColorElement getInstance ( State state ) { return ( ColorElement ) state . getElement ( index ) ; } public static void enable ( State defaultState ) { ColorElement tmp = new ColorElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } public static boolean isEnabled ( State state ) { return ( state . getDefaults ( ) . getElement ( index ) != null ) ; } protected FloatBuffer colors ; protected int colorBinding ; public static void set ( State state , FloatBuffer colors ) { getInstance ( state ) . setElt ( colors ) ; } public static FloatBuffer get ( State state ) { return getInstance ( state ) . colors ; } public void push ( State state ) { ColorElement prev = ( ColorElement ) getNextInStack ( ) ; if ( prev != null ) { colors = prev . colors ; } } public void setElt ( FloatBuffer colors ) { this . colors = colors ; } } </s>
<s> package net . java . joglutils . msg . elements ; import java . nio . * ; import javax . media . opengl . * ; import javax . media . opengl . glu . * ; import net . java . joglutils . msg . misc . * ; public class GLCoordinateElement extends CoordinateElement { public Element newInstance ( ) { return new GLCoordinateElement ( ) ; } public static GLCoordinateElement getInstance ( State state ) { return ( GLCoordinateElement ) CoordinateElement . getInstance ( state ) ; } public static void enable ( State defaultState ) { Element tmp = new GLCoordinateElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } private boolean enabled ; public void push ( State state ) { super . push ( state ) ; GLCoordinateElement prev = ( GLCoordinateElement ) getNextInStack ( ) ; if ( prev != null ) { enabled = prev . enabled ; } } public void pop ( State state , Element previousTopElement ) { GLCoordinateElement prev = ( GLCoordinateElement ) previousTopElement ; boolean shouldBeEnabled = enabled ; enabled = prev . enabled ; setEnabled ( shouldBeEnabled ) ; } public void setElt ( FloatBuffer coords ) { super . setElt ( coords ) ; setEnabled ( coords != null ) ; } private void setEnabled ( boolean enabled ) { if ( this . enabled == enabled ) return ; this . enabled = enabled ; GL2 gl = GLU . getCurrentGL ( ) . getGL2 ( ) ; if ( enabled ) { gl . glVertexPointer ( <NUM_LIT:3> , GL2 . GL_FLOAT , <NUM_LIT:0> , coords ) ; gl . glEnableClientState ( GL2 . GL_VERTEX_ARRAY ) ; } else { gl . glDisableClientState ( GL2 . GL_VERTEX_ARRAY ) ; } } } </s>
<s> package net . java . joglutils . msg . elements ; import javax . media . opengl . * ; import net . java . joglutils . msg . math . * ; import net . java . joglutils . msg . misc . * ; import net . java . joglutils . msg . nodes . * ; public class DepthTestElement extends Element { private static StateIndex index = State . registerElementType ( ) ; public StateIndex getStateIndex ( ) { return index ; } public Element newInstance ( ) { return new DepthTestElement ( ) ; } public static DepthTestElement getInstance ( State state ) { return ( DepthTestElement ) state . getElement ( index ) ; } public static void enable ( State defaultState ) { DepthTestElement tmp = new DepthTestElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } public static boolean isEnabled ( State state ) { return ( state . getDefaults ( ) . getElement ( index ) != null ) ; } protected boolean enabled ; public static void set ( State state , boolean enabled ) { getInstance ( state ) . setElt ( enabled ) ; } public static boolean getEnabled ( State state ) { return getInstance ( state ) . enabled ; } public void push ( State state ) { DepthTestElement prev = ( DepthTestElement ) getNextInStack ( ) ; if ( prev != null ) { enabled = prev . enabled ; } } public void setElt ( boolean enabled ) { this . enabled = enabled ; } } </s>
<s> package net . java . joglutils . msg . elements ; import java . nio . * ; import javax . media . opengl . * ; import net . java . joglutils . msg . math . * ; import net . java . joglutils . msg . misc . * ; import net . java . joglutils . msg . nodes . * ; public class BlendElement extends Element { private static StateIndex index = State . registerElementType ( ) ; public StateIndex getStateIndex ( ) { return index ; } public Element newInstance ( ) { return new BlendElement ( ) ; } public static BlendElement getInstance ( State state ) { return ( BlendElement ) state . getElement ( index ) ; } public static void enable ( State defaultState ) { BlendElement tmp = new BlendElement ( ) ; defaultState . setElement ( tmp . getStateIndex ( ) , tmp ) ; } public static boolean isEnabled ( State state ) { return ( state . getDefaults ( ) . getElement ( index ) != null ) ; } protected boolean enabled ; protected Vec4f blendColor = new Vec4f ( ) ; protected int srcFunc = Blend . ONE ; protected int destFunc = Blend . ZERO ; protected int blendEquation = Blend . FUNC_ADD ; public static void set ( State state , boolean enabled , Vec4f blendColor , int srcFunc , int destFunc , int blendEquation ) { getInstance ( state ) . setElt ( enabled , blendColor , srcFunc , destFunc , blendEquation ) ; } public static boolean getEnabled ( State state ) { return getInstance ( state ) . enabled ; } public static Vec4f getBlendColor ( State state ) { return getInstance ( state ) . blendColor ; } public static int getSourceFunc ( State state ) { return getInstance ( state ) . srcFunc ; } public static int getDestFunc ( State state ) { return getInstance ( state ) . destFunc ; } public static int getBlendEquation ( State state ) { return getInstance ( state ) . blendEquation ; } public void push ( State state ) { BlendElement prev = ( BlendElement ) getNextInStack ( ) ; if ( prev != null ) { enabled = prev . enabled ; blendColor . set ( prev . blendColor ) ; srcFunc = prev . srcFunc ; destFunc = prev . destFunc ; blendEquation = prev . blendEquation ; } } public void setElt ( boolean enabled , Vec4f blendColor , int srcFunc , int destFunc , int blendEquation ) { this . enabled = enabled ; this . blendColor . set ( blendColor ) ; this . srcFunc = srcFunc ; this . destFunc = destFunc ; this . blendEquation = blendEquation ; } } </s>
<s> package net . java . joglutils . msg . collections ; import java . nio . * ; import net . java . joglutils . msg . impl . * ; import net . java . joglutils . msg . math . * ; public class Vec3fCollection { private FloatBuffer data ; private static final int ELEMENT_SIZE = <NUM_LIT:3> ; public Vec3fCollection ( ) { this ( <NUM_LIT:4> ) ; } public Vec3fCollection ( int estimatedSize ) { data = BufferFactory . newFloatBuffer ( ELEMENT_SIZE * estimatedSize ) ; data . limit ( <NUM_LIT:0> ) ; } public int size ( ) { return data . limit ( ) / ELEMENT_SIZE ; } public void set ( int index , Vec3f value ) throws IndexOutOfBoundsException { if ( index >= size ( ) ) { throw new IndexOutOfBoundsException ( "<STR_LIT>" + index + "<STR_LIT>" + size ( ) ) ; } int base = index * ELEMENT_SIZE ; FloatBuffer buf = data ; buf . put ( base , value . x ( ) ) ; buf . put ( base + <NUM_LIT:1> , value . y ( ) ) ; buf . put ( base + <NUM_LIT:2> , value . z ( ) ) ; } public Vec3f get ( int index ) throws IndexOutOfBoundsException { if ( index >= size ( ) ) { throw new IndexOutOfBoundsException ( "<STR_LIT>" + index + "<STR_LIT>" + size ( ) ) ; } int base = index * ELEMENT_SIZE ; FloatBuffer buf = data ; return new Vec3f ( buf . get ( base ) , buf . get ( base + <NUM_LIT:1> ) , buf . get ( base + <NUM_LIT:2> ) ) ; } public void add ( Vec3f value ) { FloatBuffer buf = data ; if ( buf . limit ( ) == buf . capacity ( ) ) { FloatBuffer newBuf = BufferFactory . newFloatBuffer ( Math . max ( buf . capacity ( ) + ELEMENT_SIZE , round ( ( int ) ( buf . capacity ( ) * <NUM_LIT> ) ) ) ) ; newBuf . put ( buf ) ; newBuf . rewind ( ) ; newBuf . limit ( buf . limit ( ) ) ; data = newBuf ; buf = newBuf ; } int pos = buf . limit ( ) ; buf . limit ( pos + ELEMENT_SIZE ) ; buf . put ( pos , value . x ( ) ) ; buf . put ( pos + <NUM_LIT:1> , value . y ( ) ) ; buf . put ( pos + <NUM_LIT:2> , value . z ( ) ) ; } public Vec3f remove ( int index ) throws IndexOutOfBoundsException { if ( index >= size ( ) ) { throw new IndexOutOfBoundsException ( "<STR_LIT>" + index + "<STR_LIT>" + size ( ) ) ; } FloatBuffer buf = data ; int pos = index * ELEMENT_SIZE ; Vec3f res = new Vec3f ( buf . get ( pos ) , buf . get ( pos + <NUM_LIT:1> ) , buf . get ( pos + <NUM_LIT:2> ) ) ; if ( index == size ( ) - <NUM_LIT:1> ) { buf . limit ( buf . limit ( ) - ELEMENT_SIZE ) ; } else { buf . position ( pos + ELEMENT_SIZE ) ; FloatBuffer rest = buf . slice ( ) ; buf . position ( pos ) ; buf . put ( rest ) ; buf . limit ( buf . limit ( ) - ELEMENT_SIZE ) ; buf . rewind ( ) ; } return res ; } public FloatBuffer getData ( ) { FloatBuffer buf = data ; buf . position ( <NUM_LIT:0> ) ; return buf . slice ( ) ; } private static int round ( int size ) { return size - ( size % ELEMENT_SIZE ) ; } } </s>
<s> package net . java . joglutils . msg . collections ; import java . nio . * ; import net . java . joglutils . msg . impl . * ; import net . java . joglutils . msg . math . * ; public class Vec4fCollection { private FloatBuffer data ; private static final int ELEMENT_SIZE = <NUM_LIT:4> ; public Vec4fCollection ( ) { this ( <NUM_LIT:4> ) ; } public Vec4fCollection ( int estimatedSize ) { data = BufferFactory . newFloatBuffer ( ELEMENT_SIZE * estimatedSize ) ; data . limit ( <NUM_LIT:0> ) ; } public int size ( ) { return data . limit ( ) / ELEMENT_SIZE ; } public void set ( int index , Vec4f value ) throws IndexOutOfBoundsException { if ( index >= size ( ) ) { throw new IndexOutOfBoundsException ( "<STR_LIT>" + index + "<STR_LIT>" + size ( ) ) ; } int base = index * ELEMENT_SIZE ; FloatBuffer buf = data ; buf . put ( base , value . x ( ) ) ; buf . put ( base + <NUM_LIT:1> , value . y ( ) ) ; buf . put ( base + <NUM_LIT:2> , value . z ( ) ) ; buf . put ( base + <NUM_LIT:3> , value . w ( ) ) ; } public Vec4f get ( int index ) throws IndexOutOfBoundsException { if ( index >= size ( ) ) { throw new IndexOutOfBoundsException ( "<STR_LIT>" + index + "<STR_LIT>" + size ( ) ) ; } int base = index * ELEMENT_SIZE ; FloatBuffer buf = data ; return new Vec4f ( buf . get ( base ) , buf . get ( base + <NUM_LIT:1> ) , buf . get ( base + <NUM_LIT:2> ) , buf . get ( base + <NUM_LIT:3> ) ) ; } public void add ( Vec4f value ) { FloatBuffer buf = data ; if ( buf . limit ( ) == buf . capacity ( ) ) { FloatBuffer newBuf = BufferFactory . newFloatBuffer ( Math . max ( buf . capacity ( ) + ELEMENT_SIZE , round ( ( int ) ( buf . capacity ( ) * <NUM_LIT> ) ) ) ) ; newBuf . put ( buf ) ; newBuf . rewind ( ) ; newBuf . limit ( buf . limit ( ) ) ; data = newBuf ; buf = newBuf ; } int pos = buf . limit ( ) ; buf . limit ( pos + ELEMENT_SIZE ) ; buf . put ( pos , value . x ( ) ) ; buf . put ( pos + <NUM_LIT:1> , value . y ( ) ) ; buf . put ( pos + <NUM_LIT:2> , value . z ( ) ) ; buf . put ( pos + <NUM_LIT:3> , value . w ( ) ) ; } public Vec4f remove ( int index ) throws IndexOutOfBoundsException { if ( index >= size ( ) ) { throw new IndexOutOfBoundsException ( "<STR_LIT>" + index + "<STR_LIT>" + size ( ) ) ; } FloatBuffer buf = data ; int pos = index * ELEMENT_SIZE ; Vec4f res = new Vec4f ( buf . get ( pos ) , buf . get ( pos + <NUM_LIT:1> ) , buf . get ( pos + <NUM_LIT:2> ) , buf . get ( pos + <NUM_LIT:3> ) ) ; if ( index == size ( ) - <NUM_LIT:1> ) { buf . limit ( buf . limit ( ) - ELEMENT_SIZE ) ; } else { buf . position ( pos + ELEMENT_SIZE ) ; FloatBuffer rest = buf . slice ( ) ; buf . position ( pos ) ; buf . put ( rest ) ; buf . limit ( buf . limit ( ) - ELEMENT_SIZE ) ; buf . rewind ( ) ; } return res ; } public FloatBuffer getData ( ) { FloatBuffer buf = data ; buf . position ( <NUM_LIT:0> ) ; return buf . slice ( ) ; } private static int round ( int size ) { return size - ( size % ELEMENT_SIZE ) ; } } </s>
<s> package net . java . joglutils . msg . collections ; import java . nio . * ; import net . java . joglutils . msg . impl . * ; import net . java . joglutils . msg . math . * ; public class Vec2fCollection { private FloatBuffer data ; private static final int ELEMENT_SIZE = <NUM_LIT:2> ; public Vec2fCollection ( ) { this ( <NUM_LIT:4> ) ; } public Vec2fCollection ( int estimatedSize ) { data = BufferFactory . newFloatBuffer ( ELEMENT_SIZE * estimatedSize ) ; data . limit ( <NUM_LIT:0> ) ; } public int size ( ) { return data . limit ( ) / ELEMENT_SIZE ; } public void set ( int index , Vec2f value ) throws IndexOutOfBoundsException { if ( index >= size ( ) ) { throw new IndexOutOfBoundsException ( "<STR_LIT>" + index + "<STR_LIT>" + size ( ) ) ; } int base = index * ELEMENT_SIZE ; FloatBuffer buf = data ; buf . put ( base , value . x ( ) ) ; buf . put ( base + <NUM_LIT:1> , value . y ( ) ) ; } public Vec2f get ( int index ) throws IndexOutOfBoundsException { if ( index >= size ( ) ) { throw new IndexOutOfBoundsException ( "<STR_LIT>" + index + "<STR_LIT>" + size ( ) ) ; } int base = index * ELEMENT_SIZE ; FloatBuffer buf = data ; return new Vec2f ( buf . get ( base ) , buf . get ( base + <NUM_LIT:1> ) ) ; } public void add ( Vec2f value ) { FloatBuffer buf = data ; if ( buf . limit ( ) == buf . capacity ( ) ) { FloatBuffer newBuf = BufferFactory . newFloatBuffer ( Math . max ( buf . capacity ( ) + ELEMENT_SIZE , round ( ( int ) ( buf . capacity ( ) * <NUM_LIT> ) ) ) ) ; newBuf . put ( buf ) ; newBuf . rewind ( ) ; newBuf . limit ( buf . limit ( ) ) ; data = newBuf ; buf = newBuf ; } int pos = buf . limit ( ) ; buf . limit ( pos + ELEMENT_SIZE ) ; buf . put ( pos , value . x ( ) ) ; buf . put ( pos + <NUM_LIT:1> , value . y ( ) ) ; } public Vec2f remove ( int index ) throws IndexOutOfBoundsException { if ( index >= size ( ) ) { throw new IndexOutOfBoundsException ( "<STR_LIT>" + index + "<STR_LIT>" + size ( ) ) ; } FloatBuffer buf = data ; int pos = index * ELEMENT_SIZE ; Vec2f res = new Vec2f ( buf . get ( pos ) , buf . get ( pos + <NUM_LIT:1> ) ) ; if ( index == size ( ) - <NUM_LIT:1> ) { buf . limit ( buf . limit ( ) - ELEMENT_SIZE ) ; } else { buf . position ( pos + ELEMENT_SIZE ) ; FloatBuffer rest = buf . slice ( ) ; buf . position ( pos ) ; buf . put ( rest ) ; buf . limit ( buf . limit ( ) - ELEMENT_SIZE ) ; buf . rewind ( ) ; } return res ; } public FloatBuffer getData ( ) { FloatBuffer buf = data ; buf . position ( <NUM_LIT:0> ) ; return buf . slice ( ) ; } private static int round ( int size ) { return size - ( size % ELEMENT_SIZE ) ; } } </s>
<s> package net . java . joglutils . msg . impl ; import net . java . joglutils . msg . math . * ; public class RayTriangleIntersection { private Vec3f edge1 = new Vec3f ( ) ; private Vec3f edge2 = new Vec3f ( ) ; private Vec3f tvec = new Vec3f ( ) ; private Vec3f pvec = new Vec3f ( ) ; private Vec3f qvec = new Vec3f ( ) ; private static final float EPSILON = <NUM_LIT> ; public boolean intersectTriangle ( Line ray , Vec3f vert0 , Vec3f vert1 , Vec3f vert2 , Vec3f tuv ) { edge1 . sub ( vert1 , vert0 ) ; edge2 . sub ( vert2 , vert0 ) ; pvec . cross ( ray . getDirection ( ) , edge2 ) ; float det = edge1 . dot ( pvec ) ; if ( det > - EPSILON && det < EPSILON ) return false ; float invDet = <NUM_LIT:1.0f> / det ; tvec . sub ( ray . getPoint ( ) , vert0 ) ; float u = tvec . dot ( pvec ) * invDet ; if ( u < <NUM_LIT:0.0f> || u > <NUM_LIT:1.0f> ) return false ; qvec . cross ( tvec , edge1 ) ; float v = ray . getDirection ( ) . dot ( qvec ) * invDet ; if ( v < <NUM_LIT:0.0f> || ( u + v ) > <NUM_LIT:1.0f> ) return false ; float t = edge2 . dot ( qvec ) * invDet ; tuv . set ( t , u , v ) ; return true ; } public boolean intersectTriangleBackfaceCulling ( Line ray , Vec3f vert0 , Vec3f vert1 , Vec3f vert2 , Vec3f tuv ) { edge1 . sub ( vert1 , vert0 ) ; edge2 . sub ( vert2 , vert0 ) ; pvec . cross ( ray . getDirection ( ) , edge2 ) ; float det = edge1 . dot ( pvec ) ; if ( det < EPSILON ) return false ; tvec . sub ( ray . getPoint ( ) , vert0 ) ; float u = tvec . dot ( pvec ) ; if ( u < <NUM_LIT:0.0f> || u > det ) return false ; qvec . cross ( tvec , edge1 ) ; float v = ray . getDirection ( ) . dot ( qvec ) ; if ( v < <NUM_LIT:0.0f> || ( u + v ) > det ) return false ; float t = edge2 . dot ( qvec ) ; float invDet = <NUM_LIT:1.0f> / det ; t *= invDet ; u *= invDet ; v *= invDet ; tuv . set ( t , u , v ) ; return true ; } } </s>
<s> package net . java . joglutils . msg . impl ; import java . nio . * ; import java . util . * ; import com . sun . opengl . util . * ; public class BufferFactory { private static ByteBuffer curByteBuf ; private static ShortBuffer curShortBuf ; private static IntBuffer curIntBuf ; private static FloatBuffer curFloatBuf ; private static DoubleBuffer curDoubleBuf ; private static final int CHUNK_SIZE = <NUM_LIT:8> * <NUM_LIT> ; public static synchronized ByteBuffer newByteBuffer ( int numElements ) { int sz = numElements * BufferUtil . SIZEOF_BYTE ; if ( sz > CHUNK_SIZE ) { return BufferUtil . newByteBuffer ( numElements ) ; } if ( curByteBuf == null || curByteBuf . remaining ( ) < numElements ) { curByteBuf = BufferUtil . newByteBuffer ( CHUNK_SIZE / BufferUtil . SIZEOF_BYTE ) ; } curByteBuf . limit ( curByteBuf . position ( ) + numElements ) ; ByteBuffer res = curByteBuf . slice ( ) ; curByteBuf . position ( curByteBuf . limit ( ) ) ; return res ; } public static synchronized ShortBuffer newShortBuffer ( int numElements ) { int sz = numElements * BufferUtil . SIZEOF_SHORT ; if ( sz > CHUNK_SIZE ) { return BufferUtil . newShortBuffer ( numElements ) ; } if ( curShortBuf == null || curShortBuf . remaining ( ) < numElements ) { curShortBuf = BufferUtil . newShortBuffer ( CHUNK_SIZE / BufferUtil . SIZEOF_SHORT ) ; } curShortBuf . limit ( curShortBuf . position ( ) + numElements ) ; ShortBuffer res = curShortBuf . slice ( ) ; curShortBuf . position ( curShortBuf . limit ( ) ) ; return res ; } public static synchronized IntBuffer newIntBuffer ( int numElements ) { int sz = numElements * BufferUtil . SIZEOF_INT ; if ( sz > CHUNK_SIZE ) { return BufferUtil . newIntBuffer ( numElements ) ; } if ( curIntBuf == null || curIntBuf . remaining ( ) < numElements ) { curIntBuf = BufferUtil . newIntBuffer ( CHUNK_SIZE / BufferUtil . SIZEOF_INT ) ; } curIntBuf . limit ( curIntBuf . position ( ) + numElements ) ; IntBuffer res = curIntBuf . slice ( ) ; curIntBuf . position ( curIntBuf . limit ( ) ) ; return res ; } public static synchronized FloatBuffer newFloatBuffer ( int numElements ) { int sz = numElements * BufferUtil . SIZEOF_FLOAT ; if ( sz > CHUNK_SIZE ) { return BufferUtil . newFloatBuffer ( numElements ) ; } if ( curFloatBuf == null || curFloatBuf . remaining ( ) < numElements ) { curFloatBuf = BufferUtil . newFloatBuffer ( CHUNK_SIZE / BufferUtil . SIZEOF_FLOAT ) ; } curFloatBuf . limit ( curFloatBuf . position ( ) + numElements ) ; FloatBuffer res = curFloatBuf . slice ( ) ; curFloatBuf . position ( curFloatBuf . limit ( ) ) ; return res ; } public static synchronized DoubleBuffer newDoubleBuffer ( int numElements ) { int sz = numElements * BufferUtil . SIZEOF_DOUBLE ; if ( sz > CHUNK_SIZE ) { return BufferUtil . newDoubleBuffer ( numElements ) ; } if ( curDoubleBuf == null || curDoubleBuf . remaining ( ) < numElements ) { curDoubleBuf = BufferUtil . newDoubleBuffer ( CHUNK_SIZE / BufferUtil . SIZEOF_DOUBLE ) ; } curDoubleBuf . limit ( curDoubleBuf . position ( ) + numElements ) ; DoubleBuffer res = curDoubleBuf . slice ( ) ; curDoubleBuf . position ( curDoubleBuf . limit ( ) ) ; return res ; } } </s>
<s> package jgudemos ; import net . java . joglutils . jogltext . TextRenderer3D ; import com . sun . opengl . util . Animator ; import java . awt . Font ; import java . awt . Frame ; import java . awt . event . WindowAdapter ; import java . awt . event . WindowEvent ; import java . awt . geom . Rectangle2D ; import javax . media . opengl . * ; import javax . media . opengl . awt . * ; import javax . media . opengl . glu . * ; public class TestRenderer3D implements GLEventListener { TextRenderer3D tr3 ; float [ ] LightDiffuse = { <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> } ; float [ ] LightAmbient = { <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.0f> } ; float [ ] LightPosition = { <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:0.0f> } ; float [ ] mat_specular = { <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> } ; float [ ] mat_ambient_magenta = { <NUM_LIT:1.0f> , <NUM_LIT:0.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> } ; float [ ] mat_shininess = { <NUM_LIT> } ; public static void main ( String [ ] args ) { Frame frame = new Frame ( "<STR_LIT>" ) ; GLCanvas canvas = new GLCanvas ( ) ; canvas . addGLEventListener ( new TestRenderer3D ( ) ) ; frame . add ( canvas ) ; frame . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Animator animator = new Animator ( canvas ) ; frame . addWindowListener ( new WindowAdapter ( ) { @ Override public void windowClosing ( WindowEvent e ) { new Thread ( new Runnable ( ) { public void run ( ) { animator . stop ( ) ; System . exit ( <NUM_LIT:0> ) ; } } ) . start ( ) ; } } ) ; frame . setLocationRelativeTo ( null ) ; frame . setVisible ( true ) ; animator . start ( ) ; } public void init ( GLAutoDrawable drawable ) { GL2 gl = drawable . getGL ( ) . getGL2 ( ) ; System . out . println ( "<STR_LIT>" + gl . getClass ( ) . getName ( ) + "<STR_LIT>" + this . getClass ( ) . getName ( ) ) ; gl . setSwapInterval ( <NUM_LIT:1> ) ; gl . glClearColor ( <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> ) ; gl . glShadeModel ( GL2 . GL_SMOOTH ) ; gl . glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_DIFFUSE , LightAmbient , <NUM_LIT:0> ) ; gl . glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_DIFFUSE , LightDiffuse , <NUM_LIT:0> ) ; gl . glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_POSITION , LightPosition , <NUM_LIT:0> ) ; gl . glEnable ( GL2 . GL_DEPTH_TEST ) ; gl . glDepthFunc ( GL2 . GL_LESS ) ; tr3 = new TextRenderer3D ( new Font ( "<STR_LIT>" , Font . TRUETYPE_FONT , <NUM_LIT:3> ) , <NUM_LIT> ) ; } public void reshape ( GLAutoDrawable drawable , int x , int y , int width , int height ) { GL2 gl = drawable . getGL ( ) . getGL2 ( ) ; GLU glu = new GLU ( ) ; if ( height <= <NUM_LIT:0> ) height = <NUM_LIT:1> ; final float h = ( float ) width / ( float ) height ; gl . glViewport ( <NUM_LIT:0> , <NUM_LIT:0> , width , height ) ; gl . glMatrixMode ( GL2 . GL_PROJECTION ) ; gl . glLoadIdentity ( ) ; glu . gluPerspective ( <NUM_LIT> , h , <NUM_LIT:1.0> , <NUM_LIT> ) ; gl . glMatrixMode ( GL2 . GL_MODELVIEW ) ; gl . glLoadIdentity ( ) ; } public void display ( GLAutoDrawable drawable ) { GL2 gl = drawable . getGL ( ) . getGL2 ( ) ; gl . glClear ( GL2 . GL_COLOR_BUFFER_BIT | GL2 . GL_DEPTH_BUFFER_BIT ) ; gl . glLoadIdentity ( ) ; gl . glTranslatef ( <NUM_LIT> , <NUM_LIT:0.0f> , - <NUM_LIT> ) ; gl . glRotatef ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) ; String str = "<STR_LIT>" ; Rectangle2D rect = tr3 . getBounds ( str , <NUM_LIT> ) ; float offX = ( float ) rect . getCenterX ( ) ; float offY = ( float ) rect . getCenterY ( ) ; float offZ = tr3 . getDepth ( ) / <NUM_LIT> ; gl . glEnable ( GL2 . GL_LIGHTING ) ; gl . glEnable ( GL2 . GL_LIGHT0 ) ; gl . glMaterialfv ( GL2 . GL_FRONT , GL2 . GL_SPECULAR , mat_specular , <NUM_LIT:0> ) ; gl . glMaterialfv ( GL2 . GL_FRONT , GL2 . GL_SHININESS , mat_shininess , <NUM_LIT:0> ) ; gl . glMaterialfv ( GL2 . GL_FRONT , GL2 . GL_AMBIENT_AND_DIFFUSE , mat_ambient_magenta , <NUM_LIT:0> ) ; tr3 . draw ( str , - offX , offY , - offZ , <NUM_LIT:1.0f> ) ; gl . glFlush ( ) ; } public void dispose ( GLAutoDrawable drawable ) { } } </s>
<s> package jgudemos ; import net . java . joglutils . jogltext . * ; import java . awt . geom . * ; import java . awt . font . * ; import java . awt . * ; import java . awt . event . * ; import javax . swing . * ; import javax . media . opengl . * ; import javax . media . opengl . glu . * ; import com . sun . opengl . util . Animator ; public class FontDrawerDemo { static String helpString = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; static float [ ] light_ambient = { <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:1.0f> } ; static float [ ] light_diffuse = { <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> } ; static float [ ] light_specular = { <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> } ; static float [ ] light_position = { <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:1.0f> , <NUM_LIT:0.0f> } ; static boolean rotating = true ; public static void main ( String [ ] args ) { final float [ ] rotSteps = { <NUM_LIT:0.0f> , <NUM_LIT> , <NUM_LIT:0.0f> } ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( helpString ) ; final String [ ] argsFin = args ; Font font = GraphicsEnvironment . getLocalGraphicsEnvironment ( ) . getAllFonts ( ) [ <NUM_LIT:5> ] ; final FontDrawer dttf = new FontDrawer ( font ) ; final StringBuffer upperStr = new StringBuffer ( "<STR_LIT>" ) ; final StringBuffer lowerStr = new StringBuffer ( "<STR_LIT>" ) ; GLEventListener listener = new GLEventListener ( ) { GLU glu ; float xrot , yrot , zrot ; float dpth = <NUM_LIT> ; boolean filled = true , fnorm = true ; public void reshape ( GLAutoDrawable drawable , int x , int y , int width , int height ) { } public void init ( GLAutoDrawable drawable ) { drawable . setGL ( new DebugGL2 ( drawable . getGL ( ) . getGL2 ( ) ) ) ; glu = new GLU ( ) ; switch ( argsFin . length ) { case <NUM_LIT:6> : fnorm = Boolean . parseBoolean ( argsFin [ <NUM_LIT:5> ] ) ; case <NUM_LIT:5> : filled = Boolean . parseBoolean ( argsFin [ <NUM_LIT:4> ] ) ; case <NUM_LIT:4> : rotSteps [ <NUM_LIT:2> ] = Float . parseFloat ( argsFin [ <NUM_LIT:3> ] ) ; case <NUM_LIT:3> : rotSteps [ <NUM_LIT:1> ] = Float . parseFloat ( argsFin [ <NUM_LIT:2> ] ) ; case <NUM_LIT:2> : rotSteps [ <NUM_LIT:0> ] = Float . parseFloat ( argsFin [ <NUM_LIT:1> ] ) ; case <NUM_LIT:1> : dpth = Float . parseFloat ( argsFin [ <NUM_LIT:0> ] ) ; } dttf . setDepth ( dpth ) ; dttf . setFill ( filled ) ; dttf . setNormal ( FontDrawer . NormalMode . FLAT ) ; xrot = <NUM_LIT:0> ; yrot = <NUM_LIT:0> ; zrot = <NUM_LIT:0> ; GL2 gl = drawable . getGL ( ) . getGL2 ( ) ; gl . glColorMaterial ( GL2 . GL_FRONT_AND_BACK , GL2 . GL_AMBIENT_AND_DIFFUSE ) ; float [ ] mamb = { <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> } ; gl . glLightModelfv ( GL2 . GL_LIGHT_MODEL_AMBIENT , mamb , <NUM_LIT:0> ) ; gl . glEnable ( GL2 . GL_DEPTH_TEST ) ; gl . glEnable ( GL2 . GL_LIGHTING ) ; gl . glEnable ( GL2 . GL_LIGHT0 ) ; gl . glEnable ( GL2 . GL_NORMALIZE ) ; gl . glClearColor ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> ) ; } public void drawAxis ( GL2 gl ) { gl . glDisable ( GL2 . GL_LIGHTING ) ; gl . glBegin ( GL2 . GL_LINES ) ; gl . glColor3f ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ; gl . glVertex3i ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ; gl . glVertex3i ( <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:0> ) ; gl . glColor3f ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) ; gl . glVertex3i ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ; gl . glVertex3i ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:0> ) ; gl . glColor3f ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) ; gl . glVertex3i ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ; gl . glVertex3i ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:10> ) ; gl . glEnd ( ) ; gl . glEnable ( GL2 . GL_LIGHTING ) ; } public void display ( GLAutoDrawable drawable ) { GL2 gl = drawable . getGL ( ) . getGL2 ( ) ; gl . glClear ( GL2 . GL_COLOR_BUFFER_BIT | GL2 . GL_DEPTH_BUFFER_BIT ) ; gl . glMatrixMode ( GL2 . GL_PROJECTION ) ; gl . glLoadIdentity ( ) ; gl . glOrtho ( - <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> , - <NUM_LIT:5> , <NUM_LIT:5> ) ; gl . glMatrixMode ( GL2 . GL_MODELVIEW ) ; gl . glLoadIdentity ( ) ; gl . glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_AMBIENT , light_ambient , <NUM_LIT:0> ) ; gl . glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_DIFFUSE , light_diffuse , <NUM_LIT:0> ) ; gl . glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_SPECULAR , light_specular , <NUM_LIT:0> ) ; gl . glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_POSITION , light_position , <NUM_LIT:0> ) ; glu . gluLookAt ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) ; gl . glRotatef ( xrot , <NUM_LIT:1.0f> , <NUM_LIT:0> , <NUM_LIT:0> ) ; gl . glRotatef ( yrot , <NUM_LIT:0> , <NUM_LIT:1.0f> , <NUM_LIT:0> ) ; gl . glRotatef ( zrot , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1.0f> ) ; if ( rotating ) { xrot += rotSteps [ <NUM_LIT:0> ] ; yrot += rotSteps [ <NUM_LIT:1> ] ; zrot += rotSteps [ <NUM_LIT:2> ] ; } drawAxis ( gl ) ; dttf . drawString ( upperStr . toString ( ) , glu , gl ) ; dttf . drawString ( lowerStr . toString ( ) , glu , gl , - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT:0> ) ; } public void dispose ( GLAutoDrawable drawable ) { } } ; final net . java . joglutils . GLJFrame gljf = new net . java . joglutils . GLJFrame ( "<STR_LIT>" , listener , <NUM_LIT> , <NUM_LIT> ) ; gljf . setDefaultCloseOperation ( gljf . EXIT_ON_CLOSE ) ; gljf . addKeyListener ( new java . awt . event . KeyAdapter ( ) { public void keyPressed ( KeyEvent e ) { char test = e . getKeyChar ( ) ; switch ( e . getKeyChar ( ) ) { case '<CHAR_LIT>' : FontDrawer fd = dttf ; dttf . setFill ( ! dttf . isFill ( ) ) ; break ; case '<CHAR_LIT>' : switch ( dttf . getNormal ( ) ) { case NONE : dttf . setNormal ( FontDrawer . NormalMode . FLAT ) ; break ; case FLAT : dttf . setNormal ( FontDrawer . NormalMode . AVERAGED ) ; break ; case AVERAGED : dttf . setNormal ( FontDrawer . NormalMode . NONE ) ; break ; } break ; case '<CHAR_LIT>' : Animator anim = gljf . getAnimator ( ) ; if ( rotating ) { anim . stop ( ) ; rotating = false ; } else { anim . start ( ) ; rotating = true ; } break ; case '<CHAR_LIT>' : try { String strRes ; strRes = JOptionPane . showInputDialog ( "<STR_LIT>" , Float . toString ( rotSteps [ <NUM_LIT:0> ] ) ) ; if ( strRes != null ) { rotSteps [ <NUM_LIT:0> ] = Float . parseFloat ( strRes ) ; strRes = JOptionPane . showInputDialog ( "<STR_LIT>" , Float . toString ( rotSteps [ <NUM_LIT:1> ] ) ) ; if ( strRes != null ) { rotSteps [ <NUM_LIT:1> ] = Float . parseFloat ( strRes ) ; strRes = JOptionPane . showInputDialog ( "<STR_LIT>" , Float . toString ( rotSteps [ <NUM_LIT:2> ] ) ) ; if ( strRes != null ) rotSteps [ <NUM_LIT:2> ] = Float . parseFloat ( strRes ) ; } } } catch ( Exception ignore ) { } break ; case '<CHAR_LIT:>>' : case '<CHAR_LIT:.>' : float depthStep = dttf . getFont ( ) . getSize ( ) / <NUM_LIT> ; dttf . setDepth ( dttf . getDepth ( ) + depthStep ) ; break ; case '<CHAR_LIT>' : case '<CHAR_LIT:U+002C>' : depthStep = dttf . getFont ( ) . getSize ( ) / <NUM_LIT> ; dttf . setDepth ( dttf . getDepth ( ) - depthStep ) ; break ; case '<CHAR_LIT>' : case '<CHAR_LIT>' : String up = JOptionPane . showInputDialog ( "<STR_LIT>" , upperStr . toString ( ) ) ; upperStr . delete ( <NUM_LIT:0> , upperStr . length ( ) ) ; upperStr . append ( up ) ; String dn = JOptionPane . showInputDialog ( "<STR_LIT>" , lowerStr . toString ( ) ) ; lowerStr . delete ( <NUM_LIT:0> , lowerStr . length ( ) ) ; lowerStr . append ( dn ) ; break ; case '<CHAR_LIT>' : Font [ ] fonts = GraphicsEnvironment . getLocalGraphicsEnvironment ( ) . getAllFonts ( ) ; JPanel pan = new JPanel ( ) ; JComboBox cb = new JComboBox ( ) ; for ( Font f : fonts ) cb . addItem ( f ) ; cb . setSelectedItem ( dttf . getFont ( ) ) ; pan . add ( cb ) ; net . java . joglutils . JPanelDialog jpd = new net . java . joglutils . JPanelDialog ( "<STR_LIT>" , pan ) ; if ( jpd . showAsModal ( ) ) dttf . setFont ( ( Font ) cb . getSelectedItem ( ) ) ; break ; case '<CHAR_LIT>' : Font currFont = dttf . getFont ( ) ; String resultStr = JOptionPane . showInputDialog ( "<STR_LIT>" , Integer . toString ( currFont . getSize ( ) ) ) ; float targSize = Float . parseFloat ( resultStr ) ; dttf . setFont ( currFont . deriveFont ( currFont . getStyle ( ) , targSize ) ) ; break ; case '<CHAR_LIT>' : try { String xStr = JOptionPane . showInputDialog ( null , "<STR_LIT>" , Float . toString ( light_position [ <NUM_LIT:0> ] ) ) ; light_position [ <NUM_LIT:0> ] = Float . parseFloat ( xStr ) ; String yStr = JOptionPane . showInputDialog ( null , "<STR_LIT>" , Float . toString ( light_position [ <NUM_LIT:1> ] ) ) ; light_position [ <NUM_LIT:1> ] = Float . parseFloat ( yStr ) ; String zStr = JOptionPane . showInputDialog ( null , "<STR_LIT>" , Float . toString ( light_position [ <NUM_LIT:2> ] ) ) ; light_position [ <NUM_LIT:2> ] = Float . parseFloat ( zStr ) ; String wStr = JOptionPane . showInputDialog ( null , "<STR_LIT>" , Float . toString ( light_position [ <NUM_LIT:3> ] ) ) ; light_position [ <NUM_LIT:3> ] = Float . parseFloat ( wStr ) ; } catch ( Exception ignore ) { } break ; case '<CHAR_LIT>' : System . out . println ( helpString ) ; JOptionPane . showMessageDialog ( null , helpString ) ; break ; default : switch ( e . getKeyCode ( ) ) { case KeyEvent . VK_F1 : System . out . println ( helpString ) ; JOptionPane . showMessageDialog ( null , helpString ) ; break ; } } gljf . repaint ( ) ; } } ) ; gljf . generateAnimator ( ) ; gljf . setVisible ( true ) ; } } </s>
<s> package jgudemos ; import net . java . joglutils . * ; import javax . media . opengl . * ; public class BasicGLJFrameDemo { public static void main ( String [ ] args ) { GLJFrame gljf = new GLJFrame ( new GLEventListener ( ) { public void reshape ( GLAutoDrawable drawable , int x , int y , int width , int height ) { } public void init ( GLAutoDrawable drawable ) { } public void display ( GLAutoDrawable drawable ) { GL2 gl = drawable . getGL ( ) . getGL2 ( ) ; gl . glClear ( GL2 . GL_COLOR_BUFFER_BIT | GL2 . GL_DEPTH_BUFFER_BIT ) ; gl . glColor3f ( <NUM_LIT:1.0f> , <NUM_LIT> , <NUM_LIT> ) ; gl . glBegin ( GL2 . GL_TRIANGLE_STRIP ) ; gl . glVertex2d ( <NUM_LIT:0> , <NUM_LIT:0> ) ; gl . glVertex2d ( <NUM_LIT> , <NUM_LIT:1.0> ) ; gl . glVertex2d ( - <NUM_LIT> , - <NUM_LIT> ) ; gl . glEnd ( ) ; } public void dispose ( GLAutoDrawable drawable ) { } } ) ; gljf . setDefaultCloseOperation ( gljf . EXIT_ON_CLOSE ) ; gljf . setVisible ( true ) ; } } </s>
<s> package jgudemos ; import java . awt . Color ; import java . awt . Font ; import java . awt . Frame ; import java . awt . event . WindowAdapter ; import java . awt . event . WindowEvent ; import java . awt . geom . Rectangle2D ; import java . lang . reflect . Array ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . Random ; import javax . media . opengl . * ; import javax . media . opengl . awt . * ; import javax . media . opengl . glu . * ; import javax . vecmath . Point3f ; import net . java . joglutils . jogltext . TextRenderer3D ; import com . sun . opengl . util . Animator ; public class BouncingText3D implements GLEventListener { TextRenderer3D tr3 ; float [ ] LightDiffuse = { <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> } ; float [ ] LightAmbient = { <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.0f> } ; float [ ] LightPosition = { <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:0.0f> } ; float [ ] mat_specular = { <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> } ; float [ ] mat_ambient_magenta = { <NUM_LIT:1.0f> , <NUM_LIT:0.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> } ; float [ ] mat_shininess = { <NUM_LIT> } ; protected Random random = new Random ( ) ; public static final int NUM_ITEMS = <NUM_LIT:20> ; public static final int MAX_ITEMS = <NUM_LIT> ; private static int numItems = NUM_ITEMS ; private ArrayList < TextInfo3D > textInfo = new ArrayList < TextInfo3D > ( ) ; private GLU glu = new GLU ( ) ; protected GLUquadric QUADRIC ; public static void main ( String [ ] args ) { if ( args != null && Array . getLength ( args ) > <NUM_LIT:0> ) { numItems = Integer . parseInt ( args [ <NUM_LIT:0> ] . trim ( ) ) ; if ( numItems == <NUM_LIT:0> ) numItems = NUM_ITEMS ; else if ( numItems > MAX_ITEMS ) numItems = MAX_ITEMS ; } Frame frame = new Frame ( "<STR_LIT>" ) ; GLCanvas canvas = new GLCanvas ( ) ; canvas . addGLEventListener ( new BouncingText3D ( ) ) ; frame . add ( canvas ) ; frame . setSize ( <NUM_LIT> , <NUM_LIT> ) ; final Animator animator = new Animator ( canvas ) ; frame . addWindowListener ( new WindowAdapter ( ) { @ Override public void windowClosing ( WindowEvent e ) { new Thread ( new Runnable ( ) { public void run ( ) { animator . stop ( ) ; System . exit ( <NUM_LIT:0> ) ; } } ) . start ( ) ; } } ) ; frame . setLocationRelativeTo ( null ) ; frame . setVisible ( true ) ; animator . start ( ) ; } public void init ( GLAutoDrawable drawable ) { QUADRIC = glu . gluNewQuadric ( ) ; GL2 gl = drawable . getGL ( ) . getGL2 ( ) ; System . out . println ( "<STR_LIT>" + gl . getClass ( ) . getName ( ) ) ; System . out . println ( "<STR_LIT>" + gl . getClass ( ) . getName ( ) + "<STR_LIT>" + this . getClass ( ) . getName ( ) ) ; gl . setSwapInterval ( <NUM_LIT:1> ) ; gl . glClearColor ( <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> ) ; gl . glShadeModel ( GL2 . GL_SMOOTH ) ; gl . glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_DIFFUSE , LightAmbient , <NUM_LIT:0> ) ; gl . glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_DIFFUSE , LightDiffuse , <NUM_LIT:0> ) ; gl . glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_POSITION , LightPosition , <NUM_LIT:0> ) ; gl . glEnable ( GL2 . GL_DEPTH_TEST ) ; gl . glDepthFunc ( GL2 . GL_LESS ) ; gl . glEnable ( GL2 . GL_BLEND ) ; gl . glEnable ( GL2 . GL_LINE_SMOOTH ) ; gl . glBlendFunc ( GL2 . GL_SRC_ALPHA , GL2 . GL_ONE_MINUS_SRC_ALPHA ) ; tr3 = new TextRenderer3D ( new Font ( "<STR_LIT>" , Font . TRUETYPE_FONT , <NUM_LIT:3> ) , <NUM_LIT> ) ; textInfo . clear ( ) ; for ( int i = <NUM_LIT:0> ; i < numItems ; i ++ ) { textInfo . add ( randomTextInfo ( ) ) ; } } public void reshape ( GLAutoDrawable drawable , int x , int y , int width , int height ) { GL2 gl = drawable . getGL ( ) . getGL2 ( ) ; if ( height <= <NUM_LIT:0> ) height = <NUM_LIT:1> ; final float h = ( float ) width / ( float ) height ; gl . glViewport ( <NUM_LIT:0> , <NUM_LIT:0> , width , height ) ; gl . glMatrixMode ( GL2 . GL_PROJECTION ) ; gl . glLoadIdentity ( ) ; glu . gluPerspective ( <NUM_LIT> , h , <NUM_LIT:1.0> , <NUM_LIT> ) ; gl . glMatrixMode ( GL2 . GL_MODELVIEW ) ; gl . glLoadIdentity ( ) ; } public void display ( GLAutoDrawable drawable ) { GL2 gl = drawable . getGL ( ) . getGL2 ( ) ; gl . glClear ( GL2 . GL_COLOR_BUFFER_BIT | GL2 . GL_DEPTH_BUFFER_BIT ) ; gl . glMaterialfv ( GL2 . GL_FRONT , GL2 . GL_SPECULAR , mat_specular , <NUM_LIT:0> ) ; gl . glMaterialfv ( GL2 . GL_FRONT , GL2 . GL_SHININESS , mat_shininess , <NUM_LIT:0> ) ; gl . glLoadIdentity ( ) ; gl . glTranslatef ( <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , - <NUM_LIT> ) ; gl . glRotatef ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ; gl . glRotatef ( - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) ; try { gl . glEnable ( GL2 . GL_LIGHTING ) ; gl . glEnable ( GL2 . GL_LIGHT0 ) ; drawAxes ( gl ) ; for ( Iterator iter = textInfo . iterator ( ) ; iter . hasNext ( ) ; ) { TextInfo3D info = ( TextInfo3D ) iter . next ( ) ; updateTextInfo ( info ) ; gl . glPushAttrib ( GL2 . GL_TRANSFORM_BIT ) ; gl . glMatrixMode ( GL2 . GL_MODELVIEW ) ; gl . glPushMatrix ( ) ; gl . glEnable ( GL2 . GL_NORMALIZE ) ; gl . glTranslatef ( info . position . x , info . position . y , info . position . z ) ; gl . glRotatef ( info . angle . x , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ; gl . glRotatef ( info . angle . y , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) ; gl . glRotatef ( info . angle . z , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) ; gl . glMaterialfv ( GL2 . GL_FRONT_AND_BACK , GL2 . GL_AMBIENT_AND_DIFFUSE , info . material , <NUM_LIT:0> ) ; tr3 . call ( info . index ) ; gl . glPopMatrix ( ) ; gl . glPopAttrib ( ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } } public void dispose ( GLAutoDrawable drawable ) { } private static final float INIT_ANG_VEL_MAG = <NUM_LIT> ; private static final float INIT_VEL_MAG = <NUM_LIT> ; private static final float MAX_BOUNDS = <NUM_LIT> ; private static final float SCALE_FACTOR = <NUM_LIT> ; private static class TextInfo3D { Point3f angularVelocity ; Point3f velocity ; Point3f position ; Point3f angle ; float h ; float s ; float v ; int index ; float curTime ; float [ ] material = new float [ <NUM_LIT:4> ] ; float r ; float g ; float b ; String text ; } Point3f tmp = new Point3f ( ) ; private void updateTextInfo ( TextInfo3D info ) { float deltaT = <NUM_LIT> ; if ( random . nextInt ( <NUM_LIT> ) == <NUM_LIT:0> ) { info . angularVelocity = randomRotation ( INIT_ANG_VEL_MAG , INIT_ANG_VEL_MAG , INIT_ANG_VEL_MAG ) ; info . velocity = randomVelocity ( INIT_VEL_MAG , INIT_VEL_MAG , INIT_VEL_MAG ) ; } tmp . set ( info . angularVelocity ) ; tmp . scale ( deltaT * deltaT ) ; info . angle . add ( tmp ) ; tmp . set ( info . velocity ) ; tmp . scale ( deltaT ) ; info . position . add ( tmp ) ; info . angle . x = clampAngle ( info . angle . x ) ; info . angle . y = clampAngle ( info . angle . y ) ; info . angle . z = clampAngle ( info . angle . z ) ; info . velocity . x = clampBounds ( info . position . x , info . velocity . x ) ; info . velocity . y = clampBounds ( info . position . y , info . velocity . y ) ; info . velocity . z = clampBounds ( info . position . z , info . velocity . z ) ; } private float clampBounds ( float pos , float velocity ) { if ( pos < - MAX_BOUNDS || pos > MAX_BOUNDS ) { velocity *= - <NUM_LIT:1.0f> ; } return velocity ; } private float clampAngle ( float angle ) { if ( angle < <NUM_LIT:0> ) { angle += <NUM_LIT> ; } else if ( angle > <NUM_LIT> ) { angle -= <NUM_LIT> ; } return angle ; } private TextInfo3D randomTextInfo ( ) { TextInfo3D info = new TextInfo3D ( ) ; info . text = randomString ( ) ; info . angle = randomRotation ( INIT_ANG_VEL_MAG , INIT_ANG_VEL_MAG , INIT_ANG_VEL_MAG ) ; info . position = randomVector ( MAX_BOUNDS , MAX_BOUNDS , MAX_BOUNDS ) ; Rectangle2D rect = tr3 . getBounds ( info . text , SCALE_FACTOR ) ; float offX = ( float ) rect . getCenterX ( ) ; float offY = ( float ) rect . getCenterY ( ) ; float offZ = tr3 . getDepth ( ) / <NUM_LIT> ; tr3 . setDepth ( <NUM_LIT> + random . nextFloat ( ) * <NUM_LIT> ) ; info . index = tr3 . compile ( info . text , - offX , offY , - offZ , SCALE_FACTOR ) ; info . angularVelocity = randomRotation ( INIT_ANG_VEL_MAG , INIT_ANG_VEL_MAG , INIT_ANG_VEL_MAG ) ; info . velocity = randomVelocity ( INIT_VEL_MAG , INIT_VEL_MAG , INIT_VEL_MAG ) ; Color c = randomColor ( ) ; c . getColorComponents ( info . material ) ; info . material [ <NUM_LIT:3> ] = random . nextFloat ( ) * <NUM_LIT> + <NUM_LIT> ; return info ; } private String randomString ( ) { switch ( random . nextInt ( <NUM_LIT:3> ) ) { case <NUM_LIT:0> : return "<STR_LIT>" ; case <NUM_LIT:1> : return "<STR_LIT>" ; default : return "<STR_LIT>" ; } } private Point3f randomVector ( float x , float y , float z ) { return new Point3f ( x * random . nextFloat ( ) , y * random . nextFloat ( ) , z * random . nextFloat ( ) ) ; } private Point3f randomVelocity ( float x , float y , float z ) { return new Point3f ( x * ( random . nextFloat ( ) - <NUM_LIT> ) , y * ( random . nextFloat ( ) - <NUM_LIT> ) , z * ( random . nextFloat ( ) - <NUM_LIT> ) ) ; } private Point3f randomRotation ( float x , float y , float z ) { return new Point3f ( random . nextFloat ( ) * <NUM_LIT> , random . nextFloat ( ) * <NUM_LIT> , random . nextFloat ( ) * <NUM_LIT> ) ; } private Color randomColor ( ) { float r = <NUM_LIT:0> ; float g = <NUM_LIT:0> ; float b = <NUM_LIT:0> ; float s = <NUM_LIT:0> ; do { r = random . nextFloat ( ) ; g = random . nextFloat ( ) ; b = random . nextFloat ( ) ; float [ ] hsb = Color . RGBtoHSB ( ( int ) ( <NUM_LIT> * r ) , ( int ) ( <NUM_LIT> * g ) , ( int ) ( <NUM_LIT> * b ) , null ) ; s = hsb [ <NUM_LIT:1> ] ; } while ( ( r < <NUM_LIT> && g < <NUM_LIT> && b < <NUM_LIT> ) || s < <NUM_LIT> ) ; return new Color ( r , g , b ) ; } protected void drawAxes ( GL2 gl ) { float [ ] mat_ambient_red = { <NUM_LIT:1.0f> , <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:1.0f> } ; float [ ] mat_ambient_green = { <NUM_LIT:0.0f> , <NUM_LIT:1.0f> , <NUM_LIT:0.0f> , <NUM_LIT:1.0f> } ; float [ ] mat_ambient_blue = { <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , <NUM_LIT:1.0f> , <NUM_LIT:1.0f> } ; drawAxis ( gl , <NUM_LIT:2> , mat_ambient_red ) ; drawAxis ( gl , <NUM_LIT:0> , mat_ambient_blue ) ; drawAxis ( gl , <NUM_LIT:1> , mat_ambient_green ) ; } private void drawAxis ( GL2 gl , int rot , float [ ] material ) { float [ ] mat_ambient_grey = { <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.0f> } ; final double AXIS_RADIUS = <NUM_LIT> ; final int AXIS_HEIGHT = <NUM_LIT:5> ; final float AXIS_STEP = <NUM_LIT> ; gl . glPushMatrix ( ) ; if ( rot == <NUM_LIT:1> ) gl . glRotatef ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ; else if ( rot == <NUM_LIT:0> ) gl . glRotatef ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) ; gl . glTranslatef ( <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , ( float ) - AXIS_HEIGHT / <NUM_LIT> ) ; float pos = - AXIS_HEIGHT / <NUM_LIT> ; int i = <NUM_LIT:0> ; while ( pos < AXIS_HEIGHT / <NUM_LIT> ) { if ( ( i ++ & <NUM_LIT:1> ) == <NUM_LIT:0> ) gl . glMaterialfv ( GL2 . GL_FRONT , GL2 . GL_AMBIENT_AND_DIFFUSE , material , <NUM_LIT:0> ) ; else gl . glMaterialfv ( GL2 . GL_FRONT , GL2 . GL_AMBIENT_AND_DIFFUSE , mat_ambient_grey , <NUM_LIT:0> ) ; glu . gluCylinder ( QUADRIC , AXIS_RADIUS , AXIS_RADIUS , AXIS_STEP , <NUM_LIT:8> , <NUM_LIT:1> ) ; gl . glTranslatef ( <NUM_LIT:0.0f> , <NUM_LIT:0.0f> , AXIS_STEP ) ; pos += AXIS_STEP ; } gl . glPopMatrix ( ) ; } } </s>
<s> package com . komamitsu . addressbook . controller ; import javax . validation . Valid ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import org . springframework . beans . factory . annotation . Autowired ; import org . springframework . stereotype . Controller ; import org . springframework . ui . Model ; import org . springframework . validation . BindingResult ; import org . springframework . web . bind . annotation . RequestMapping ; import org . springframework . web . bind . annotation . RequestMethod ; import com . komamitsu . addressbook . domain . Person ; import com . komamitsu . addressbook . repository . PersonDao ; @ Controller @ RequestMapping ( value = "<STR_LIT>" ) public class PersonController { private Logger logger = LoggerFactory . getLogger ( PersonController . class ) ; @ Autowired private PersonDao personDao ; @ RequestMapping ( value = "<STR_LIT:list>" , method = RequestMethod . GET ) public String getAddressList ( Model model ) { model . addAttribute ( "<STR_LIT>" , personDao . selectAll ( ) ) ; return "<STR_LIT>" ; } @ RequestMapping ( value = "<STR_LIT>" , method = RequestMethod . GET ) public String createForm ( Model model ) { model . addAttribute ( "<STR_LIT>" , new Person ( ) ) ; return "<STR_LIT>" ; } @ RequestMapping ( value = "<STR_LIT>" , method = RequestMethod . POST ) public String create ( @ Valid Person person , BindingResult result ) { if ( result . hasErrors ( ) ) { logger . warn ( result . getFieldErrors ( ) . toString ( ) ) ; return "<STR_LIT>" ; } this . personDao . insert ( person ) ; return "<STR_LIT>" ; } } </s>
<s> package com . komamitsu . addressbook . controller ; import javax . validation . Valid ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import org . springframework . beans . factory . annotation . Autowired ; import org . springframework . stereotype . Controller ; import org . springframework . ui . Model ; import org . springframework . validation . BindingResult ; import org . springframework . web . bind . annotation . RequestMapping ; import org . springframework . web . bind . annotation . RequestMethod ; import com . komamitsu . addressbook . domain . Project ; import com . komamitsu . addressbook . repository . ProjectDao ; @ Controller @ RequestMapping ( value = "<STR_LIT>" ) public class ProjectController { private Logger logger = LoggerFactory . getLogger ( ProjectController . class ) ; @ Autowired private ProjectDao projectDao ; @ RequestMapping ( value = "<STR_LIT:list>" , method = RequestMethod . GET ) public String getAddressList ( Model model ) { model . addAttribute ( "<STR_LIT>" , projectDao . selectAll ( ) ) ; return "<STR_LIT>" ; } @ RequestMapping ( value = "<STR_LIT>" , method = RequestMethod . GET ) public String createForm ( Model model ) { model . addAttribute ( "<STR_LIT>" , new Project ( ) ) ; return "<STR_LIT>" ; } @ RequestMapping ( value = "<STR_LIT>" , method = RequestMethod . POST ) public String create ( @ Valid Project project , BindingResult result ) { if ( result . hasErrors ( ) ) { logger . warn ( result . getFieldErrors ( ) . toString ( ) ) ; return "<STR_LIT>" ; } this . projectDao . insert ( project ) ; return "<STR_LIT>" ; } } </s>
<s> package com . komamitsu . addressbook . controller ; import javax . validation . Valid ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import org . springframework . beans . factory . annotation . Autowired ; import org . springframework . stereotype . Controller ; import org . springframework . ui . Model ; import org . springframework . validation . BindingResult ; import org . springframework . web . bind . annotation . RequestMapping ; import org . springframework . web . bind . annotation . RequestMethod ; import com . komamitsu . addressbook . domain . Person ; import com . komamitsu . addressbook . repository . PersonDao ; @ Controller @ RequestMapping ( value = "<STR_LIT>" ) public class PersonListController { private Logger logger = LoggerFactory . getLogger ( PersonListController . class ) ; @ Autowired private PersonDao personDao ; @ RequestMapping ( value = "<STR_LIT:list>" , method = RequestMethod . GET ) public String getAddressList ( Model model ) { model . addAttribute ( "<STR_LIT>" , personDao . selectAll ( ) ) ; return "<STR_LIT>" ; } @ RequestMapping ( value = "<STR_LIT>" , method = RequestMethod . GET ) public String createForm ( Model model ) { model . addAttribute ( "<STR_LIT>" , new Person ( ) ) ; return "<STR_LIT>" ; } @ RequestMapping ( value = "<STR_LIT>" , method = RequestMethod . POST ) public String create ( @ Valid Person person , BindingResult result ) { if ( result . hasErrors ( ) ) { logger . warn ( result . getFieldErrors ( ) . toString ( ) ) ; return "<STR_LIT>" ; } this . personDao . insert ( person ) ; return "<STR_LIT>" ; } } </s>
<s> package com . komamitsu . addressbook . controller ; import javax . validation . Valid ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import org . springframework . beans . factory . annotation . Autowired ; import org . springframework . stereotype . Controller ; import org . springframework . ui . Model ; import org . springframework . validation . BindingResult ; import org . springframework . web . bind . annotation . RequestMapping ; import org . springframework . web . bind . annotation . RequestMethod ; import com . komamitsu . addressbook . domain . Person ; import com . komamitsu . addressbook . repository . PersonDao ; @ Controller @ RequestMapping ( value = "<STR_LIT>" ) public class AddressListController { private Logger logger = LoggerFactory . getLogger ( AddressListController . class ) ; @ Autowired private PersonDao personDao ; @ RequestMapping ( value = "<STR_LIT:list>" , method = RequestMethod . GET ) public String getAddressList ( Model model ) { model . addAttribute ( "<STR_LIT>" , personDao . selectAll ( ) ) ; return "<STR_LIT>" ; } @ RequestMapping ( value = "<STR_LIT>" , method = RequestMethod . GET ) public String createForm ( Model model ) { model . addAttribute ( "<STR_LIT>" , new Person ( ) ) ; return "<STR_LIT>" ; } @ RequestMapping ( value = "<STR_LIT>" , method = RequestMethod . POST ) public String create ( @ Valid Person person , BindingResult result ) { if ( result . hasErrors ( ) ) { logger . warn ( result . getFieldErrors ( ) . toString ( ) ) ; return "<STR_LIT>" ; } this . personDao . insert ( person ) ; return "<STR_LIT>" ; } } </s>
<s> package com . komamitsu . addressbook . repository . impl ; import java . util . List ; import org . springframework . beans . factory . annotation . Autowired ; import org . springframework . beans . factory . annotation . Qualifier ; import org . springframework . orm . ibatis . support . SqlMapClientDaoSupport ; import org . springframework . stereotype . Repository ; import com . ibatis . sqlmap . client . SqlMapClient ; import com . komamitsu . addressbook . domain . Project ; import com . komamitsu . addressbook . repository . ProjectDao ; @ Repository public class SqlMapProjectDaoImpl extends SqlMapClientDaoSupport implements ProjectDao { private static final String NAMESPACE = "<STR_LIT>" ; @ Autowired @ Qualifier ( "<STR_LIT>" ) public void injectSqlMapClient ( SqlMapClient sqlMapClient ) { setSqlMapClient ( sqlMapClient ) ; } @ Override @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public List < Project > selectAll ( ) { return getSqlMapClientTemplate ( ) . queryForList ( NAMESPACE + "<STR_LIT>" ) ; } @ Override public Long insert ( Project project ) { return ( Long ) getSqlMapClientTemplate ( ) . insert ( NAMESPACE + "<STR_LIT>" , project ) ; } @ Override public void update ( Project project ) { getSqlMapClientTemplate ( ) . update ( NAMESPACE + "<STR_LIT>" , project ) ; } @ Override public void delete ( Project project ) { getSqlMapClientTemplate ( ) . delete ( NAMESPACE + "<STR_LIT>" , project ) ; } @ Override public Project selectById ( long id ) { return ( Project ) getSqlMapClientTemplate ( ) . queryForObject ( NAMESPACE + "<STR_LIT>" , id ) ; } } </s>
<s> package com . komamitsu . addressbook . repository . impl ; import java . util . List ; import org . springframework . beans . factory . annotation . Autowired ; import org . springframework . beans . factory . annotation . Qualifier ; import org . springframework . orm . ibatis . support . SqlMapClientDaoSupport ; import org . springframework . stereotype . Repository ; import com . ibatis . sqlmap . client . SqlMapClient ; import com . komamitsu . addressbook . domain . Person ; import com . komamitsu . addressbook . repository . PersonDao ; @ Repository public class SqlMapPersonDaoImpl extends SqlMapClientDaoSupport implements PersonDao { private static final String NAMESPACE = "<STR_LIT>" ; @ Autowired @ Qualifier ( "<STR_LIT>" ) public void injectSqlMapClient ( SqlMapClient sqlMapClient ) { setSqlMapClient ( sqlMapClient ) ; } @ Override @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public List < Person > selectAll ( ) { return getSqlMapClientTemplate ( ) . queryForList ( NAMESPACE + "<STR_LIT>" ) ; } @ Override public Long insert ( Person person ) { return ( Long ) getSqlMapClientTemplate ( ) . insert ( NAMESPACE + "<STR_LIT>" , person ) ; } @ Override public void update ( Person person ) { getSqlMapClientTemplate ( ) . update ( NAMESPACE + "<STR_LIT>" , person ) ; } @ Override public void delete ( Person person ) { getSqlMapClientTemplate ( ) . delete ( NAMESPACE + "<STR_LIT>" , person ) ; } @ Override public Person selectById ( long id ) { return ( Person ) getSqlMapClientTemplate ( ) . queryForObject ( NAMESPACE + "<STR_LIT>" , id ) ; } } </s>
<s> package com . komamitsu . addressbook . repository ; import java . util . List ; import com . komamitsu . addressbook . domain . Person ; public interface PersonDao { Person selectById ( long id ) ; List < Person > selectAll ( ) ; Long insert ( Person person ) ; void update ( Person person ) ; void delete ( Person person ) ; } </s>
<s> package com . komamitsu . addressbook . repository ; import java . util . List ; import com . komamitsu . addressbook . domain . Project ; public interface ProjectDao { Project selectById ( long id ) ; List < Project > selectAll ( ) ; Long insert ( Project project ) ; void update ( Project project ) ; void delete ( Project project ) ; } </s>
<s> package com . komamitsu . addressbook . domain ; import org . hibernate . validator . constraints . NotEmpty ; public class Project { private Long id ; @ NotEmpty private String name ; public Long getId ( ) { return id ; } public void setId ( Long id ) { this . id = id ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } } </s>
<s> package com . komamitsu . addressbook . domain ; import org . hibernate . validator . constraints . NotEmpty ; public class Person { private Long id ; @ NotEmpty private String name ; @ NotEmpty private String postcode ; @ NotEmpty private String address ; public Long getId ( ) { return id ; } public void setId ( Long id ) { this . id = id ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public String getPostcode ( ) { return postcode ; } public void setPostcode ( String postcode ) { this . postcode = postcode ; } public String getAddress ( ) { return address ; } public void setAddress ( String address ) { this . address = address ; } } </s>
<s> package com . komamitsu . addressbook . domain ; import static org . junit . Assert . assertEquals ; import org . junit . After ; import org . junit . AfterClass ; import org . junit . Before ; import org . junit . BeforeClass ; import org . junit . Test ; public class TestProject { private Project project ; @ BeforeClass public static void setUpBeforeClass ( ) throws Exception { } @ AfterClass public static void tearDownAfterClass ( ) throws Exception { } @ Before public void setUp ( ) throws Exception { project = new Project ( ) ; } @ After public void tearDown ( ) throws Exception { } @ Test public void testAccessorOfName ( ) { project . setName ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , project . getName ( ) ) ; } } </s>
<s> package com . komamitsu . addressbook . domain ; import static org . junit . Assert . assertEquals ; import org . junit . After ; import org . junit . AfterClass ; import org . junit . Before ; import org . junit . BeforeClass ; import org . junit . Test ; public class TestPerson { private Person person ; @ BeforeClass public static void setUpBeforeClass ( ) throws Exception { } @ AfterClass public static void tearDownAfterClass ( ) throws Exception { } @ Before public void setUp ( ) throws Exception { person = new Person ( ) ; } @ After public void tearDown ( ) throws Exception { } @ Test public void testAccessorOfName ( ) { person . setName ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , person . getName ( ) ) ; } @ Test public void testAccessorOfAddress ( ) { person . setAddress ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , person . getAddress ( ) ) ; } @ Test public void testAccessorOfPostCode ( ) { person . setPostcode ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , person . getPostcode ( ) ) ; } } </s>
<s> package com . komamitsu . addressbook . repository . impl ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertNotNull ; import java . util . List ; import javax . sql . DataSource ; import org . junit . Before ; import org . junit . Test ; import org . springframework . beans . factory . annotation . Autowired ; import org . springframework . beans . factory . annotation . Qualifier ; import org . springframework . test . context . ContextConfiguration ; import org . springframework . test . context . junit4 . AbstractTransactionalJUnit4SpringContextTests ; import org . springframework . test . context . transaction . TransactionConfiguration ; import com . komamitsu . addressbook . domain . Person ; import com . komamitsu . addressbook . repository . PersonDao ; @ ContextConfiguration ( "<STR_LIT>" ) @ TransactionConfiguration ( transactionManager = "<STR_LIT>" ) public class TestSqlMapPersonDaoImpl extends AbstractTransactionalJUnit4SpringContextTests { private static final String NAME_OF_PERSON_A = "<STR_LIT>" ; private static final String ADDRESS_OF_PERSON_A = "<STR_LIT>" ; private static final String POSTCODE_OF_PERSON_A = "<STR_LIT>" ; private static final String NAME_OF_PERSON_B = "<STR_LIT>" ; private static final String ADDRESS_OF_PERSON_B = "<STR_LIT>" ; private static final String POSTCODE_OF_PERSON_B = "<STR_LIT>" ; @ Autowired private PersonDao personDao ; @ Autowired @ Qualifier ( "<STR_LIT>" ) @ Override public void setDataSource ( DataSource dataSource ) { super . setDataSource ( dataSource ) ; } @ Before public void setup ( ) { deleteFromTables ( "<STR_LIT>" ) ; Person person = null ; person = new Person ( ) ; person . setName ( NAME_OF_PERSON_A ) ; person . setAddress ( ADDRESS_OF_PERSON_A ) ; person . setPostcode ( POSTCODE_OF_PERSON_A ) ; assertNotNull ( personDao . insert ( person ) ) ; person = new Person ( ) ; person . setName ( NAME_OF_PERSON_B ) ; person . setAddress ( ADDRESS_OF_PERSON_B ) ; person . setPostcode ( POSTCODE_OF_PERSON_B ) ; assertNotNull ( personDao . insert ( person ) ) ; } @ Test public void testSelectAllPeople ( ) { List < Person > people = personDao . selectAll ( ) ; assertEquals ( <NUM_LIT:2> , people . size ( ) ) ; Person person = null ; person = people . get ( <NUM_LIT:0> ) ; assertEquals ( NAME_OF_PERSON_A , person . getName ( ) ) ; assertEquals ( ADDRESS_OF_PERSON_A , person . getAddress ( ) ) ; assertEquals ( POSTCODE_OF_PERSON_A , person . getPostcode ( ) ) ; person = people . get ( <NUM_LIT:1> ) ; assertEquals ( NAME_OF_PERSON_B , person . getName ( ) ) ; assertEquals ( ADDRESS_OF_PERSON_B , person . getAddress ( ) ) ; assertEquals ( POSTCODE_OF_PERSON_B , person . getPostcode ( ) ) ; } @ Test public void testSelectPersonById ( ) { List < Person > people = personDao . selectAll ( ) ; Person person = personDao . selectById ( people . get ( <NUM_LIT:0> ) . getId ( ) ) ; assertEquals ( NAME_OF_PERSON_A , person . getName ( ) ) ; assertEquals ( ADDRESS_OF_PERSON_A , person . getAddress ( ) ) ; assertEquals ( POSTCODE_OF_PERSON_A , person . getPostcode ( ) ) ; } @ Test public void testUpdatePerson ( ) { List < Person > people = personDao . selectAll ( ) ; Person person = people . get ( <NUM_LIT:0> ) ; final String name = "<STR_LIT>" ; final String address = "<STR_LIT>" ; final String postcode = "<STR_LIT>" ; person . setName ( name ) ; person . setAddress ( address ) ; person . setPostcode ( postcode ) ; personDao . update ( person ) ; person = personDao . selectById ( person . getId ( ) ) ; assertEquals ( name , person . getName ( ) ) ; assertEquals ( address , person . getAddress ( ) ) ; assertEquals ( postcode , person . getPostcode ( ) ) ; } @ Test public void testDeletePerson ( ) { List < Person > people = personDao . selectAll ( ) ; personDao . delete ( people . get ( <NUM_LIT:0> ) ) ; people = personDao . selectAll ( ) ; assertEquals ( <NUM_LIT:1> , people . size ( ) ) ; Person person = people . get ( <NUM_LIT:0> ) ; assertEquals ( NAME_OF_PERSON_B , person . getName ( ) ) ; assertEquals ( ADDRESS_OF_PERSON_B , person . getAddress ( ) ) ; assertEquals ( POSTCODE_OF_PERSON_B , person . getPostcode ( ) ) ; } } </s>
<s> package com . komamitsu . addressbook . repository . impl ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertNotNull ; import java . util . List ; import javax . sql . DataSource ; import org . junit . Before ; import org . junit . Test ; import org . springframework . beans . factory . annotation . Autowired ; import org . springframework . beans . factory . annotation . Qualifier ; import org . springframework . test . context . ContextConfiguration ; import org . springframework . test . context . junit4 . AbstractTransactionalJUnit4SpringContextTests ; import org . springframework . test . context . transaction . TransactionConfiguration ; import com . komamitsu . addressbook . domain . Project ; import com . komamitsu . addressbook . repository . ProjectDao ; @ ContextConfiguration ( "<STR_LIT>" ) @ TransactionConfiguration ( transactionManager = "<STR_LIT>" ) public class TestSqlMapProjectDaoImpl extends AbstractTransactionalJUnit4SpringContextTests { private static final String NAME_OF_PROJECT_A = "<STR_LIT>" ; private static final String NAME_OF_PROJECT_B = "<STR_LIT>" ; @ Autowired private ProjectDao projectDao ; @ Autowired @ Qualifier ( "<STR_LIT>" ) @ Override public void setDataSource ( DataSource dataSource ) { super . setDataSource ( dataSource ) ; } @ Before public void setup ( ) { deleteFromTables ( "<STR_LIT>" ) ; Project project = null ; project = new Project ( ) ; project . setName ( NAME_OF_PROJECT_A ) ; assertNotNull ( projectDao . insert ( project ) ) ; project = new Project ( ) ; project . setName ( NAME_OF_PROJECT_B ) ; assertNotNull ( projectDao . insert ( project ) ) ; } @ Test public void testSelectAllPeople ( ) { List < Project > projects = projectDao . selectAll ( ) ; assertEquals ( <NUM_LIT:2> , projects . size ( ) ) ; Project project = null ; project = projects . get ( <NUM_LIT:0> ) ; assertEquals ( NAME_OF_PROJECT_A , project . getName ( ) ) ; project = projects . get ( <NUM_LIT:1> ) ; assertEquals ( NAME_OF_PROJECT_B , project . getName ( ) ) ; } @ Test public void testSelectProjectById ( ) { List < Project > projects = projectDao . selectAll ( ) ; Project project = projectDao . selectById ( projects . get ( <NUM_LIT:0> ) . getId ( ) ) ; assertEquals ( NAME_OF_PROJECT_A , project . getName ( ) ) ; } @ Test public void testUpdateProject ( ) { List < Project > projects = projectDao . selectAll ( ) ; Project project = projects . get ( <NUM_LIT:0> ) ; final String name = "<STR_LIT>" ; project . setName ( name ) ; projectDao . update ( project ) ; project = projectDao . selectById ( project . getId ( ) ) ; assertEquals ( name , project . getName ( ) ) ; } @ Test public void testDeleteProject ( ) { List < Project > projects = projectDao . selectAll ( ) ; projectDao . delete ( projects . get ( <NUM_LIT:0> ) ) ; projects = projectDao . selectAll ( ) ; assertEquals ( <NUM_LIT:1> , projects . size ( ) ) ; Project project = projects . get ( <NUM_LIT:0> ) ; assertEquals ( NAME_OF_PROJECT_B , project . getName ( ) ) ; } } </s>
<s> package com . somethingsimilar . opposite_of_a_bloom_filter ; import java . nio . ByteBuffer ; import org . junit . Test ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertTrue ; import static org . junit . Assert . fail ; public class OoaBFilterTest { private class FElement implements OoaBFilter . Element { private final ByteBuffer byteBuffer ; public FElement ( int a , int b , int c ) { this . byteBuffer = ByteBuffer . allocate ( <NUM_LIT:12> ) ; this . byteBuffer . putInt ( a ) ; this . byteBuffer . putInt ( b ) ; this . byteBuffer . putInt ( c ) ; } public ByteBuffer getByteBuffer ( ) { byteBuffer . rewind ( ) ; return byteBuffer ; } } @ Test public void testTheBasics ( ) { OoaBFilter filter = new OoaBFilter ( <NUM_LIT:2> , <NUM_LIT:12> ) ; FElement twentyNineId = new FElement ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; FElement thirtyId = new FElement ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> ) ; FElement thirtyThreeId = new FElement ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; assertFalse ( "<STR_LIT>" , filter . containsAndAdd ( twentyNineId ) ) ; assertTrue ( "<STR_LIT>" , filter . containsAndAdd ( twentyNineId ) ) ; assertFalse ( "<STR_LIT>" , filter . containsAndAdd ( thirtyId ) ) ; assertTrue ( "<STR_LIT>" , filter . containsAndAdd ( twentyNineId ) ) ; assertTrue ( "<STR_LIT>" , filter . containsAndAdd ( thirtyId ) ) ; assertFalse ( "<STR_LIT>" , filter . containsAndAdd ( thirtyThreeId ) ) ; assertTrue ( "<STR_LIT>" , filter . containsAndAdd ( thirtyThreeId ) ) ; assertFalse ( "<STR_LIT>" , filter . containsAndAdd ( thirtyId ) ) ; assertTrue ( "<STR_LIT>" , filter . containsAndAdd ( thirtyId ) ) ; assertFalse ( "<STR_LIT>" , filter . containsAndAdd ( thirtyThreeId ) ) ; } @ Test public void testSizeRounding ( ) { OoaBFilter filter = new OoaBFilter ( <NUM_LIT:3> , <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:4> , filter . getSize ( ) ) ; filter = new OoaBFilter ( <NUM_LIT:4> , <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:4> , filter . getSize ( ) ) ; filter = new OoaBFilter ( <NUM_LIT> , <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , filter . getSize ( ) ) ; } @ Test public void testTooLargeSize ( ) { int size = ( <NUM_LIT:1> << <NUM_LIT:30> ) + <NUM_LIT:1> ; try { new OoaBFilter ( size , <NUM_LIT:0> ) ; fail ( "<STR_LIT>" ) ; } catch ( IllegalArgumentException e ) { String msg = "<STR_LIT>" + size ; assertEquals ( msg , e . getMessage ( ) ) ; } } @ Test public void testTooSmallSize ( ) { int size = <NUM_LIT:0> ; try { new OoaBFilter ( size , <NUM_LIT:0> ) ; fail ( "<STR_LIT>" ) ; } catch ( IllegalArgumentException e ) { String msg = "<STR_LIT>" ; assertEquals ( "<STR_LIT>" , msg , e . getMessage ( ) ) ; } } } </s>
<s> package com . somethingsimilar . opposite_of_a_bloom_filter ; import org . junit . Test ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertTrue ; import static org . junit . Assert . fail ; public class ByteArrayFilterTest { @ Test public void testTheBasics ( ) { ByteArrayFilter filter = new ByteArrayFilter ( <NUM_LIT:2> ) ; byte [ ] twentyNineId = new byte [ ] { <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } ; byte [ ] thirtyId = new byte [ ] { <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> } ; byte [ ] thirtyThreeId = new byte [ ] { <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } ; assertFalse ( "<STR_LIT>" , filter . containsAndAdd ( twentyNineId ) ) ; assertTrue ( "<STR_LIT>" , filter . containsAndAdd ( twentyNineId ) ) ; assertFalse ( "<STR_LIT>" , filter . containsAndAdd ( thirtyId ) ) ; assertTrue ( "<STR_LIT>" , filter . containsAndAdd ( twentyNineId ) ) ; assertTrue ( "<STR_LIT>" , filter . containsAndAdd ( thirtyId ) ) ; assertFalse ( "<STR_LIT>" , filter . containsAndAdd ( thirtyThreeId ) ) ; assertTrue ( "<STR_LIT>" , filter . containsAndAdd ( thirtyThreeId ) ) ; assertFalse ( "<STR_LIT>" , filter . containsAndAdd ( thirtyId ) ) ; assertTrue ( "<STR_LIT>" , filter . containsAndAdd ( thirtyId ) ) ; assertFalse ( "<STR_LIT>" , filter . containsAndAdd ( thirtyThreeId ) ) ; } @ Test public void testSizeRounding ( ) { ByteArrayFilter filter = new ByteArrayFilter ( <NUM_LIT:3> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:4> , filter . getSize ( ) ) ; filter = new ByteArrayFilter ( <NUM_LIT:4> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT:4> , filter . getSize ( ) ) ; filter = new ByteArrayFilter ( <NUM_LIT> ) ; assertEquals ( "<STR_LIT>" , <NUM_LIT> , filter . getSize ( ) ) ; } @ Test public void testTooLargeSize ( ) { int size = ( <NUM_LIT:1> << <NUM_LIT:30> ) + <NUM_LIT:1> ; try { new ByteArrayFilter ( size ) ; fail ( "<STR_LIT>" ) ; } catch ( IllegalArgumentException e ) { String msg = "<STR_LIT>" + size ; assertEquals ( msg , e . getMessage ( ) ) ; } } @ Test public void testTooSmallSize ( ) { int size = <NUM_LIT:0> ; try { new ByteArrayFilter ( size ) ; fail ( "<STR_LIT>" ) ; } catch ( IllegalArgumentException e ) { String msg = "<STR_LIT>" ; assertEquals ( "<STR_LIT>" , msg , e . getMessage ( ) ) ; } } } </s>
<s> package com . somethingsimilar . opposite_of_a_bloom_filter ; import java . math . RoundingMode ; import java . util . Arrays ; import java . nio . ByteBuffer ; import com . google . common . hash . HashCode ; import com . google . common . hash . HashFunction ; import com . google . common . hash . Hashing ; import com . google . common . math . IntMath ; public class OoaBFilter { public interface Element { public ByteBuffer getByteBuffer ( ) ; } private static final HashFunction HASH_FUNC = Hashing . murmur3_32 ( ) ; private final int sizeMask ; private final ByteBuffer [ ] array ; private static final int MAX_SIZE = <NUM_LIT:1> << <NUM_LIT:30> ; public OoaBFilter ( int size , int bufSize ) { if ( size <= <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" + size ) ; } if ( size > MAX_SIZE ) { throw new IllegalArgumentException ( "<STR_LIT>" + size ) ; } int poweredSize = IntMath . pow ( <NUM_LIT:2> , IntMath . log2 ( size , RoundingMode . CEILING ) ) ; this . sizeMask = poweredSize - <NUM_LIT:1> ; this . array = new ByteBuffer [ poweredSize ] ; int i = <NUM_LIT:0> ; while ( i < poweredSize ) { array [ i ] = ByteBuffer . allocate ( bufSize ) ; i ++ ; } } public boolean containsAndAdd ( Element element ) { ByteBuffer eBytes = element . getByteBuffer ( ) ; HashCode code = HASH_FUNC . hashBytes ( eBytes . array ( ) ) ; int index = code . asInt ( ) & sizeMask ; boolean seen = true ; ByteBuffer buffer = array [ index ] ; synchronized ( buffer ) { if ( ! buffer . equals ( eBytes ) ) { seen = false ; buffer . put ( eBytes ) ; buffer . rewind ( ) ; } } return seen ; } public int getSize ( ) { return array . length ; } } </s>
<s> package com . somethingsimilar . opposite_of_a_bloom_filter ; import java . math . RoundingMode ; import java . util . Arrays ; import java . util . concurrent . atomic . AtomicReferenceArray ; import com . google . common . hash . HashCode ; import com . google . common . hash . HashFunction ; import com . google . common . hash . Hashing ; import com . google . common . math . IntMath ; public class ByteArrayFilter { private static final HashFunction HASH_FUNC = Hashing . murmur3_32 ( ) ; private final int sizeMask ; private final AtomicReferenceArray < byte [ ] > array ; private static final int MAX_SIZE = <NUM_LIT:1> << <NUM_LIT:30> ; public ByteArrayFilter ( int size ) { if ( size <= <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" + size ) ; } if ( size > MAX_SIZE ) { throw new IllegalArgumentException ( "<STR_LIT>" + size ) ; } int poweredSize = IntMath . pow ( <NUM_LIT:2> , IntMath . log2 ( size , RoundingMode . CEILING ) ) ; this . sizeMask = poweredSize - <NUM_LIT:1> ; this . array = new AtomicReferenceArray < byte [ ] > ( poweredSize ) ; } public boolean containsAndAdd ( byte [ ] id ) { HashCode code = HASH_FUNC . hashBytes ( id ) ; int index = Math . abs ( code . asInt ( ) ) & sizeMask ; byte [ ] oldId = array . getAndSet ( index , id ) ; return Arrays . equals ( id , oldId ) ; } public int getSize ( ) { return array . length ( ) ; } } </s>
<s> package com . g4 . matlab . ann ; import com . mathworks . toolbox . javabuilder . * ; import com . mathworks . toolbox . javabuilder . internal . * ; import java . util . * ; public class ANN extends MWComponentInstance < ANN > { private static final Set < Disposable > sInstances = new HashSet < Disposable > ( ) ; private static final MWFunctionSignature sBackpropagationSignature = new MWFunctionSignature ( <NUM_LIT:1> , false , "<STR_LIT>" , <NUM_LIT:5> , false ) ; private static final MWFunctionSignature sCreateIndividualSignature = new MWFunctionSignature ( <NUM_LIT:1> , false , "<STR_LIT>" , <NUM_LIT:5> , false ) ; private static final MWFunctionSignature sEvalANNSignature = new MWFunctionSignature ( <NUM_LIT:2> , false , "<STR_LIT>" , <NUM_LIT:6> , false ) ; private static final MWFunctionSignature sGenerateInputFromFileSignature = new MWFunctionSignature ( <NUM_LIT:4> , false , "<STR_LIT>" , <NUM_LIT:3> , false ) ; private static final MWFunctionSignature sSaveIndividualSignature = new MWFunctionSignature ( <NUM_LIT:0> , false , "<STR_LIT>" , <NUM_LIT:2> , false ) ; private ANN ( final MWMCR mcr ) throws MWException { super ( mcr ) ; synchronized ( ANN . class ) { sInstances . add ( this ) ; } } public ANN ( ) throws MWException { this ( AnnMCRFactory . newInstance ( ) ) ; } private static MWComponentOptions getPathToComponentOptions ( String path ) { MWComponentOptions options = new MWComponentOptions ( new MWCtfExtractLocation ( path ) , new MWCtfDirectorySource ( path ) ) ; return options ; } public ANN ( String pathToComponent ) throws MWException { this ( AnnMCRFactory . newInstance ( getPathToComponentOptions ( pathToComponent ) ) ) ; } public ANN ( MWComponentOptions componentOptions ) throws MWException { this ( AnnMCRFactory . newInstance ( componentOptions ) ) ; } public void dispose ( ) { try { super . dispose ( ) ; } finally { synchronized ( ANN . class ) { sInstances . remove ( this ) ; } } } public static void main ( String [ ] args ) { try { MWMCR mcr = AnnMCRFactory . newInstance ( ) ; mcr . runMain ( sBackpropagationSignature , args ) ; mcr . dispose ( ) ; } catch ( Throwable t ) { t . printStackTrace ( ) ; } } public static void disposeAllInstances ( ) { synchronized ( ANN . class ) { for ( Disposable i : sInstances ) i . dispose ( ) ; sInstances . clear ( ) ; } } public void backpropagation ( List lhs , List rhs ) throws MWException { fMCR . invoke ( lhs , rhs , sBackpropagationSignature ) ; } public void backpropagation ( Object [ ] lhs , Object [ ] rhs ) throws MWException { fMCR . invoke ( Arrays . asList ( lhs ) , Arrays . asList ( rhs ) , sBackpropagationSignature ) ; } public Object [ ] backpropagation ( int nargout , Object ... rhs ) throws MWException { Object [ ] lhs = new Object [ nargout ] ; fMCR . invoke ( Arrays . asList ( lhs ) , MWMCR . getRhsCompat ( rhs , sBackpropagationSignature ) , sBackpropagationSignature ) ; return lhs ; } public void createIndividual ( List lhs , List rhs ) throws MWException { fMCR . invoke ( lhs , rhs , sCreateIndividualSignature ) ; } public void createIndividual ( Object [ ] lhs , Object [ ] rhs ) throws MWException { fMCR . invoke ( Arrays . asList ( lhs ) , Arrays . asList ( rhs ) , sCreateIndividualSignature ) ; } public Object [ ] createIndividual ( int nargout , Object ... rhs ) throws MWException { Object [ ] lhs = new Object [ nargout ] ; fMCR . invoke ( Arrays . asList ( lhs ) , MWMCR . getRhsCompat ( rhs , sCreateIndividualSignature ) , sCreateIndividualSignature ) ; return lhs ; } public void evalANN ( List lhs , List rhs ) throws MWException { fMCR . invoke ( lhs , rhs , sEvalANNSignature ) ; } public void evalANN ( Object [ ] lhs , Object [ ] rhs ) throws MWException { fMCR . invoke ( Arrays . asList ( lhs ) , Arrays . asList ( rhs ) , sEvalANNSignature ) ; } public Object [ ] evalANN ( int nargout , Object ... rhs ) throws MWException { Object [ ] lhs = new Object [ nargout ] ; fMCR . invoke ( Arrays . asList ( lhs ) , MWMCR . getRhsCompat ( rhs , sEvalANNSignature ) , sEvalANNSignature ) ; return lhs ; } public void generateInputFromFile ( List lhs , List rhs ) throws MWException { fMCR . invoke ( lhs , rhs , sGenerateInputFromFileSignature ) ; } public void generateInputFromFile ( Object [ ] lhs , Object [ ] rhs ) throws MWException { fMCR . invoke ( Arrays . asList ( lhs ) , Arrays . asList ( rhs ) , sGenerateInputFromFileSignature ) ; } public Object [ ] generateInputFromFile ( int nargout , Object ... rhs ) throws MWException { Object [ ] lhs = new Object [ nargout ] ; fMCR . invoke ( Arrays . asList ( lhs ) , MWMCR . getRhsCompat ( rhs , sGenerateInputFromFileSignature ) , sGenerateInputFromFileSignature ) ; return lhs ; } public void saveIndividual ( List lhs , List rhs ) throws MWException { fMCR . invoke ( lhs , rhs , sSaveIndividualSignature ) ; } public void saveIndividual ( Object [ ] lhs , Object [ ] rhs ) throws MWException { fMCR . invoke ( Arrays . asList ( lhs ) , Arrays . asList ( rhs ) , sSaveIndividualSignature ) ; } public Object [ ] saveIndividual ( Object ... rhs ) throws MWException { Object [ ] lhs = new Object [ <NUM_LIT:0> ] ; fMCR . invoke ( Arrays . asList ( lhs ) , MWMCR . getRhsCompat ( rhs , sSaveIndividualSignature ) , sSaveIndividualSignature ) ; return lhs ; } } </s>
<s> package com . g4 . matlab . ann ; </s>
<s> package com . g4 . matlab . ann ; import com . mathworks . toolbox . javabuilder . * ; import com . mathworks . toolbox . javabuilder . internal . * ; public class AnnMCRFactory { private static final byte [ ] sSessionKey = { <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } ; private static final byte [ ] sPublicKey = { <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } ; private static final String [ ] sMatlabPath = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; private static final String [ ] sClassPath = { } ; private static final String [ ] sLibraryPath = { } ; private static final String [ ] sApplicationOptions = { } ; private static final String [ ] sRuntimeOptions = { } ; private static final String [ ] sSetWarningState = { "<STR_LIT>" } ; private static final String sComponentPrefDir = "<STR_LIT>" ; private static final String sComponentName = "<STR_LIT>" ; private static final NativeComponentData sComponentData = new NativeComponentData ( createComponentData ( MWMCR . findComponentParentDirOnClassPath ( sComponentName , "<STR_LIT>" ) ) ) ; private static final MWComponentOptions sDefaultComponentOptions = new MWComponentOptions ( MWCtfExtractLocation . EXTRACT_TO_CACHE , new MWCtfClassLoaderSource ( AnnMCRFactory . class ) ) ; static NativePtr createComponentData ( String pathToComponent ) { try { return MWMCR . getNativeMCR ( ) . mclCreateComponentData ( sPublicKey , sComponentName , "<STR_LIT>" , sSessionKey , sMatlabPath , sClassPath , sLibraryPath , sApplicationOptions , sRuntimeOptions , sComponentPrefDir , pathToComponent , sSetWarningState ) ; } catch ( MWException e ) { return NativePtr . NULL ; } } private AnnMCRFactory ( ) { } public static MWMCR newInstance ( MWComponentOptions componentOptions ) throws MWException { if ( null == componentOptions . getCtfSource ( ) ) { componentOptions = new MWComponentOptions ( componentOptions ) ; componentOptions . setCtfSource ( sDefaultComponentOptions . getCtfSource ( ) ) ; } return MWMCR . newInstance ( sComponentData , componentOptions , AnnMCRFactory . class , sComponentName , new int [ ] { <NUM_LIT:7> , <NUM_LIT> } ) ; } public static MWMCR newInstance ( ) throws MWException { return newInstance ( sDefaultComponentOptions ) ; } } </s>
<s> package com . g4 . matlab . ann ; import com . mathworks . toolbox . javabuilder . pooling . Poolable ; import java . util . List ; import java . rmi . Remote ; import java . rmi . RemoteException ; public interface ANNRemote extends Poolable { public Object [ ] backpropagation ( int nargout , Object ... rhs ) throws RemoteException ; public Object [ ] createIndividual ( int nargout , Object ... rhs ) throws RemoteException ; public Object [ ] evalANN ( int nargout , Object ... rhs ) throws RemoteException ; public Object [ ] generateInputFromFile ( int nargout , Object ... rhs ) throws RemoteException ; public Object [ ] saveIndividual ( Object ... rhs ) throws RemoteException ; void dispose ( ) throws RemoteException ; } </s>
<s> package com . g4 . java . model ; import java . util . ArrayList ; import java . util . List ; import com . mathworks . toolbox . javabuilder . MWArray ; import com . mathworks . toolbox . javabuilder . MWCellArray ; import com . mathworks . toolbox . javabuilder . MWClassID ; import com . mathworks . toolbox . javabuilder . MWNumericArray ; public class Individual { private MWCellArray data ; private double apptitude ; public Individual ( ) { } public MWCellArray getData ( ) { return data ; } public void setData ( MWCellArray data ) { this . data = data ; } public double getApptitude ( ) { return <NUM_LIT:1> / apptitude ; } public void setApptitude ( double apptitude ) { this . apptitude = apptitude ; } public List < double [ ] [ ] > getLupusMatrix ( ) { List < double [ ] [ ] > ret = new ArrayList < double [ ] [ ] > ( ) ; for ( int i = <NUM_LIT:1> ; i <= data . numberOfElements ( ) ; i ++ ) { MWNumericArray matrix = ( MWNumericArray ) data . getCell ( i ) ; double [ ] [ ] doubleMatrix = ( double [ ] [ ] ) matrix . toArray ( ) ; ret . add ( doubleMatrix ) ; } return ret ; } public double [ ] getLupusArray ( ) { int size = <NUM_LIT:0> ; for ( int i = <NUM_LIT:1> ; i <= data . numberOfElements ( ) ; i ++ ) { MWArray matrix = ( MWArray ) data . getCell ( i ) ; int [ ] dim = matrix . getDimensions ( ) ; size += dim [ <NUM_LIT:0> ] * dim [ <NUM_LIT:1> ] ; } double [ ] ret = new double [ size ] ; int index = <NUM_LIT:0> ; for ( int i = <NUM_LIT:1> ; i <= data . numberOfElements ( ) ; i ++ ) { MWNumericArray matrix = ( MWNumericArray ) data . getCell ( i ) ; double [ ] [ ] doubleMatrix = ( double [ ] [ ] ) matrix . toArray ( ) ; for ( int j = <NUM_LIT:0> ; j < doubleMatrix . length ; j ++ ) { for ( int k = <NUM_LIT:0> ; k < doubleMatrix [ j ] . length ; k ++ ) { ret [ index ++ ] = doubleMatrix [ j ] [ k ] ; } } matrix . dispose ( ) ; } return ret ; } public static Individual creator ( MWCellArray cellArray , double [ ] values ) { Individual ret = new Individual ( ) ; MWCellArray data = new MWCellArray ( cellArray . numberOfElements ( ) , <NUM_LIT:1> ) ; int index = <NUM_LIT:0> ; for ( int i = <NUM_LIT:1> ; i <= cellArray . numberOfElements ( ) ; i ++ ) { MWNumericArray matrix = ( MWNumericArray ) cellArray . getCell ( i ) ; int [ ] dim = matrix . getDimensions ( ) ; double [ ] [ ] createdMatrix = new double [ dim [ <NUM_LIT:0> ] ] [ dim [ <NUM_LIT:1> ] ] ; for ( int j = <NUM_LIT:0> ; j < dim [ <NUM_LIT:0> ] ; j ++ ) { for ( int k = <NUM_LIT:0> ; k < dim [ <NUM_LIT:1> ] ; k ++ ) { createdMatrix [ j ] [ k ] = values [ index ++ ] ; } } data . set ( i , new MWNumericArray ( createdMatrix , MWClassID . DOUBLE ) ) ; } ret . setData ( data ) ; return ret ; } } </s>
<s> package com . g4 . java . mutation ; import com . g4 . java . model . Individual ; import com . g4 . java . util . RandomGenerator ; public class ClassicMutation implements Mutation { protected double mutationPercentage ; private double alleleProb ; public ClassicMutation ( double mutationPercentage , double alleleProb ) { this . mutationPercentage = mutationPercentage ; this . alleleProb = alleleProb ; } public Individual mutate ( Individual entity , int iteration ) { double [ ] bits = entity . getLupusArray ( ) ; for ( int i = <NUM_LIT:0> ; i < bits . length ; ++ i ) { double charProba = RandomGenerator . getDouble ( ) ; if ( charProba < this . alleleProb ) { bits [ i ] = RandomGenerator . getDouble ( - <NUM_LIT> , <NUM_LIT> ) ; } } return Individual . creator ( entity . getData ( ) , bits ) ; } public double getMutationProbability ( ) { return mutationPercentage ; } public boolean shouldMutate ( ) { double prob = RandomGenerator . getDouble ( ) ; return prob < mutationPercentage ; } @ Override public void updateMutationProbability ( int iteration ) { } } </s>
<s> package com . g4 . java . mutation ; import com . g4 . java . model . Individual ; public interface Mutation { void updateMutationProbability ( int iteration ) ; Individual mutate ( Individual entity , int iteration ) ; boolean shouldMutate ( ) ; } </s>
<s> package com . g4 . java . mutation ; public class NotUniformMutation extends ClassicMutation { private int generationsToDecrease ; private double decreaseConstant ; public NotUniformMutation ( double mutationPercentage , int generationsToDecrease , double decreaseConstant , double alleleProb ) { super ( mutationPercentage , alleleProb ) ; this . generationsToDecrease = generationsToDecrease ; this . decreaseConstant = decreaseConstant ; } @ Override public void updateMutationProbability ( int iteration ) { if ( iteration % generationsToDecrease == <NUM_LIT:0> && iteration != <NUM_LIT:0> ) { this . mutationPercentage *= ( <NUM_LIT:1> - decreaseConstant ) ; } } } </s>
<s> package com . g4 . java . reproduction ; import java . util . ArrayList ; import java . util . List ; import com . g4 . java . model . Individual ; public class MonogamousReproduction implements Reproduction { public List < Individual [ ] > getParents ( List < Individual > populations ) { int size = populations . size ( ) ; if ( size % <NUM_LIT:2> != <NUM_LIT:0> ) { populations . add ( populations . get ( size - <NUM_LIT:1> ) ) ; size ++ ; } List < Individual [ ] > families = new ArrayList < Individual [ ] > ( size * <NUM_LIT:2> ) ; for ( int i = <NUM_LIT:0> ; i < size / <NUM_LIT:2> ; ++ i ) { Individual [ ] parents = new Individual [ <NUM_LIT:2> ] ; parents [ <NUM_LIT:0> ] = populations . get ( i ) ; parents [ <NUM_LIT:1> ] = populations . get ( i + size / <NUM_LIT:2> ) ; families . add ( parents ) ; } return families ; } } </s>
<s> package com . g4 . java . reproduction ; import java . util . List ; import com . g4 . java . model . Individual ; public interface Reproduction { List < Individual [ ] > getParents ( List < Individual > populations ) ; } </s>
<s> package com . g4 . java ; public class PlotData { public Double fitness ; public Double worst ; public Double median ; public PlotData ( double fitness , double worst , double median ) { this . fitness = new Double ( fitness ) ; this . worst = new Double ( worst ) ; this . median = new Double ( median ) ; } } </s>
<s> package com . g4 . java . ending ; import java . util . ArrayList ; import java . util . List ; import com . g4 . java . model . Individual ; import com . g4 . java . selection . EliteSelection ; import com . g4 . java . selection . Selection ; public class ContentEnding implements EndingMethod { private List < Double > stats = new ArrayList < Double > ( ) ; private int iterationsToImprove ; private double improvement ; private Selection elite ; public ContentEnding ( int iterationsToImprove , double improvement ) { this . iterationsToImprove = iterationsToImprove ; this . improvement = improvement ; this . elite = new EliteSelection ( <NUM_LIT:1> ) ; } @ Override public boolean shouldEnd ( List < Individual > population , int iterations ) { Individual best = elite . select ( population , <NUM_LIT:0> ) . get ( <NUM_LIT:0> ) ; if ( iterations < iterationsToImprove ) { stats . add ( iterations , best . getApptitude ( ) ) ; return false ; } else if ( iterations == iterationsToImprove ) { stats . add ( iterations , best . getApptitude ( ) ) ; } else { stats . set ( iterations % ( iterationsToImprove + <NUM_LIT:1> ) , best . getApptitude ( ) ) ; } if ( stats . get ( iterations % ( iterationsToImprove + <NUM_LIT:1> ) ) - ( stats . get ( ( iterations + <NUM_LIT:1> ) % ( iterationsToImprove + <NUM_LIT:1> ) ) ) < improvement ) { return true ; } return false ; } } </s>
<s> package com . g4 . java . ending ; import java . util . List ; import com . g4 . java . model . Individual ; public class MaxGenerationEnding implements EndingMethod { private int iterationsToEnd ; public MaxGenerationEnding ( int iterationsToEnd ) { this . iterationsToEnd = iterationsToEnd ; } @ Override public boolean shouldEnd ( List < Individual > population , int iterations ) { return iterations == iterationsToEnd ; } } </s>
<s> package com . g4 . java . ending ; import java . util . ArrayList ; import java . util . List ; import com . g4 . java . model . Individual ; import com . g4 . java . selection . EliteSelection ; import com . g4 . java . selection . Selection ; public class StructuralEnding implements EndingMethod { private int iterationsToCheck ; private int toBeEqual ; private Selection elite ; private List < List < Individual > > lastIndividuals ; public StructuralEnding ( int iterationsToCheck , int percent , int popSize ) { this . iterationsToCheck = iterationsToCheck ; this . toBeEqual = ( popSize * percent ) / <NUM_LIT:100> ; this . elite = new EliteSelection ( this . toBeEqual ) ; this . lastIndividuals = new ArrayList < List < Individual > > ( ) ; } @ Override public boolean shouldEnd ( List < Individual > population , int iterations ) { if ( iterations % iterationsToCheck != <NUM_LIT:0> || iterations == <NUM_LIT:0> ) { lastIndividuals . add ( population ) ; return false ; } List < List < Individual > > bests = new ArrayList < List < Individual > > ( ) ; for ( List < Individual > list : lastIndividuals ) { bests . add ( elite . select ( list , <NUM_LIT:0> ) ) ; } boolean ret = false ; for ( int i = <NUM_LIT:0> ; i < this . toBeEqual ; i ++ ) { double firstApp = bests . get ( <NUM_LIT:0> ) . get ( i ) . getApptitude ( ) ; double lastApp = bests . get ( bests . size ( ) - <NUM_LIT:1> ) . get ( i ) . getApptitude ( ) ; ret |= ( firstApp == lastApp ) ; } return ret ; } } </s>
<s> package com . g4 . java . ending ; import java . util . List ; import com . g4 . java . model . Individual ; import com . g4 . java . selection . EliteSelection ; import com . g4 . java . selection . Selection ; public class OptimumOrFitnessEnding implements EndingMethod { private double optimum ; private double tolerance ; private Selection elite ; public OptimumOrFitnessEnding ( double optimum , double tolerance ) { this . optimum = optimum ; this . tolerance = tolerance ; elite = new EliteSelection ( <NUM_LIT:1> ) ; } @ Override public boolean shouldEnd ( List < Individual > population , int iterations ) { Individual best = elite . select ( population , <NUM_LIT:0> ) . get ( <NUM_LIT:0> ) ; return Math . abs ( ( best . getApptitude ( ) - optimum ) ) < tolerance ; } } </s>
<s> package com . g4 . java . ending ; import java . util . List ; import com . g4 . java . model . Individual ; public class MixEnding implements EndingMethod { private List < EndingMethod > endingMethods ; public MixEnding ( List < EndingMethod > endingMethods ) { this . endingMethods = endingMethods ; } @ Override public boolean shouldEnd ( List < Individual > population , int iterations ) { for ( EndingMethod endingMethod : endingMethods ) { if ( endingMethod . shouldEnd ( population , iterations ) ) { System . out . println ( "<STR_LIT>" + endingMethod . getClass ( ) . getCanonicalName ( ) ) ; return true ; } } return false ; } } </s>