Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Moving view point

843799Dec 12 2001 — edited Dec 14 2001
I'm developing a simple application which displays a set of x,y,z axes where the x axis is a line from (0,0,0) to (1,0,0), the y axis is a line from (0,0,0) to (0,1,0) and the z axis is a line from (0,0,0) to (0,0,1).
When I draw this on the Canvas, it only draw in the top right quarter (because 0,0 is the middle of the canvas)
How can I move my view position so that 0,0 will be the bottom left corner of the canvas?

The code so far is:
public class Graph3D {

	private Canvas3D canvas3D;
	private Point3d[] points = new Point3d[4];
	private UpdateBehavior uBehavior;
	private CubicCurve3D cc;
	private CurveGuides cg;

	public Graph3D(Point3d[] p){

		points = p;

		GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
		canvas3D = new Canvas3D(config);

		BranchGroup scene = createSceneGraph();
		scene.compile();

		SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

		simpleU.getViewingPlatform().setNominalViewingTransform();

		simpleU.addBranchGraph(scene);
	}


	public BranchGroup createSceneGraph() {
		// Create the root of the branch group
		BranchGroup objRoot = new BranchGroup();

		// rotate object has composite transformation matrix
		Transform3D rotate = new Transform3D();
		Transform3D tempRotate = new Transform3D();

		rotate.rotX(Math.PI/20.0d);
		tempRotate.rotY(Math.PI/6.0d);

		rotate.mul(tempRotate);
		TransformGroup objRotate = new TransformGroup(rotate);

		cc = new CubicCurve3D(points[0],points[1],points[2],points[3]);
		Point3d[] ps = {points[0],points[1],points[2],points[3]};
		cg = new CurveGuides(ps);

		cc.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
		cc.setCapability(Shape3D.ALLOW_GEOMETRY_READ);

		cg.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
		cg.setCapability(Shape3D.ALLOW_GEOMETRY_READ);

		Line3D ax1 = new Line3D(new Point3d(0,0,0), new Point3d(1,0,0));
		Line3D ax2 = new Line3D(new Point3d(0,0,0), new Point3d(0,1,0));
		Line3D ax3 = new Line3D(new Point3d(0,0,0), new Point3d(0,0,1));

		objRotate.addChild(ax1);
		objRotate.addChild(ax2);
		objRotate.addChild(ax3);
		objRotate.addChild(cc);
		objRotate.addChild(cg);

		uBehavior = new UpdateBehavior(cc,cg);
		uBehavior.setSchedulingBounds(new BoundingSphere());

		objRoot.addChild(objRotate);
		objRoot.addChild(uBehavior);

		return objRoot;
	}

	public Canvas3D getCanvas3D() {
		return canvas3D;
	}

	public void updatePoints(Point3d[] p)
	{
		points = p;
		uBehavior.setNewPoints(points);
	}
}

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jan 11 2002
Added on Dec 12 2001
3 comments
94 views