Hintergrundfarbe

T

theBigJimmy

Gast
Hallo,

ich habe ein ganz einfaches Problem:

Ich würde im folgendem Programm gerne die Hintergrundfarbe von schwarz auf weiß setzen... wie geht das?

Java:
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.Appearance;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.PointAttributes;
import javax.media.j3d.Transform3D;
 
import javax.swing.JFrame;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Matrix4f;
import javax.vecmath.Color3f;
import javax.vecmath.Vector3f;
import javax.vecmath.*;
 
import com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.behaviors.mouse.MouseTranslate;
import com.sun.j3d.utils.behaviors.mouse.MouseZoom;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.Cylinder;
 
import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
 
import java.util.LinkedList;
 
import java.lang.Math;
 
/**
 * @author Thomas.Darimont
 *
 */
public class test2 extends JFrame
{

 public test2() throws Exception
    {
        super("AlignTest");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
 
        Canvas3D canvas = new Canvas3D(
            SimpleUniverse.getPreferredConfiguration());
        canvas.setSize(320, 240);
        SimpleUniverse simpleUniverse = new SimpleUniverse(canvas);
        simpleUniverse.getViewingPlatform().setNominalViewingTransform();
 
        BranchGroup rootBranchGroup = new BranchGroup();
        TransformGroup rootTransformGroup = new TransformGroup();
 
        rootBranchGroup.addChild(rootTransformGroup);
        rootTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
 
        Appearance ap = new Appearance();
        ColoringAttributes ca = new ColoringAttributes();
        ca.setColor(0f, 0f, 150f);
        ap.setColoringAttributes(ca);
 
        Vector3f p0 = new Vector3f(-5f, -0.5f, 0.999583f);
        Transform3D transform3d = new Transform3D();
        transform3d.setTranslation(p0);
        TransformGroup rootTransformGroup2 = new TransformGroup(transform3d);
        rootTransformGroup2.addChild(new Box(0.02f, 0.02f, 0.02f, ap));
        rootTransformGroup.addChild(rootTransformGroup2);
 
 
        BoundingSphere boundingSphere = new BoundingSphere(
            new Point3d(0, 0, 0), 10000);
 
        MouseRotate mouseRotate = new MouseRotate();
        mouseRotate.setTransformGroup(rootTransformGroup); // !!!!!!!!!!
        mouseRotate.setSchedulingBounds(boundingSphere);
        rootBranchGroup.addChild(mouseRotate);
 
        MouseTranslate mouseTranslate = new MouseTranslate();
        mouseTranslate.setTransformGroup(rootTransformGroup); // !!!!!!!!!!!
        mouseTranslate.setSchedulingBounds(boundingSphere);
        rootBranchGroup.addChild(mouseTranslate);
 
        MouseZoom mouseZoom = new MouseZoom();
        mouseZoom.setTransformGroup(rootTransformGroup); // !!!!!!!!!
        mouseZoom.setSchedulingBounds(boundingSphere);
        rootBranchGroup.addChild(mouseZoom);
 
        KeyNavigatorBehavior keyNavigatorBehavior = new KeyNavigatorBehavior(
            rootTransformGroup);
        keyNavigatorBehavior.setSchedulingBounds(boundingSphere);
        rootBranchGroup.addChild(keyNavigatorBehavior);
 
        rootBranchGroup.compile();
 
        simpleUniverse.addBranchGraph(rootBranchGroup);
 
        add(canvas);
        pack();
        setVisible(true);
    }
 
    public static void main(String[] args) throws Exception
    {
        // TODO Auto-generated method stub
        test2 t = new test2();
    }
 
}

Viele Grüße und danke im Vorraus
 

theBigJimmy

Mitglied
Ok, habs selber rausgefunden:

Java:
        Color3f color = new Color3f(150f, 150f, 150f);
        Background background = new Background();
        background.setColor(color);
        background.setCapability(Background.ALLOW_COLOR_WRITE);
        background.setApplicationBounds(boundingSphere);
        rootBranchGroup.addChild(background);
 
Ähnliche Java Themen

Ähnliche Java Themen


Oben