Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (589)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Obtain 2D onScreen projection coordinate?  (Read 3090 times)
0 Members and 1 Guest are viewing this topic.
Offline jiapei100

Junior Devvie





« Posted 2009-12-16 08:04:37 »


Hi, all:

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

1  
2  
3  
4  
5  
6  
7  
8  
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

Welcome to Vision Open
http://www.visionopen.com
Offline tom
« Reply #1 - Posted 2009-12-16 16:48:10 »

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?

Offline jiapei100

Junior Devvie





« Reply #2 - Posted 2009-12-16 17:08:36 »


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




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?

Welcome to Vision Open
http://www.visionopen.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jiapei100

Junior Devvie





« Reply #3 - Posted 2009-12-17 05:19:47 »


Hi,
Is it possible for a cascade of TransformGroups?

I mean, in my case, I've got a
1  
Sphere sphere

which has a corresponding
1  
TransformGroup sphereTrans


However, this sphereTrans belongs to a BranchGroup
1  
m_BranchGroup.addChild(sphereTrans);


Further, this BranchGroup has a corresponding TransformGroup, say
1  
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




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?

Welcome to Vision Open
http://www.visionopen.com
Offline jiapei100

Junior Devvie





« Reply #4 - Posted 2009-12-18 05:45:38 »


Problem solved.
Tom, you are right, use

1  
getLocalToVWorld


Cheers
JIA

Welcome to Vision Open
http://www.visionopen.com
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (22 views)
2014-11-22 12:13:56

xFryIx (69 views)
2014-11-13 12:34:49

digdugdiggy (48 views)
2014-11-12 21:11:50

digdugdiggy (42 views)
2014-11-12 21:10:15

digdugdiggy (36 views)
2014-11-12 21:09:33

kovacsa (60 views)
2014-11-07 19:57:14

TehJavaDev (63 views)
2014-11-03 22:04:50

BurntPizza (61 views)
2014-11-03 18:54:52

moogie (76 views)
2014-11-03 06:22:04

CopyableCougar4 (77 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!