1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| //////////////CODE//////////////
class Siege {
private Frame motherApp;
private Vector3f vect;
public Siege(Frame motherApp, Vector3f vect) {
this.motherApp = motherApp;
this.vect = vect;
}
private Appearance mkAppWithTexture(String textureName) {
Appearance app = new Appearance();
TextureLoader loader = new TextureLoader(textureName, motherApp);
ImageComponent2D image = loader.getImage();
Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA,
image.getWidth(), image.getHeight());
texture.setImage(0, image);
texture.setEnable(true);
texture.setMagFilter(Texture.BASE_LEVEL_LINEAR);
texture.setMinFilter(Texture.BASE_LEVEL_LINEAR);
app.setTexture(texture);
app.setTextureAttributes(new TextureAttributes());
return app;
}
public BranchGroup createSiege() {
BranchGroup myScene = new BranchGroup();
Transform3D tr3d = new Transform3D();
tr3d.setTranslation(vect);
TransformGroup tg = new TransformGroup(tr3d);
Appearance LOGOApp = mkAppWithTexture("M:/workspace/FirstAppletCLT/src/LOGO.gif");
// on crée une apparence de couleur bleue
Appearance app_bleu = new Appearance();
ColoringAttributes bleu = new ColoringAttributes();
bleu.setColor(0.1f, 0.1f, 1.0f);
// on precise le rendu
bleu.setShadeModel(ColoringAttributes.NICEST);
app_bleu.setColoringAttributes(bleu);
// on crée un vecteur de translation 30 cm suivant les Y (dans l'autre
// sens)
Transform3D translate3 = new Transform3D();
translate3.set(new Vector3f(-0.4f, 0.4f, 0.0f));
// on crée un groupe de transformation TG3 suivant la matrice de
// transformation translate3
TransformGroup TG3 = new TransformGroup(translate3);
// on crée un cube qui herite de cette rotation
TG3.addChild(new Box(0.3f, 0.1f, 0.4f, Box.GENERATE_TEXTURE_COORDS,
LOGOApp));
// on crée un vecteur de translation 30 cm suivant les Y (dans l'autre
// sens)
Transform3D translate = new Transform3D();
translate.set(new Vector3f(0.0f, 1.0f, -0.5f));
// on crée un groupe de transformation TG3 suivant la matrice de
// transformation translate3
TransformGroup TG = new TransformGroup(translate);
// on crée un cube qui herite de cette rotation
TG.addChild(new Box(0.1f, 0.6f, 0.4f, Box.GENERATE_TEXTURE_COORDS,
LOGOApp));
// on crée un vecteur de translation 30 cm suivant les Y (dans l'autre
// sens)
Transform3D translate4 = new Transform3D();
translate4.set(new Vector3f(-0.6f, 0.0f, -0.5f));
// on crée un groupe de transformation TG3 suivant la matrice de
// transformation translate3
TransformGroup TG4 = new TransformGroup(translate4);
// on crée un cube qui herite de cette rotation
TG4.addChild(new Box(0.05f, 0.3f, 0.2f, Box.GENERATE_TEXTURE_COORDS,
app_bleu));
// on crée un vecteur de translation 30 cm suivant les Y (dans l'autre
// sens)
Transform3D translate5 = new Transform3D();
translate5.set(new Vector3f(-0.2f, 0.0f, -0.5f));
// on crée un groupe de transformation TG3 suivant la matrice de
// transformation translate3
TransformGroup TG5 = new TransformGroup(translate5);
// on crée un cube qui herite de cette rotation
TG5.addChild(new Box(0.05f, 0.3f, 0.2f, Box.GENERATE_TEXTURE_COORDS,
app_bleu));
tg.addChild(TG3);
tg.addChild(TG);
tg.addChild(TG4);
tg.addChild(TG5);
myScene.addChild(tg);
myScene.compile();
return myScene;
}
} |
Partager