Obtain 2D onScreen projection coordinate?

Hi, all:

I created a Sphere, and I can drag it as I wish.
The code is like:


Sphere sphs = new Sphere(0.02f, someAppearance);
TramsformGroup sphTrans = new TransformGroup();
sphTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
sphTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
sphTrans.setCapability(Group.ALLOW_CHILDREN_EXTEND);
sphTrans.setCapability(Group.ALLOW_CHILDREN_READ);
sphTrans.setCapability(Group.ALLOW_CHILDREN_WRITE);
sphTrans.addChild(sphs);

I would like to obtain two things:

  1. the new coordinate of this “sphs” after I dragged the 3D object randomly.
    In my application now, after some rotation and translation, “sphs” changes its position on the screen image, however, it looks its 3D coordinate didn’t change at all. So, does that mean, the 3D coordinate won’t change even if I dragged it around??

  2. How to obtain the 2D onScreen projection coordinates after 3D transformation?
    For sure, the 2D on screen coordinate of this “sphs” varies all the time. How can I obtain the dynamic 2D projection coordinates of this “sphs”

Thanks in advance.

Best Regards
JIA

Best Regards
JIA Pei

  1. correct the coordinates in the geometry is defined in local space. They are transformed into eye space when rendered using the TransformGroups. You can use the the getLocalToVWorld method to get a transform you can use to transform the coordinates into world space, if that is what you are after.

  2. There might be something you can use in com.sun.j3d.utils.universe.ViewInfo. Why do you need this information?

Hi, Tom:

Thanks for your reply.
In fact, I would like to produce some .jpg file. I found some code to snap the entire view (onScreenCanvas) into a single .jpg file.

However, I would like to further realize the functionality as:

When I drag the object in the view, the object might move its position form A to B.
Now, I don’t want to snap the entire image, I would like to focus on this specific object.
That means, I would like to find a small rectangle, which just contains this object.
And, I snap this small rectangle and save it as my concerned .jpg file.
That’s why I’ve got to know the object’s 2D project coordinate(s).

So…
Seriously thank for your answering and should have some further suggestions
after you get to know my purpose, please do not hesitate to give me some further help.

Best Wishes
JIA

Hi,
Is it possible for a cascade of TransformGroups?

I mean, in my case, I’ve got a

Sphere sphere

which has a corresponding

TransformGroup sphereTrans

However, this sphereTrans belongs to a BranchGroup

m_BranchGroup.addChild(sphereTrans);

Further, this BranchGroup has a corresponding TransformGroup, say

m_TransformGroup.addChild(m_BranchGroup);

Now, I transform(including, rotation, scaling and translating) the top-level TransformGroup, say “m_TransformGroup”.
This m_TransformGroup doesn’t affect sphereTrans at all. But, sphere has been still transformed !!
This is correct !!!

However, how can I obtain the coordinate of this sphere now?

It looks like the total transform of this sphere replies on both TransformGroups “m_TransformGroup” and “sphereTrans”.

So, what are the exact code that I can use to obtain the coordinate (3D and 2D on screen projection) of “sphere”?

Urgent… Please do help.

Thanks in advance.

Best Regards
JIA

Problem solved.
Tom, you are right, use

getLocalToVWorld

Cheers
JIA