Java Code Examples for com.sun.j3d.utils.geometry.Box

The following examples show how to use com.sun.j3d.utils.geometry.Box. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: algorithms-sedgewick-wayne   Source File: StdDraw3D.java    License: MIT License 6 votes vote down vote up
/**
 * Draws a solid rectangular prism centered at (x, y, z) with a 2d image
 * loaded from imageURL and pasted on the surface of the box.
 */
public static TransformGroup drawBox (double x, double y, double z, double w, double h, double d, String imageURL) {
    Appearance appearance = createAppearance();

    // Load an image from the file
    TextureLoader loader;
    try {
        loader = new TextureLoader(imageURL, "RGBA", new Container());
    } catch (Exception e) {
        throw new RuntimeException ("Could not read from the file '" + imageURL + "'");
    }
    Texture texture = loader.getTexture();
    texture.setBoundaryModeS(Texture.WRAP);
    texture.setBoundaryModeT(Texture.WRAP);
    texture.setBoundaryColor( new Color4f( 0.0f, 1.0f, 0.0f, 0.0f ) );

    // Set up the texture attributes
    TextureAttributes textureAttributes = new TextureAttributes();
    textureAttributes.setTextureMode(TextureAttributes.REPLACE);

    appearance.setTexture(texture);
    appearance.setTextureAttributes(textureAttributes);
    Box box = new Box(scaleWidth(w), scaleHeight(h), scaleDepth(d), primitiveflags, appearance, NUM_DIVISIONS);
    return drawPrimitive(box, x, y, z);
}
 
Example 2
Source Project: javagame   Source File: Main.java    License: MIT License 6 votes vote down vote up
private Box createBox() {
    // ��
    Appearance app = new Appearance();
    Material mat = new Material();
    mat.setAmbientColor(new Color3f(0.0f, 0.0f, 1.0f));
    mat.setSpecularColor(new Color3f(1.0f, 1.0f, 1.0f));
    app.setMaterial(mat);

    // �����ɂ���
    TransparencyAttributes transAttr = new TransparencyAttributes(
            TransparencyAttributes.BLENDED, 0.5f);
    app.setTransparencyAttributes(transAttr);

    Box box = new Box(0.5f, 0.5f, 0.5f, app);

    return box;
}
 
Example 3
Source Project: javagame   Source File: Floor.java    License: MIT License 6 votes vote down vote up
public Floor() {
    floorBG = new BranchGroup();

    Appearance app = new Appearance();
    
    // ��
    Material mat = new Material();
    mat.setAmbientColor(new Color3f(1.0f, 1.0f, 0.0f));  // ���F
    mat.setSpecularColor(new Color3f(1.0f, 1.0f, 1.0f));
    app.setMaterial(mat);

    // �����쐬
    Box floor = new Box(10.0f, 0.001f, 10.0f, app);

    floorBG.addChild(floor);
}
 
Example 4
Source Project: javagame   Source File: CrystalBall.java    License: MIT License 4 votes vote down vote up
/**
 * �V�[�����\�z����
 * 
 * @return BG
 */
public BranchGroup createSceneGraph() {
    BranchGroup bg = new BranchGroup();

    // �O�~
    Appearance app = new Appearance();
    app.setTexture(loadTexture("carpet.jpg"));  // �O�~�̃e�N�X�`��
    Box floor = new Box(0.8f, 0.01f, 0.8f, Box.GENERATE_TEXTURE_COORDS, app);

    // ������
    app = new Appearance();
    Material mat = new Material();
    mat.setAmbientColor(new Color3f(0.0f, 0.0f, 1.0f));
    mat.setSpecularColor(new Color3f(1.0f, 1.0f, 1.0f));
    app.setMaterial(mat);

    TransparencyAttributes transAttr = new TransparencyAttributes(
            TransparencyAttributes.BLENDED, 0.5f);
    app.setTransparencyAttributes(transAttr);

    Sphere sphere = new Sphere(0.3f, Sphere.GENERATE_NORMALS, 100, app);

    // �������ړ��p
    Transform3D t3d = new Transform3D();
    t3d.set(new Vector3f(0.0f, 0.3f, 0.0f));
    TransformGroup tg = new TransformGroup(t3d);
    tg.addChild(sphere);

    bg.addChild(floor);
    bg.addChild(tg);
    
    // ����
    BoundingSphere bounds = new BoundingSphere();

    Light light = new AmbientLight();
    light.setInfluencingBounds(bounds);
    bg.addChild(light);

    light = new DirectionalLight(new Color3f(1.0f, 1.0f, 1.0f), new Vector3f(1.0f, -1.0f, -1.0f));
    light.setInfluencingBounds(bounds);
    bg.addChild(light);

    return bg;
}
 
Example 5
Source Project: algorithms-sedgewick-wayne   Source File: StdDraw3D.java    License: MIT License 2 votes vote down vote up
/**
 * Draws a solid rectangular prism centered at (x, y, z).
 * To set its color, call setPenColor before this method.
 * If penColor has an alpha component, the box will be semi-transparent.
 * Returns a TransformGroup representing the box which can then be
 * passed to the moveObject or rotateObject methods.
 * @param x the x coordinate of the center of the box
 * @param y the y coordinate of the center of the box
 * @param z the z coordinate of the center of the box
 * @param w the width (x-direction) of the box
 * @param h the height (y-direction) of the box
 * @param d the depth (z-direction) of the box
 */
public static TransformGroup drawBox (double x, double y, double z, double w, double h, double d) {
    Appearance appearance = createAppearance();
    Box box = new Box(scaleWidth(w), scaleHeight(h), scaleDepth(d), primitiveflags, appearance, NUM_DIVISIONS);
    return drawPrimitive(box, x, y, z);
}