public class Sun extends BranchGroup{
Canvas3D canvas3D;
String nameFile;
float sizeSun;
float scaleTexture;
public Sun(Canvas3D canvas3D, String nameFile){
setDefault(canvas3D, nameFile);
createSun();
}
public Sun(Canvas3D canvas3D, String nameFile, float sizeSun, float scaleTexture){
setDefault(canvas3D, nameFile);
this.sizeSun = sizeSun;
this.scaleTexture = scaleTexture;
createSun();
}
private void setDefault(Canvas3D canvas3D, String nameFile){
this.sizeSun = 1.0f;
this.scaleTexture = 1.0f;
this.canvas3D = canvas3D;
this.nameFile = nameFile;
}
private Appearance createTexture(){
TextureLoader tex = new TextureLoader(this.getClass().getResource(nameFile),canvas3D);
Texture2D tex2d = (Texture2D) tex.getTexture();
Appearance app = new Appearance();
app.setTexture(tex2d);
TextureAttributes texAtt = new TextureAttributes();
Transform3D trans = new Transform3D();
trans.set(scaleTexture);
texAtt.setTextureTransform(trans);
app.setTextureAttributes(texAtt);
return app;
}
private void createSun(){
BranchGroup bg = new BranchGroup();
Sphere objSun = new Sphere(sizeSun, Sphere.GENERATE_TEXTURE_COORDS, 120, createTexture());
bg.addChild(objSun);
this.addChild(bg);
}
public Canvas3D getCanvas3D() {
return canvas3D;
}
public void setCanvas3D(Canvas3D canvas3d) {
canvas3D = canvas3d;
}
public String getNameFile() {
return nameFile;
}
public void setNameFile(String nameFile) {
this.nameFile = nameFile;
}
public float getSizeSun() {
return sizeSun;
}
public void setSizeSun(float sizeSun) {
this.sizeSun = sizeSun;
}
}