Managing the layout of a Java MainFrame of Canvas3d
Posted
by John N
on Stack Overflow
See other posts from Stack Overflow
or by John N
Published on 2010-03-30T18:29:35Z
Indexed on
2010/03/30
18:33 UTC
Read the original article
Hit count: 429
Hi, Im trying to organise the layout of four canvas3d objects in a single MainFrame. Iv tried using some layout managers but none are working (or im doing it wrong). Can anyone give me advice or point me to a way to get this to display the four canvas's as a grid of four?
Thanks,
John
public class Main {
public static void Main(){
Window win = new Window();
}
}
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.Locale;
import javax.media.j3d.PhysicalBody;
import javax.media.j3d.PhysicalEnvironment;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.View;
import javax.media.j3d.ViewPlatform;
import javax.media.j3d.VirtualUniverse;
import javax.vecmath.Vector3f;
import com.sun.j3d.utils.picking.PickCanvas;
public class Universe {
boolean camera = true;
Canvas3D canvas1, canvas2, canvas3, canvas4;
VirtualUniverse universe;
Locale locale;
TransformGroup vpTrans1, vpTransRight, vpTransFront, vpTransPers;
TransformGroup mouseTransform = null;
View view1, view2, view3, view4;
BranchGroup scene;
PickCanvas pickCanvas1 = null;
PickCanvas pickCanvas2 = null;
PickCanvas pickCanvas3 = null;
PickCanvas pickCanvas4 = null;
BranchGroup obj = new BranchGroup();
// Create a BranchGroup node for the view platform
BranchGroup vpRoot = new BranchGroup();
//Temp vars for cam movement
public Universe(Canvas3D c1, Canvas3D c2, Canvas3D c3, Canvas3D c4, BranchGroup scene) {
this.canvas1 = c1;
this.canvas2 = c2;
this.canvas3 = c3;
this.canvas4 = c4;
this.scene = scene;
// Establish a virtual universe that has a single
// hi-res Locale
universe = new VirtualUniverse();
locale = new Locale(universe);
// Create a PhysicalBody and PhysicalEnvironment object
PhysicalBody body = new PhysicalBody();
PhysicalEnvironment environment =
new PhysicalEnvironment();
// Create a View and attach the Canvas3D and the physical
// body and environment to the view.
view1 = new View();
view1.addCanvas3D(c1);
view1.addCanvas3D(c2);
view1.addCanvas3D(c3);
view1.addCanvas3D(c4);
view1.setPhysicalBody(body);
view1.setPhysicalEnvironment(environment);
// Create a BranchGroup node for the view platform
BranchGroup vpRoot = new BranchGroup();
// Create a ViewPlatform object, and its associated
// TransformGroup object, and attach it to the root of the
// subgraph. Attach the view to the view platform.
Transform3D t = new Transform3D();
t.set(new Vector3f(0.0f, 0.0f, 2.0f));
ViewPlatform vp = new ViewPlatform();
vpTrans1 = new TransformGroup(t);
vpTrans1.addChild(vp);
vpRoot.addChild(vpTrans1);
vpRoot.addChild(scene);
view1.attachViewPlatform(vp);
// Attach the branch graph to the universe, via the
// Locale. The scene graph is now live!
locale.addBranchGraph(vpRoot);
}
}
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.Locale;
import javax.media.j3d.PhysicalBody;
import javax.media.j3d.PhysicalEnvironment;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.View;
import javax.media.j3d.ViewPlatform;
import javax.media.j3d.VirtualUniverse;
import javax.vecmath.Vector3f;
import com.sun.j3d.utils.picking.PickCanvas;
public class Universe {
boolean camera = true;
Canvas3D canvas1, canvas2, canvas3, canvas4;
VirtualUniverse universe;
Locale locale;
TransformGroup vpTrans1, vpTransRight, vpTransFront, vpTransPers;
TransformGroup mouseTransform = null;
View view1, view2, view3, view4;
BranchGroup scene;
PickCanvas pickCanvas1 = null;
PickCanvas pickCanvas2 = null;
PickCanvas pickCanvas3 = null;
PickCanvas pickCanvas4 = null;
BranchGroup obj = new BranchGroup();
// Create a BranchGroup node for the view platform
BranchGroup vpRoot = new BranchGroup();
//Temp vars for cam movement
public Universe(Canvas3D c1, Canvas3D c2, Canvas3D c3, Canvas3D c4, BranchGroup scene) {
this.canvas1 = c1;
this.canvas2 = c2;
this.canvas3 = c3;
this.canvas4 = c4;
this.scene = scene;
// Establish a virtual universe that has a single
// hi-res Locale
universe = new VirtualUniverse();
locale = new Locale(universe);
// Create a PhysicalBody and PhysicalEnvironment object
PhysicalBody body = new PhysicalBody();
PhysicalEnvironment environment =
new PhysicalEnvironment();
// Create a View and attach the Canvas3D and the physical
// body and environment to the view.
view1 = new View();
view1.addCanvas3D(c1);
view1.addCanvas3D(c2);
view1.addCanvas3D(c3);
view1.addCanvas3D(c4);
view1.setPhysicalBody(body);
view1.setPhysicalEnvironment(environment);
// Create a BranchGroup node for the view platform
BranchGroup vpRoot = new BranchGroup();
// Create a ViewPlatform object, and its associated
// TransformGroup object, and attach it to the root of the
// subgraph. Attach the view to the view platform.
Transform3D t = new Transform3D();
t.set(new Vector3f(0.0f, 0.0f, 2.0f));
ViewPlatform vp = new ViewPlatform();
vpTrans1 = new TransformGroup(t);
vpTrans1.addChild(vp);
vpRoot.addChild(vpTrans1);
vpRoot.addChild(scene);
view1.attachViewPlatform(vp);
// Attach the branch graph to the universe, via the
// Locale. The scene graph is now live!
locale.addBranchGraph(vpRoot);
}
}
© Stack Overflow or respective owner