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 113 114 115 116 117 118 119 120 121 122
|
public BranchGroup createSceneGraph()
{
BranchGroup parent = new BranchGroup();
Transform3D translate = new Transform3D();
translate.setTranslation(new Vector3f(0, 1, 0));
Transform3D rotate = new Transform3D();
rotate.rotY(Math.PI/4);
translate.mul(rotate);
//***************************************
TransformGroup jambe = new TransformGroup();
jambe.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
jambe.addChild(createJambeD());
TransformGroup cuisse = new TransformGroup();
cuisse.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
cuisse.addChild(createCuisseD());
/**************************************/
Alpha alpha = new Alpha(10, 4000);
alpha.setMode(Alpha.DECREASING_ENABLE|Alpha.INCREASING_ENABLE);
alpha.setDecreasingAlphaDuration(4000);
alpha.setStartTime(System.currentTimeMillis());
Transform3D axe = new Transform3D();
AxisAngle4f axisAngle = new AxisAngle4f(0, 0, 1, (float)Math.PI/4);
axe.set(axisAngle);
RotationInterpolator rotator = new RotationInterpolator(alpha, jambe);
rotator.setTransformAxis(axe);
rotator.setSchedulingBounds(new BoundingSphere(new Point3d(0, 0, 0), 10));
jambe.addChild(rotator);
/**************************************/
PointLight pLight = new PointLight();
pLight.setColor(new Color3f(1f, 1f, 0.5f));
pLight.setPosition(0, 0, 1);
pLight.setInfluencingBounds(new BoundingSphere());
parent.addChild(pLight);
TransformGroup transform = new TransformGroup(translate);
transform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
transform.addChild(cuisse);
transform.addChild(jambe);
parent.addChild(transform);
Background bg = new Background(new Color3f(1, 1, 1));
bg.setApplicationBounds(new BoundingSphere());
parent.addChild(bg);
return parent;
}
private TransformGroup createCuisseD()
{
Cylinder cuisse = new Cylinder(0.03f, 0.32f);
Sphere genoux = new Sphere(0.04f);
Transform3D translateGenoux = new Transform3D();
translateGenoux.setTranslation(new Vector3f(0.0f, -0.18f, 0.f));
TransformGroup gen = new TransformGroup(translateGenoux);
gen.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
gen.addChild(genoux);
Transform3D translateCuisse = new Transform3D();
translateCuisse.setTranslation(new Vector3f(-0.066f, -0.76f, -0.01f));
Transform3D rot = new Transform3D();
rot.rotZ(-Math.PI/24);
translateCuisse.mul(rot);
TransformGroup tg = new TransformGroup(translateCuisse);
tg.addChild(cuisse);
tg.addChild(gen);
return tg;
}
private TransformGroup createJambeD()
{
Cylinder cuisse = new Cylinder(0.026f, 0.34f);
Box pied = new Box(0.05f, 0.03f, 0.1f, null);
Transform3D translateGenoux = new Transform3D();
translateGenoux.setTranslation(new Vector3f(0.0f, -0.2f, 0.05f));
TransformGroup gen = new TransformGroup(translateGenoux);
gen.addChild(pied);
Transform3D translateCuisse = new Transform3D();
translateCuisse.setTranslation(new Vector3f(-0.09f, -1.1f, -0.01f));
Transform3D rot = new Transform3D();
rot.rotZ(-Math.PI/12);
//translateCuisse.mul(rot);
TransformGroup tg = new TransformGroup(translateCuisse);
tg.addChild(cuisse);
tg.addChild(gen);
return tg;
} |
Partager