在运行时改变一个球的颜色

时间:2010-03-04 12:44:40

标签: java 3d

我有一个有白色球(3d图形)的场景,场景在我的框架上也在我的框架的北面有一个面板有一个按钮,点击按钮球将是红色的。我可以这样做吗?请帮助我谢谢

这是创建白色球体的代码:

  protected void floatingWhiteSphere() {

    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f specular = new Color3f(0.9f, 0.9f, 0.9f);

    Material blueMat = new Material(white, black, white, specular, 25.0f);
    // sets ambient, emissive, diffuse, specular, shininess
    blueMat.setLightingEnable(true);

    Appearance blueApp = new Appearance();
    blueApp.setMaterial(blueMat);

    // position the sphere
    Transform3D t3d = new Transform3D();
    t3d.set(new Vector3f(0, 1, -5));
    TransformGroup tg = new TransformGroup(t3d);
    tg.addChild(new Sphere(1.0f, blueApp));   // set its radius and appearance

    sceneBG.addChild(tg);

}

1 个答案:

答案 0 :(得分:0)

我认为通过设置第二种材质,将第二种材质加载到对象并在单击按钮时重新绘制框架应该可以解决问题。我对绘画程序不是很熟悉,因此很抱歉......