Skip to main content

Adding ViewingPlatform to a TransformGroup

2 replies [Last post]
z5
Offline
Joined: 2007-06-26
Points: 0

Hi,

I have a TransformGroup with some content moving around (controlled by user input).
Now I´d like the ViewingPlatform to follow this object.
My first approach was to simply add the ViewingPlatform to the moving TransformGroup but this didnt work (ViewingPlatform is already a child of Locale I think).
I could apply the same transformations to my moving TG and the TG of the ViewingPlatform, but I´d like to avoid this. There must be a better way do this.
Any hints?

Message was edited by: z5

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
stylertim
Offline
Joined: 2006-05-04
Points: 0

> with some content moving around

Could you be a little more specific?

The easiest way to keep the "view centered" on a certain object, is to "transform" the ViewingPlatform in the same manner as the object. For instance, if you rotate an object around the center of the coordinate system, which basically is the constant position of the camera simulated by the ViewingPlatform, about the y-axis with an angle of 45° clockwise, simply rotate the ViewingPlatform the same way. If you translate the object 2 units towards the negative x-axis, translate the ViewingPlatform accordingly a.s.o..

If you want to increase or decrease the distance between the object and the ViewingPlatform you have to keep the platform stationary and move the object either in the direction of the look vector or in its opposite direction, depending on the effect you'd like to see.

Hope that helped.

- Thomas

starman2049
Offline
Joined: 2007-06-27
Points: 0

This is what I do, don't know if it will help or not...

My setup is as follows:
===========================================================
Canvas3D canvas3D;

setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
canvas3D = new Canvas3D(config);
canvas3D.setSize(575, 525);
add("Center", canvas3D);

m_bsBounds = new BoundingSphere(new Point3d(), 1000.0);

Locale myLocale = new Locale(new VirtualUniverse());

BranchGroup pickScene = new BranchGroup();
BranchGroup nonPickScene = createSceneGraph();
nonPickScene.setPickable(false);

sub_Column_ArrowsLoad flowArrows = new sub_Column_ArrowsLoad(rd, nonPickScene, 0.0f, 0.0f, 0.0f );
new sub_Column_ShipLoad(rd, nonPickScene, 0.0f, 0.0f, 0.0f );

sub_Column_3DToolTip toolTip = new sub_Column_3DToolTip(pickScene);

new sub_Column_SliderLoad(rd, pickScene, canvas3D, flowArrows, this, toolTip);
BranchGroup myView = createViewGraph(canvas3D, pickScene);

myLocale.addBranchGraph(pickScene);
myLocale.addBranchGraph(nonPickScene);
myLocale.addBranchGraph(myView);
===========================================================

And, my createViewGraph(...) s as follows:
===========================================================
private BranchGroup createViewGraph(Canvas3D canvas3D, BranchGroup pickScene)
{
sub_Column_MyMouseBehavior camera;

// Create the root of the branch graph
BranchGroup viewRoot = new BranchGroup();

TransformGroup steerTG = new TransformGroup();

ViewPlatform vp = new ViewPlatform();

View myView = new View();
myView.addCanvas3D(canvas3D);
myView.attachViewPlatform(vp);
myView.setPhysicalBody(new PhysicalBody());
myView.setPhysicalEnvironment(new PhysicalEnvironment());

Transform3D t3d = new Transform3D();
steerTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
steerTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
steerTG.setTransform(t3d);

myView.setBackClipDistance(1000);
myView.setFieldOfView(0.25);

camera = new sub_Column_MyMouseBehavior(steerTG, pickScene, canvas3D);
camera.setSchedulingBounds(m_bsBounds);

steerTG.addChild(vp);
viewRoot.addChild(steerTG);
viewRoot.addChild(camera);

return viewRoot;
}
===========================================================

This allows me to do what you ar saying (I think)

Hope this helps...