Skip to main content

A small rotation during translation

9 replies [Last post]
ssid19
Offline
Joined: 2006-02-17

Hi,

I am not a Computer Science guy and have limited knowledge about both, Java and Java3D. When i translate a primitive ( say a box), at the center i see only one surface but at the corner of the canvas, i see three surfaces due to fixed view point.
This is the code i have: -

SimpleUniverse sU = new SimpleUniverse(canvas3d);
Transform3D vT = new Transform3D();
vT.setTranslation(new Vector3f(0,0,50));
sU.getViewingPlatform().getViewPlatformTransform().setTransform(vT);
BranchGroup scene = createSceneGraph(sU, canvas3d, listener);
scene.compile();
sU.addBranchGraph(scene);

There is no mention of parallel or prespective views. Please let me know how to change it to translate it without rotation. I am urgent need of it, any help will be greatly appreciated.

Thanks
Sid

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
darrinps
Offline
Joined: 2003-06-12

Hmmm...this did not work for me (although it did seem to reduce the rotation a little).

Here is what I have:

scene = createSceneGraph();
u = new SimpleUniverse(canvas3D);

View view0 = u.getViewer().getView();
View view = new View();
PhysicalBody myBod = view0.getPhysicalBody();
view.setPhysicalBody(myBod);
view.setPhysicalEnvironment(view0.getPhysicalEnvironment());
view.attachViewPlatform(u.getViewingPlatform().getViewPlatform());

//Stop the rotation upon translation
view.setProjectionPolicy(View.PARALLEL_PROJECTION);
// view.setFieldOfView(Math.toRadians(30.0d));

// Move the ViewPlatform back a little so the objects in the scene can be viewed.
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);

Am I doing something wrong? The image does indeed rotate while being translated (using the built in MouseTranslate).

Any ideas as to what is wrong?

Thanks!

nitro
Offline
Joined: 2004-09-12

You change the view policy of view with no canvas attached to it.
change your code as following:
[code]
scene = createSceneGraph();
u = new SimpleUniverse(canvas3D);

View view = u.getViewer().getView();
//Stop the rotation upon translation
view.setProjectionPolicy(View.PARALLEL_PROJECTION);
// view.setFieldOfView(Math.toRadians(30.0d));

// Move the ViewPlatform back a little so the objects in the scene can be viewed.
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
[/code]

By the way: you do not stop the rotation, there is no rotation is just becaus if you do not stand in central front of an object (in perspective view) you will see some parts of the sides (as in the real world)

darrinps
Offline
Joined: 2003-06-12

That did it!

Thanks.

BTW, it did increase the scale quite a bit for some reason...no problem as I can rescale, but I didn't expect that to happen.

Anonymous

..see class "View" method "setProjectionPolicy" in java3d 1.3.2 documentation.

aces
Offline
Joined: 2003-07-17

add something like below, after universe creation.

[code]
View view = myCanvas3D.getView();
// using narrow view instead default PI/4 (45º)
view.setFieldOfView(Math.toRadians(30.0d));

// RADICAL approach. Lost depth, make far looks close
// rarely used.
view.setProjectionPolicy(View.PARALLEL_PROJECTION);
[/code]

See Java3D example PickTest demo, use Alt + Mouse Righ-click drag, in both Parspective and Parallel mode.

nitro
Offline
Joined: 2004-09-12

> // RADICAL approach. Lost depth, make far looks close
>
> // rarely used.
> view.setProjectionPolicy(View.PARALLEL_PROJECTION);
> [/code]
>

I think for technical uses (e.g civil engineering CAD) parallel projection is comonly used.

ssid19
Offline
Joined: 2006-02-17

Hi,

I tried this option

View view = myCanvas3D.getView();
view.setProjectionPolicy(View.PARALLEL_PROJECTION);

I am gettin an error at myCanvas3D ...it is not letting me create a view.............any suggestions

the code again

SimpleUniverse simpleU = new SimpleUniverse(canvas3d);
Transform3D viewerTranslation = new Transform3D();
viewerTranslation.setTranslation(new Vector3f(0,0,50));
simpleU.getViewingPlatform().getViewPlatformTransform().setTransform(viewerTranslation);
BranchGroup scene = createSceneGraph(simpleU, canvas3d, listener);
scene.compile();
simpleU.addBranchGraph(scene);

The problem is, i cant add a new view ...and transform3D is deciding the prespective view point at Z= 50.

Thanks
Sid

aces
Offline
Joined: 2003-07-17

Ops !

You do not create a new View, just update your current View, creates automagically by Canvas3D/SimpleUniverse.
Of course you must switch [i] "myCanvas"[/i] for your [i]"canvas3d"[/i].

try
SimpleUniverse simpleU = new SimpleUniverse(canvas3d); [b]
View view = canvas3d.getView();
view.setProjectionPolicy(View.PARALLEL_PROJECTION); [/b]
Transform3D viewerTranslation = new Transform3D();
...(your code)

>Nitro
>.. Parallel view used in Civil engineering ...
Yes, you are right, Nitro. For cuts. I remember this...
And I am Civil Engineer :D

Message was edited by: aces
There was atype error in canvas3d name

ssid19
Offline
Joined: 2006-02-17

Hi,

Thanks alot for your help. It is done !!
Thanks once again !!

Sid