📄 displayboundingbox.java
字号:
/* * SimpleBox.java */package org.java3dgamesdk.graphics.util;import javax.media.j3d.*;import javax.vecmath.*;import com.sun.j3d.utils.geometry.*;import org.java3dgamesdk.graphics.*;/** * * @author Norbert Nopper */public class DisplayBoundingBox extends Model3D { /** * Class variable for the red color. */ final public static Color3f RED = new Color3f(1.0f, 0.0f, 0.0f); /** * Class variable for the green color. */ final public static Color3f GREEN = new Color3f(0.0f, 1.0f, 0.0f); /** * Class variable for the blue color. */ final public static Color3f BLUE = new Color3f(0.0f, 0.0f, 1.0f); final public static int MODEL_FASTEST = 0; final public static int MODEL_NICEST = 1; final public static int MODEL_SHADE_FLAT = 2; final public static int MODEL_SHADE_GOURAUD = 3; final public static int TRANS_NONE = 0; final public static int TRANS_FASTEST = 1; final public static int TRANS_NICEST = 2; final public static int TRANS_SCREEN_DOOR = 3; final public static int TRANS_BLENDED = 4; private Box box; public DisplayBoundingBox(BoundingBox boundingBox) { Point3d lower = new Point3d(); Point3d upper = new Point3d(); boundingBox.getLower(lower); boundingBox.getUpper(upper); Appearance appearance = new Appearance(); appearance.setColoringAttributes(new ColoringAttributes(GREEN, MODEL_FASTEST)); appearance.setTransparencyAttributes(new TransparencyAttributes(TRANS_FASTEST, 0.9f)); box = new Box((float)(upper.x-lower.x)/2.0f, (float)(upper.y-lower.y)/2.0f, (float)(upper.z-lower.z)/2.0f, appearance); x = (upper.x+lower.x)/2.0f; y = (upper.y+lower.y)/2.0f; z = (upper.z+lower.z)/2.0f; } public void changeColor(Color3f color) { Appearance appearance = box.getAppearance(); ColoringAttributes attributes = appearance.getColoringAttributes(); attributes.setColor(color); appearance.setColoringAttributes(attributes); box.setAppearance(appearance); } /** * Nothing needs to be updated. * * @param time the passed time in milliseconds */ protected void updateModel(long time) { // do nothing } /** * Render the line. * * @param gc3D the graphics contect 3D to render on */ protected void drawModel(GraphicsContext3D gc3D) { gc3D.setAppearance(box.getAppearance()); for(int i = 0; i <6; i++) gc3D.draw(box.getShape(i)); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -