⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swdiet3d.java

📁 SWDiet3D is a port to SuperWaba of the Diet3D, the free 3D engine for J2ME mobiles, written by Phili
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    static final String vshape[] = { "cube", "sphere",                                     "axis" , "logo2d" , "tux"};    static final String vanim[] = { "demo" , "spin" , "no" };    public static int anim=0;    public static int tick=0;    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/* $Id: MathFixed.java.in,v 1.5 2004/11/02 14:33:14 rzr Exp $ *//** * @author www.Philippe.COVAL.free.fr * Copyright and License : http://rzr.online.fr/license.htm **//* $Id: HackJavaCpp.java.in,v 1.6 2004/11/02 14:33:14 rzr Exp $ *//* $Id: *//** * @author www.Philippe.COVAL.free.fr * Copyright and License : http://rzr.online.fr/license.htm * Provide basic Math operations on fixed reals stored on int's * This a sample example, need some fix check for stabilty (+half may help) * the idea is to >> when using reals , not needed on intergers * TODO: check for stability,  * Optimised : unroll loops, reuse vs create objects, inline as much as possible * Was released in a bugged version; now ok 20031120 **/    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    // all this section will have to move is a separated Precision.class    /*2^16 =  655362^32 =  42949672964294967296 / 2 =  2147483648srrt=() = 46340.95/ 3 = 15446    */    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    public static final int offset=10;    public static final int one=1024;    public static final int PI=3217;    public static final int sqrt2=1448;    public static final int sqrt3=1774;    public static final int exp=2784;    public static final int log10=2358;    //public static final int sinesize=32;    //public static final int sine[]={ 0, 200, 392, 569, 724, 851, 946, 1004, 1024, 1004, 946, 851, 724, 569, 392, 200, 0, -200, -392, -569, -724, -851, -946, -1004, -1024, -1004, -946, -851, -724, -569, -392, -200 };    public static final int sinesize=64;    public static final int sine[]={        0, 100, 200, 297, 392, 483, 569, 650, 724, 792, 851, 903, 946, 980, 1004, 1019,        1024, 1019, 1004, 980, 946, 903, 851, 792, 724, 650, 569, 483, 392, 297, 200, 100,        0, -100, -200, -297, -392, -483, -569, -650, -724, -792, -851, -903, -946, -980, -1004, -1019,        -1024, -1019, -1004, -980, -946, -903, -851, -792, -724, -650, -569, -483, -392, -297, -200, -100    };    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    public static final int precision_sqrt = 1;    public static final int PI2= PI * 2;    public static final int half = one /2;    public static final int sinstep= (( PI * 2 ) / sinesize );    public static final int sinoff=((sinesize*3) / 4);    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    // Reusable objects    static int[][] tmpint4x4a = new int[4][4];    static int[][] tmpint4x4b = new int[4][4];    static int[] sc = new int[2];    //static int[] tmpint3a = new int[3];    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ///    public static int max(int a, int b)    {        return ((a > b ) ? a : b);    }    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    /// that one fix cohenrence and speed up    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    public static int sqrt(int a)    {        ////debug("+sqrt"); print(a);        if ( a == 0 ) return 0;        int g,q,r=0;        if ( a >= one ) g = one; else g = 1 ;        do {            q = ( (a<<offset ) / g ) ;            g = ( g + q ) >> 1; // average /2            ////debug("srqt g="+g+" / q="+q);//            r = (q-g);            r = (r > 0 ) ? r : -r ;        } while( r > precision_sqrt);        return g;    }    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    public static void initIdentity(int[][] m)    {        //for(int i=0;i<4;i++) for(int j=0;j<4;j++) m[i][j]=0;        //for(int i=0;i<4;i++) m[i][i]= one;        m[0][0] = m[1][1] = m[2][2] = one;        m[0][1] = m[0][2] = m[1][0] = m[1][2] = m[2][0] = m[2][1] = 0;        m[3][0] = m[3][1] = m[3][2] = one; //        m[0][3] = m[1][3] = m[2][3] = 0 ;        m[3][3] = one; //tranlation    }    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    public static void printV(int[] v)    {        ;        int i=0;        for( i=0; i < 2 ; i++) ;        ;    }    public static void printS(int a)    {        ;    }    public static void printM(int[][] m)    {        for(int i=0;i<4;i++) {            for(int j=0;j<4;j++)                ;            ;        }        ;        //debug("-printM");    }    ///TEST THIS    /// nrom(a) * norm(b) * cos(a,b)    // 1/2 * ( ( norm(u+v)^2 - norm(u)^2 - norm(v)^2 )    ///TEST THIS    /// @param f is a real integer (2,3, etc)    public static void crossVV(int[] a, int[] b , int[] r)    {        //print(a); print(b);        r[0] = ( ( (a[1]*b[2]) + half ) >> offset ) - ( ( (a[2]*b[1]) + half ) >> offset );        r[1] = ( ( (a[2]*b[0]) + half ) >> offset ) - ( ( (a[0]*b[2]) + half ) >> offset );        r[2] = ( ( (a[0]*b[1]) + half ) >> offset ) - ( ( (a[1]*b[0]) + half ) >> offset );        //        print(r);        ////debug("-cross");    }    public static void normVVV(int[] a, int[] b, int[] c,int[] r)    {        int[] x= new int[3]; int[] y= new int[3]; //opt        { x[0] = c[0]- a[0]; x[1] = c[1]- a[1]; x[2] = c[2]- a[2]; }; { y[0] = b[0]- a[0]; y[1] = b[1]- a[1]; y[2] = b[2]- a[2]; };        crossVV(x,y,r);    }    public static void normV(int[] a, int[] r)    {        ////debug("+norm");        print(a);        r[0] = a[0]; r[1] = a[1]; r[2] = a[2];        int l = (sqrt( (( ( (a[0]*a[0]) + half ) >> offset )) + (( ( (a[1]*a[1]) + half ) >> offset )) + (( ( (a[2]*a[2]) + half ) >> offset ))));        ////debug("lenght="+l);        if ( l != 0 ) l = ( (one<<offset ) / l ) ; //!!        { r[0] = ( ( (r[0]*l) + half ) >> offset ); r[1] = ( ( (r[1]*l) + half ) >> offset ); r[2] = ( ( (r[2]*l) + half ) >> offset ); };        // print(r);        //debug("-norm");    }    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    /**     * dot product X . Y = |X| * |Y] * cos( angle(Y,X cw))     **/    public static int dotVV(int[] a, int[] b)    {        return(( ( (a[0]*b[0]) + half ) >> offset )) + (( ( (a[1]*b[1]) + half ) >> offset )) + (( ( (a[2]*b[2]) + half ) >> offset )) ;    }    //#define MACROdotVV(a,b,r) { \    //r =  mult(a[0],b[0]) + mult(a[1],b[1]) + mult(a[2],b[2]) ; }    //#define dotVV(a,b,r) MACROdotVV(a,b,r)     public static void copyMM(int s[][], int d[][])    {        //for(int i=0;i<4;i++) for(int j=0;j<4;j++) d[i][j] = s[i][j];        d[0][0]=s[0][0]; d[0][1]=s[0][1]; d[0][2]=s[0][2];        d[1][0]=s[1][0]; d[1][1]=s[1][1]; d[1][2]=s[1][2];        d[2][0]=s[2][0]; d[2][1]=s[2][1]; d[2][2]=s[2][2];    }    public static void multMM( int a[][] , int b[][] , int res[][] )    {        { res[0][0] = ( ( ( (a[0][0]*b[0][0]) + half ) >> offset )+( ( (a[0][1]*b[1][0]) + half ) >> offset )+( ( (a[0][2]*b[2][0]) + half ) >> offset )); res[0][1] = ( ( ( (a[0][0]*b[0][1]) + half ) >> offset )+( ( (a[0][1]*b[1][1]) + half ) >> offset )+( ( (a[0][2]*b[2][1]) + half ) >> offset )); res[0][2] = ( ( ( (a[0][0]*b[0][2]) + half ) >> offset )+( ( (a[0][1]*b[1][2]) + half ) >> offset )+( ( (a[0][2]*b[2][2]) + half ) >> offset )); res[1][0] = ( ( ( (a[1][0]*b[0][0]) + half ) >> offset )+( ( (a[1][1]*b[1][0]) + half ) >> offset )+( ( (a[1][2]*b[2][0]) + half ) >> offset )); res[1][1] = ( ( ( (a[1][0]*b[0][1]) + half ) >> offset )+( ( (a[1][1]*b[1][1]) + half ) >> offset )+( ( (a[1][2]*b[2][1]) + half ) >> offset )); res[1][2] = ( ( ( (a[1][0]*b[0][2]) + half ) >> offset )+( ( (a[1][1]*b[1][2]) + half ) >> offset )+( ( (a[1][2]*b[2][2]) + half ) >> offset )); res[2][0] = ( ( ( (a[2][0]*b[0][0]) + half ) >> offset )+( ( (a[2][1]*b[1][0]) + half ) >> offset )+( ( (a[2][2]*b[2][0]) + half ) >> offset )); res[2][1] = ( ( ( (a[2][0]*b[0][1]) + half ) >> offset )+( ( (a[2][1]*b[1][1]) + half ) >> offset )+( ( (a[2][2]*b[2][1]) + half ) >> offset )); res[2][2] = ( ( ( (a[2][0]*b[0][2]) + half ) >> offset )+( ( (a[2][1]*b[1][2]) + half ) >> offset )+( ( (a[2][2]*b[2][2]) + half ) >> offset )); };    }    //#define  multMM(a,b,r)  MACROmultMM(a,b,r)    public static void multMV( int[][] m, int[]v , int[] r)    {        r[0]= ( ( (v[0]*m[0][0]) + half ) >> offset ) + ( ( (v[1]*m[0][1]) + half ) >> offset ) + ( ( (v[2]*m[0][2]) + half ) >> offset );        r[1]= ( ( (v[0]*m[1][0]) + half ) >> offset ) + ( ( (v[1]*m[1][1]) + half ) >> offset ) + ( ( (v[2]*m[1][2]) + half ) >> offset );        r[2]= ( ( (v[0]*m[2][0]) + half ) >> offset ) + ( ( (v[1]*m[2][1]) + half ) >> offset ) + ( ( (v[2]*m[2][2]) + half ) >> offset );    }    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    /// warning  //TODO use quaternion for axe/angle rotations    public static void rotate(int x, int y, int z , int[][] m)    {        //debug("+rotate "+x);        //printM( m );        if ( z != 0 ) {            //debug(".rotateZ="+z);            { while ( z < 0 ) { z += PI2; } sc[0] = ( ( (z%PI2) * sinesize + half ) / PI2 ) ; sc[1] = ( sc[0] + (sinesize/4)); sc[0] = sine[ (sc[0]%sinesize) ]; sc[1] = sine[ (sc[1]%sinesize) ]; };            tmpint4x4a[0][0] = sc[1];            tmpint4x4a[0][1] = - sc[0];            tmpint4x4a[0][2] = 0;            tmpint4x4a[1][0] = sc[0];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -