javax.media.j3d.BranchGroup Java Examples

The following examples show how to use javax.media.j3d.BranchGroup. 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 File: CrystalBall.java    From javagame with MIT License 7 votes vote down vote up
public CrystalBall() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse
            .getPreferredConfiguration();
    Canvas3D canvas = new Canvas3D(config);
    add(canvas, BorderLayout.CENTER);

    universe = new SimpleUniverse(canvas);

    // �V�[�����\�z
    BranchGroup scene = createSceneGraph();
    scene.compile();

    // ���_���Z�b�g
    universe.getViewingPlatform().setNominalViewingTransform();

    // �}�E�X����
    orbitControls(canvas);

    universe.addBranchGraph(scene);
}
 
Example #2
Source File: RotatingCube.java    From javagame with MIT License 6 votes vote down vote up
public RotatingCube() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    Canvas3D canvas = new Canvas3D(config);
    add(canvas, BorderLayout.CENTER);

    SimpleUniverse universe = new SimpleUniverse(canvas);

    // �V�[�����\�z
    BranchGroup scene = createSceneGraph();
    scene.compile();
    
    // ���_���Z�b�g
    universe.getViewingPlatform().setNominalViewingTransform();
    
    universe.addBranchGraph(scene);
}
 
Example #3
Source File: Main3D.java    From javagame with MIT License 6 votes vote down vote up
public Main3D() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse
            .getPreferredConfiguration();
    Canvas3D canvas = new Canvas3D(config);
    add(canvas, BorderLayout.CENTER);

    universe = new SimpleUniverse(canvas);

    // �V�[�����\�z
    BranchGroup scene = createSceneGraph();
    scene.compile();

    // ���_���Z�b�g
    universe.getViewingPlatform().setNominalViewingTransform();

    // �}�E�X����
    orbitControls(canvas);

    universe.addBranchGraph(scene);
}
 
Example #4
Source File: Main.java    From javagame with MIT License 6 votes vote down vote up
/**
 * �V�[�����\�z����
 * 
 * @return BG
 */
public BranchGroup createSceneGraph() {
    BranchGroup bg = new BranchGroup();

    // �����ŃV�[�����쐬����

    // �{�[����lj�
    Ball ball = new Ball(0, 20.0, 0);
    BallBehavior ballBehavior = new BallBehavior(ball, 20);
    bg.addChild(ball);
    bg.addChild(ballBehavior);

    // ����lj�
    bg.addChild(createFloor());

    // ������lj�
    bg.addChild(createAmbientLight());
    bg.addChild(createDirectionalLight());
    
    return bg;
}
 
Example #5
Source File: Main.java    From javagame with MIT License 6 votes vote down vote up
public Main() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse
            .getPreferredConfiguration();
    Canvas3D canvas = new Canvas3D(config);
    add(canvas, BorderLayout.CENTER);

    universe = new SimpleUniverse(canvas);

    // �V�[�����\�z
    BranchGroup scene = createSceneGraph();
    scene.compile();

    // ���_���Z�b�g
    Transform3D viewPlatformTransform = new Transform3D();
    viewPlatformTransform.setTranslation(new Vector3d(0.0, 0.0, 10.0));
    universe.getViewingPlatform().getViewPlatformTransform().setTransform(viewPlatformTransform);

    // �}�E�X����
    orbitControls(canvas);

    universe.addBranchGraph(scene);
}
 
Example #6
Source File: MainPanel.java    From javagame with MIT License 6 votes vote down vote up
/**
 * ���E���\�z
 */
private void createSceneGraph() {
    // sceneBG�ɂ��낢��ڑ����邱�ƂŐ��E���\�������
    sceneBG = new BranchGroup();
    // ���E�͈̔́i�����Ȃǂ̋y�Ԕ͈́j
    bounds = new BoundingSphere(new Point3d(0, 0, 0), BOUND_SIZE);

    lightScene(); // ������sceneBG�ɒlj�
    addBackground(); // ���sceneBG�ɒlj�

    // ���W����lj�
    Axis axis = new Axis();
    sceneBG.addChild(axis.getBG());

    sceneBG.compile();
}
 
Example #7
Source File: Main3D.java    From javagame with MIT License 6 votes vote down vote up
public Main3D() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse
            .getPreferredConfiguration();
    Canvas3D canvas = new Canvas3D(config);
    add(canvas, BorderLayout.CENTER);

    universe = new SimpleUniverse(canvas);

    // �V�[�����\�z
    BranchGroup scene = createSceneGraph();
    scene.compile();

    // ���_���Z�b�g
    universe.getViewingPlatform().setNominalViewingTransform();

    // �}�E�X����
    orbitControls(canvas);

    universe.addBranchGraph(scene);
}
 
Example #8
Source File: Floor.java    From javagame with 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 #9
Source File: Main.java    From javagame with MIT License 6 votes vote down vote up
public Main() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse
            .getPreferredConfiguration();
    Canvas3D canvas = new Canvas3D(config);
    add(canvas, BorderLayout.CENTER);

    universe = new SimpleUniverse(canvas);

    // �V�[�����\�z
    BranchGroup scene = createSceneGraph();
    scene.compile();

    // ���_���Z�b�g
    universe.getViewingPlatform().setNominalViewingTransform();

    // �}�E�X����
    orbitControls(canvas);

    universe.addBranchGraph(scene);
}
 
Example #10
Source File: Main.java    From javagame with MIT License 6 votes vote down vote up
/**
 * �V�[�����\�z����
 * 
 * @return BG
 */
public BranchGroup createSceneGraph() {
    BranchGroup bg = new BranchGroup();

    // �����ŃV�[�����쐬����

    // ���ˉ��{�[����lj�
    Ball ball = new Ball(0, 0, 0, 0.05, 0.02, -0.03);
    BallBehavior ballBehavior = new BallBehavior(ball, 50);
    bg.addChild(ball);
    bg.addChild(ballBehavior);

    // ����lj�
    bg.addChild(createBox());

    // ������lj�
    bg.addChild(createAmbientLight());
    bg.addChild(createDirectionalLight());

    return bg;
}
 
Example #11
Source File: MainPanel.java    From javagame with MIT License 5 votes vote down vote up
/**
 * ���E���\�z
 */
private void createSceneGraph() {
    // sceneBG�ɂ��낢��ڑ����邱�ƂŐ��E���\�������
    sceneBG = new BranchGroup();
    // ���E�͈̔́i�����Ȃǂ̋y�Ԕ͈́j
    bounds = new BoundingSphere(new Point3d(0, 0, 0), BOUND_SIZE);

    lightScene(); // ������sceneBG�ɒlj�
    addBackground(); // ���sceneBG�ɒlj�
    addSphere(); // ����lj�

    sceneBG.compile();
}
 
Example #12
Source File: RotatingCube.java    From javagame with MIT License 5 votes vote down vote up
public BranchGroup createSceneGraph() {
    BranchGroup bg = new BranchGroup();

    // �L���[�u���X����
    Transform3D rotate = new Transform3D();
    Transform3D tempRotate = new Transform3D();

    rotate.rotX(Math.PI / 4.0);
    tempRotate.rotY(Math.PI / 4.0);
    rotate.mul(tempRotate);

    TransformGroup rotateTG = new TransformGroup(rotate);

    // �L���[�u����]����
    TransformGroup spinTG = new TransformGroup();
    spinTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    // �J���[�L���[�u���쐬����spinTG�ɒlj�
    ColorCube cube = new ColorCube(0.4);
    spinTG.addChild(cube);

    // ��]�^��
    Alpha rotationAlpha = new Alpha(-1, 4000);
    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, spinTG);
    // �͈͂��w��
    BoundingSphere bounds = new BoundingSphere();
    rotator.setSchedulingBounds(bounds);
    spinTG.addChild(rotator);

    rotateTG.addChild(spinTG);
    bg.addChild(rotateTG);

    return bg;
}
 
