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

📄 checkerfloor.java

📁 希望能对学习java3d的有所帮助,我们共同学习
💻 JAVA
字号:
//package j3d_movie;///**// * <p>Title: </p>// * <p>Description: </p>// * <p>Copyright: Copyright (c) 2008</p>// * <p>Company: </p>// * @author not attributable// * @version 1.0// */////public class CheckerFloor {//  public CheckerFloor() {//  }////}// CheckerFloor.java// Andrew Davison, April 2005, ad@fivedots.coe.psu.ac.th/* The floor is a blue and green chessboard, with a small red square   at the (0,0) position on the (X,Z) plane, and with numbers along   the X- and Z- axes.3. 地板是一个蓝色和绿色的棋盘上,一个红色的小广场   在( 0,0 )位置对(十, Z )的飞机,并与沿号码   的X和Z轴。*//*import java.awt.*;import javax.media.j3d.*;import com.sun.j3d.utils.geometry.Text2D;import javax.vecmath.*;import java.util.ArrayList;public class CheckerFloor{  private final static int FLOOR_LEN = 20;  // should be even  // colours for floor, etc  private final static Color3f blue = new Color3f(0.0f, 0.1f, 0.4f);  private final static Color3f green = new Color3f(0.0f, 0.5f, 0.1f);  private final static Color3f medRed = new Color3f(0.8f, 0.4f, 0.3f);  private final static Color3f white = new Color3f(1.0f, 1.0f, 1.0f);  private BranchGroup floorBG;  public CheckerFloor()  // create tiles, add origin marker, then the axes labels  {    ArrayList blueCoords = new ArrayList();    ArrayList greenCoords = new ArrayList();    floorBG = new BranchGroup();    boolean isBlue;    for(int z=-FLOOR_LEN/2; z <= (FLOOR_LEN/2)-1; z++) {      isBlue = (z%2 == 0)? true : false;    // set colour for new row      for(int x=-FLOOR_LEN/2; x <= (FLOOR_LEN/2)-1; x++) {        if (isBlue)          createCoords(x, z, blueCoords);        else          createCoords(x, z, greenCoords);        isBlue = !isBlue;      }    }    floorBG.addChild( new ColouredTiles(blueCoords, blue) );    floorBG.addChild( new ColouredTiles(greenCoords, green) );    addOriginMarker();    labelAxes();  }  // end of CheckerFloor()  private void createCoords(int x, int z, ArrayList coords)  // Coords for a single blue or green square,  // its left hand corner at (x,0,z)  {    // points created in counter-clockwise order    Point3f p1 = new Point3f(x, 0.0f, z+1.0f);    Point3f p2 = new Point3f(x+1.0f, 0.0f, z+1.0f);    Point3f p3 = new Point3f(x+1.0f, 0.0f, z);    Point3f p4 = new Point3f(x, 0.0f, z);    coords.add(p1); coords.add(p2);    coords.add(p3); coords.add(p4);  }  // end of createCoords()  private void addOriginMarker()  // A red square centered at (0,0,0), of length 0.5  {  // points created counter-clockwise, a bit above the floor    Point3f p1 = new Point3f(-0.25f, 0.01f, 0.25f);    Point3f p2 = new Point3f(0.25f, 0.01f, 0.25f);    Point3f p3 = new Point3f(0.25f, 0.01f, -0.25f);    Point3f p4 = new Point3f(-0.25f, 0.01f, -0.25f);    ArrayList oCoords = new ArrayList();    oCoords.add(p1); oCoords.add(p2);    oCoords.add(p3); oCoords.add(p4);    floorBG.addChild( new ColouredTiles(oCoords, medRed) );  } // end of addOriginMarker();  private void labelAxes()  // Place numbers along the X- and Z-axes at the integer positions  {    Vector3d pt = new Vector3d();    for (int i=-FLOOR_LEN/2; i <= FLOOR_LEN/2; i++) {      pt.x = i;      floorBG.addChild( makeText(pt,""+i) );   // along x-axis    }    pt.x = 0;    for (int i=-FLOOR_LEN/2; i <= FLOOR_LEN/2; i++) {      pt.z = i;      floorBG.addChild( makeText(pt,""+i) );   // along z-axis    }  }  // end of labelAxes()  private TransformGroup makeText(Vector3d vertex, String text)  // Create a Text2D object at the specified vertex  {    Text2D message = new Text2D(text, white, "SansSerif", 36, Font.BOLD );       // 36 point bold Sans Serif    TransformGroup tg = new TransformGroup();    Transform3D t3d = new Transform3D();    t3d.setTranslation(vertex);    tg.setTransform(t3d);    tg.addChild(message);    return tg;  } // end of getTG()  public BranchGroup getBG()  {  return floorBG;  }}  // end of CheckerFloor class*/

⌨️ 快捷键说明

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