开发者

changing the color of one ball at the run time

开发者 https://www.devze.com 2022-12-22 02:10 出处:网络
I have a scene that has a white ball(3d graphics) and the scene is on my frame also the north of my frame there is a panel which has a button and by clicking on the button the ball will be red.how can

I have a scene that has a white ball(3d graphics) and the scene is on my frame also the north of my frame there is a panel which has a button and by clicking on the button the ball will be red.how can I do that?please help me thanks

this is the code that creates a white sphere:

  protected void floatingWhiteSphere() {

    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f specula开发者_运维百科r = 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);

}


I think by setting a second material, loading the second material to the object and repainting the frame when the button is clicked should do the trick. I'm not very familiar with painting procedures to get into details so sorry...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号