Example #13
Source File: MainPanel.java    From javagame with MIT License 5 votes vote down vote up
/**
 * ���E���\�z
 */
private void createSceneGraph() {
    // sceneBG�ɂ��낢��ڑ����邱�ƂŐ��E���\�������
    sceneBG = new BranchGroup();
    // ���E�͈̔́i�����Ȃǂ̋y�Ԕ͈́j
    bounds = new BoundingSphere(new Point3d(0, 0, 0), BOUND_SIZE);

    lightScene(); // ������sceneBG�ɒlj�
    addBackground(); // ���sceneBG�ɒlj�
    
    Floor floor = new Floor();
    sceneBG.addChild(floor.getBG());

    sceneBG.compile();
}
 
Example #14
Source File: Axis.java    From javagame with MIT License 5 votes vote down vote up
public Axis() {
    axisBG = new BranchGroup();

    // Geometry�̐���
    LineArray axisX = new LineArray(2, LineArray.COORDINATES
            | LineArray.COLOR_3);
    LineArray axisY = new LineArray(2, LineArray.COORDINATES
            | LineArray.COLOR_3);
    LineArray axisZ = new LineArray(2, LineArray.COORDINATES
            | LineArray.COLOR_3);

    // ���_�̃Z�b�g
    Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f green = new Color3f(0.0f, 1.0f, 0.0f);
    Color3f blue = new Color3f(0.0f, 0.0f, 1.0f);

    axisX.setCoordinate(0, new Point3f(-10.0f, 0.0f, 0.0f));
    axisX.setCoordinate(1, new Point3f(10.0f, 0.0f, 0.0f));
    axisX.setColor(0, red);
    axisX.setColor(1, red);

    axisY.setCoordinate(0, new Point3f(0.0f, -10.0f, 0.0f));
    axisY.setCoordinate(1, new Point3f(0.0f, 10.0f, 0.0f));
    axisY.setColor(0, green);
    axisY.setColor(1, green);

    axisZ.setCoordinate(0, new Point3f(0.0f, 0.0f, -10.0f));
    axisZ.setCoordinate(1, new Point3f(0.0f, 0.0f, 10.0f));
    axisZ.setColor(0, blue);
    axisZ.setColor(1, blue);

    // axisBG�ɒlj�
    axisBG.addChild(new Shape3D(axisX));
    axisBG.addChild(new Shape3D(axisY));
    axisBG.addChild(new Shape3D(axisZ));
}
 
Example #15
Source File: Axis.java    From javagame with MIT License 5 votes vote down vote up
public Axis() {
    axisBG = new BranchGroup();

    // Geometry�̐���
    LineArray axisX = new LineArray(2, LineArray.COORDINATES | LineArray.COLOR_3);
    LineArray axisY = new LineArray(2, LineArray.COORDINATES | LineArray.COLOR_3);
    LineArray axisZ = new LineArray(2, LineArray.COORDINATES | LineArray.COLOR_3);

    // ���_�̃Z�b�g
    Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f green = new Color3f(0.0f, 1.0f, 0.0f);
    Color3f blue = new Color3f(0.0f, 0.0f, 1.0f);

    axisX.setCoordinate(0, new Point3f(-1.0f, 0.0f, 0.0f));
    axisX.setCoordinate(1, new Point3f(1.0f, 0.0f, 0.0f));
    axisX.setColor(0, red);
    axisX.setColor(1, red);

    axisY.setCoordinate(0, new Point3f(0.0f, -1.0f, 0.0f));
    axisY.setCoordinate(1, new Point3f(0.0f, 1.0f, 0.0f));
    axisY.setColor(0, green);
    axisY.setColor(1, green);

    axisZ.setCoordinate(0, new Point3f(0.0f, 0.0f, -1.0f));
    axisZ.setCoordinate(1, new Point3f(0.0f, 0.0f, 1.0f));
    axisZ.setColor(0, blue);
    axisZ.setColor(1, blue);

    // BG�ɒlj�
    axisBG.addChild(new Shape3D(axisX));
    axisBG.addChild(new Shape3D(axisY));
    axisBG.addChild(new Shape3D(axisZ));
}
 
