2009-07-31 55 views
0

我想在Java 3D中绘制透明平面(X [0..100],Y [0..100],Z = 0),但无法弄清楚。我查看了教程页面,仍然找不到任何示例程序。如何在Java 3D中绘制透明平面?

我试图找到一个“平面”对象作为BranchGroup添加到我现有的TransformGroup,但没有这样一个平面对象;我应该使用什么?我如何使它透明?

+1

如果它是透明的,你怎么能肯定它的不存在? :-)对不起,没有冒犯。 (你确定它被称为飞机?)提供更多信息。 – zoidbeck 2009-07-31 19:09:17

回答

0

这是我在直方图上使用的一段代码 - 这可能在平面上工作。

private static void createAppearances() { 
    normalAppearance = new Appearance(); 
    normalAppearance.setMaterial(normalMaterial); 
    selectedAppearance = new Appearance(); 
    selectedAppearance.setMaterial(selectedMaterial); 
    TransparencyAttributes ta = new TransparencyAttributes(); 

    ta.setTransparencyMode (TransparencyAttributes.BLENDED); 
    ta.setTransparency (DEFAULT_HISTOGRAM_ALPHA); 

    normalAppearance.setTransparencyAttributes (ta); 
    selectedAppearance.setTransparencyAttributes(ta); 
} 

如果我没记错,关键是TransparencyAttributes。我希望我能告诉你更多,但我现在无法得到它(缺少一些与3D无关的旧图书馆)。

0

试试这个代码...

BranchGroup group = new BranchGroup(); //Content branch. 
PolygonAttributes p = new PolygonAttributes(); //Not sure how to make it transparent/try code above. 
Appearance planeAppearance = new Appearance(); 
planeAppearance.setPolygonAttributes (p); 
Color3f planeColor = new Color3f (1.0f, 1.0f, 1.0f); //This makes it white. 
ColoringAttributes planeCA = new ColoringAttributes (planeColor, 1); 
planeAppearance.setColoringAttributes(planeCA); 
QuadArray plane = new QuadArray (4, QuadArray.COORDINATES); //This makes the plane. 
    plane.setCoordinate(0, new Point3f(-5f, -5f, -15f)); //You specify your own cornerpoints... 
    plane.setCoordinate(1, new Point3f(5f, -5f, -15f)); 
    plane.setCoordinate(2, new Point3f(5f, 5f, -15f)); 
    plane.setCoordinate(3, new Point3f(-5f, 5f, -15f)); 
group.addChild(new Shape3D(plane, planeAppearance)); //Add plane to content branch.