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

📄 cubemodel.java

📁 wince 5.0上基于personal java写的的虚拟魔方
💻 JAVA
字号:

/*
 * Java Virtual Cube
 * -----------------
 *
 * Copyright 1996, Song Li  
 * URL: http://www.cs.umbc.edu/~sli2
 *
 * 
 * You can use the code for any nonprofittable use. But remember to mention
 * the authors' names in your revised program. You are also encouraged to
 * improve the program or give your comments and bug reports. If there are
 * further questions, please contact me and I'll be glad to help. My E-Mail
 * address is: sli2@gl.umbc.edu.
 *
 */




import java.awt.*;
import java.util.*;




class CubeModel extends Model3D {

    CubeModel (Vertex viewpoint) {
        super (viewpoint) ;
    }
        


    public Vertex Unproject (float selx, float sely) {
        Matrix3D invmat = ViewMat.Inverse () ;
        
        for (int i=3; i<6; i++) {
            Vertex hotpoint = new Vertex () ;
            Vertex selpoint = new Vertex (selx, sely, 
                ((CubeFace) Faces.elementAt (i)).Unproject (selx, sely)) ;
            invmat.Transform (selpoint, hotpoint) ;
            
            float x = hotpoint.x ;
            float y = hotpoint.y ;
            float z = hotpoint.z ;
            
            float deltax = x>0 ? (x>3 ? x-3 : 3-x) : (x<-3 ? -3-x : x+3) ;
            if (deltax < 0.0001)
                if ((y>=-3 && y<=3) && (z>=-3 && z<=3)) {
                    hotpoint.x = x>0 ? 3 : -3 ;
                    return hotpoint ;
                    }
            
            float deltay = y>0 ? (y>3 ? y-3 : 3-y) : (y<-3 ? -3-y : y+3) ;
            if (deltay < 0.0001)
                if ((x>=-3 && x<=3) && (z>=-3 && z<=3)) {
                    hotpoint.y = y>0 ? 3 : -3 ;
                    return hotpoint ;
                    }
            
            float deltaz = z>0 ? (z>3 ? z-3 : 3-z) : (z<-3 ? -3-z : z+3) ;
            if (deltaz < 0.0001)
                if ((x>=-3 && x<=3) && (y>=-3 && y<=3)) {
                    hotpoint.z = z>0 ? 3 : -3 ;
                    return hotpoint ;
                    }
            }
        
        return null ;
    }
    




    public synchronized void Paint (Graphics graph, int width, int height) {
        Sort () ;
        for (int i=3; i<6; i++) {
            Face face = (Face) Faces.elementAt (i) ;
            face.Paint (graph, width, height) ;
            }
    }
    


}

⌨️ 快捷键说明

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