java - Correct usage of TransformGroup -
i have started graphics assignment , first use of java3d. have started off attempting build chair (don't laugh @ following :p).
i wanted know if tell me correct usage pattern because pretty sure little bit off.
here have drawn:
as can see box seat , 4 cylinders legs.
here code used draw it:
public class chair { public chair() { simpleuniverse universe = new simpleuniverse(); branchgroup group = new branchgroup(); // main seat component box box = new box(.39f,.03f,.37f, new appearance()); transformgroup seatgroup = new transformgroup(); transform3d transform = new transform3d(); vector3f vector = new vector3f(.0f, .0f, .0f); transform.settranslation(vector); seatgroup.settransform(transform); seatgroup.addchild(box); // legs of chair cylinder leg1 = new cylinder(.07f, .45f); cylinder leg2 = new cylinder(.07f, .45f); cylinder leg3 = new cylinder(.07f, .45f); cylinder leg4 = new cylinder(.07f, .45f); //create new transformgroup, vector position each leg transformgroup leg1group = new transformgroup(); transform3d legtransform = new transform3d(); vector3f leg1position = new vector3f(-.37f, -0.225f, -.35f); legtransform.settranslation(leg1position); leg1group.settransform(legtransform); leg1group.addchild(leg1); seatgroup.addchild(leg1group); transformgroup leg2group = new transformgroup(); transform3d leg2transform = new transform3d(); vector3f leg2position = new vector3f(.37f, -0.225f, .35f); leg2transform.settranslation(leg2position); leg2group.settransform(leg2transform); leg2group.addchild(leg2); seatgroup.addchild(leg2group); transformgroup leg3group = new transformgroup(); transform3d leg3transform = new transform3d(); vector3f leg3position = new vector3f(.37f, -0.225f, -.35f); leg3transform.settranslation(leg3position); leg3group.settransform(leg3transform); leg3group.addchild(leg3); seatgroup.addchild(leg3group); transformgroup leg4group = new transformgroup(); transform3d leg4transform = new transform3d(); vector3f leg4position = new vector3f(-.37f, -0.225f, .35f); leg4transform.settranslation(leg4position); leg4group.settransform(leg4transform); leg4group.addchild(leg4); seatgroup.addchild(leg4group); //add seat group main object group group.addchild(seatgroup); //stuff see universe// color3f light1color = new color3f(.1f, 1.4f, .1f); // green light boundingsphere bounds = new boundingsphere(new point3d(0.0, 0.0, 0.0), 100.0); vector3f light1direction = new vector3f(4.0f, -7.0f, -12.0f); directionallight light1 = new directionallight(light1color, light1direction); light1.setinfluencingbounds(bounds); group.addchild(light1); universe.getviewingplatform().setnominalviewingtransform(); // add group of objects universe universe.addbranchgraph(group); canvas3d canvas = new canvas3d(simpleuniverse.getpreferredconfiguration()); viewingplatform viewplatform = universe.getviewingplatform(); boundingsphere boundingsphere = new boundingsphere(new point3d(0f, 0f, 0f), 100f); // add behaviour viewplatform, allowing user rotate, zoom, , straff scene orbitbehavior orbitbehaviour = new orbitbehavior(canvas, orbitbehavior.reverse_all | orbitbehavior.stop_zoom); orbitbehaviour.setschedulingbounds(boundingsphere); viewplatform.setviewplatformbehavior(orbitbehaviour); } public static void main(string[] args) { new chair(); } }
i want know if correct usage of groups seems there lot of duplication... if shed light on appreciate lot !!
this step towards learning java3d. taking homemade or per made script , being able read, understand , memorizing code can become faster , better programmer. define better take ones experience , force onto you. learning in order master need follow own methods. because every person different in way. follow foot steps of per's don't step directly in indent.
Comments
Post a Comment