Example #16
Source File: Main3D.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �V�[�����\�z����
 * @return BG
 */
public BranchGroup createSceneGraph() {
    BranchGroup bg = new BranchGroup();

    // ��]�pTG
    TransformGroup spinTG = new TransformGroup();
    spinTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // ��]�^��
    Alpha rotationAlpha = new Alpha(-1, 4000);
    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha,
            spinTG);

    // �͈͂��w��
    BoundingSphere bounds = new BoundingSphere();
    rotator.setSchedulingBounds(bounds);

    spinTG.addChild(rotator);

    // �g���C�t�H�[�X
    Triforce triforce = new Triforce();
    spinTG.addChild(triforce.getBG()); // spinTG�ɒlj��I

    bg.addChild(spinTG);

    return bg;
}
 
Example #17
Source File: KinematicObject.java    From jMAVSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public KinematicObject(World world) {
    super(world);
    rotation.setIdentity();
    transformGroup = new TransformGroup();
    transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    transform = new Transform3D();
    transformGroup.setTransform(transform);
    branchGroup = new BranchGroup();
    branchGroup.addChild(transformGroup);
}
 
Example #18
Source File: Helper.java    From MogwaiERDesignerNG with GNU General Public License v3.0 5 votes vote down vote up
public static BranchGroup addElementAt(Node aShape, Vector3f aTranslation, float aScale) {

        BranchGroup theGroup = new BranchGroup();
        theGroup.setCapability(BranchGroup.ALLOW_DETACH);

        Transform3D theTransform = new Transform3D();
        theTransform.setTranslation(aTranslation);
        theTransform.setScale(aScale);
        TransformGroup theTransformGroup = new TransformGroup(theTransform);
        theTransformGroup.addChild(aShape);

        theGroup.addChild(theTransformGroup);

        return theGroup;
    }
 
Example #19
Source File: KinematicObject.java    From jMAVSim with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public BranchGroup getBranchGroup() {
    return branchGroup;
}
 
Example #20
Source File: CrystalBall.java    From javagame with 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 #21
Source File: Floor.java    From javagame with MIT License 4 votes vote down vote up
public BranchGroup getBG() {
    return floorBG;
}
 
Example #22
Source File: Main3D.java    From javagame with MIT License 4 votes vote down vote up
/**
 * �V�[�����\�z����
 * 
 * @return BG
 */
public BranchGroup createSceneGraph() {
    BranchGroup bg = new BranchGroup();

    // ������3D�I�u�W�F�N�g��lj�

    // ���W����lj�
    Axis axis = new Axis();
    bg.addChild(axis.getBG());

    // �_��lj�
    Point3f[] vertices = { // �_�̍��W
            new Point3f(-0.5f, 0.5f, -0.5f),
            new Point3f(0.5f, 0.5f, -0.5f),
            new Point3f(0.5f, 0.5f, 0.5f),
            new Point3f(-0.5f, 0.5f, 0.5f),
            new Point3f(-0.5f, -0.5f, -0.5f),
            new Point3f(0.5f, -0.5f, -0.5f),
            new Point3f(0.5f, -0.5f, 0.5f),
            new Point3f(-0.5f, -0.5f, 0.5f)
    };

    Color3f[] colors = { // �_�̐F
            new Color3f(1.0f, 1.0f, 0.0f),
            new Color3f(1.0f, 1.0f, 0.0f),
            new Color3f(1.0f, 1.0f, 0.0f),
            new Color3f(1.0f, 1.0f, 0.0f),
            new Color3f(1.0f, 1.0f, 0.0f),
            new Color3f(1.0f, 1.0f, 0.0f),
            new Color3f(1.0f, 1.0f, 0.0f),
            new Color3f(1.0f, 1.0f, 0.0f)
    };

    // Geometry
    PointArray geo = new PointArray(8, PointArray.COORDINATES
            | PointArray.COLOR_3);
    geo.setCoordinates(0, vertices); // ���_���W���Z�b�g
    geo.setColors(0, colors); // �F���Z�b�g

    // Appearance
    Appearance app = new Appearance();
    PointAttributes attr = new PointAttributes(5.0f, false); // �_�̑傫��
    app.setPointAttributes(attr);

    bg.addChild(new Shape3D(geo, app));

    // �����܂�

    return bg;
}
 
Example #23
Source File: Triforce.java    From javagame with MIT License 4 votes vote down vote up
public Triforce() {
    triforceBG = new BranchGroup();

    // Geometry�̐���
    TriangleArray t1 = new TriangleArray(3, TriangleArray.COORDINATES
            | TriangleArray.COLOR_3);
    TriangleArray t2 = new TriangleArray(3, TriangleArray.COORDINATES
            | TriangleArray.COLOR_3);
    TriangleArray t3 = new TriangleArray(3, TriangleArray.COORDINATES
            | TriangleArray.COLOR_3);

    // ���_�̃Z�b�g
    Color3f yellow = new Color3f(1.0f, 1.0f, 0.0f); // �g���C�t�H�[�X�̐F

    // ��̎O�p�`
    t1.setCoordinate(0, new Point3f(0.0f, 0.6f, 0.0f));
    t1.setCoordinate(1, new Point3f(-0.3f, 0.0f, 0.0f));
    t1.setCoordinate(2, new Point3f(0.3f, 0.0f, 0.0f));
    t1.setColor(0, yellow);
    t1.setColor(1, yellow);
    t1.setColor(2, yellow);

    // �����̎O�p�`
    t2.setCoordinate(0, new Point3f(-0.3f, 0.0f, 0.0f));
    t2.setCoordinate(1, new Point3f(-0.6f, -0.6f, 0.0f));
    t2.setCoordinate(2, new Point3f(0.0f, -0.6f, 0.0f));
    t2.setColor(0, yellow);
    t2.setColor(1, yellow);
    t2.setColor(2, yellow);

    // �E���̎O�p�`
    t3.setCoordinate(0, new Point3f(0.3f, 0.0f, 0.0f));
    t3.setCoordinate(1, new Point3f(0.0f, -0.6f, 0.0f));
    t3.setCoordinate(2, new Point3f(0.6f, -0.6f, 0.0f));
    t3.setColor(0, yellow);
    t3.setColor(1, yellow);
    t3.setColor(2, yellow);

    // Appearance�̐ݒ�
    Appearance app = new Appearance();

    PolygonAttributes pAttr = new PolygonAttributes();
    pAttr.setCullFace(PolygonAttributes.CULL_NONE); // ���ʂ��`��

    app.setPolygonAttributes(pAttr);

    // BG�ɒlj�
    triforceBG.addChild(new Shape3D(t1, app));
    triforceBG.addChild(new Shape3D(t2, app));
    triforceBG.addChild(new Shape3D(t3, app));
}
 
Example #24
Source File: Axis.java    From javagame with MIT License 2 votes vote down vote up
/**
 * ���W����\��BG��Ԃ�
 * 
 * @return ���W����BG
 */
public BranchGroup getBG() {
    return axisBG;
}
 
Example #25
Source File: Axis.java    From javagame with MIT License 2 votes vote down vote up
/**
 * �\�z�������W����BG��Ԃ�
 * 
 * @return ���W����BG
 */
public BranchGroup getBG() {
    return axisBG;
}
 
Example #26
Source File: Triforce.java    From javagame with MIT License 2 votes vote down vote up
/**
 * �\�z����BG��Ԃ�
 * 
 * @return BG
 */
public BranchGroup getBG() {
    return triforceBG;
}