Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  How to calculate height of the loaded object?  (Read 2449 times)
0 Members and 1 Guest are viewing this topic.
Offline jiapei100

Junior Member





« Posted 2009-12-19 22:28:05 »

Hi, all:

Question again.

After loading a Scene, I would like to know the loaded object's absolute height at the very first loading without any further transform yet.
How to do that?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
int flags = ObjectFile.TRIANGULATE | ObjectFile.STRIPIFY | ObjectFile.RESIZE;
ObjectFile f = new ObjectFile(flags, 0.0f);
m_S = null;
try {
   m_S = f.load(fname);
} catch (FileNotFoundException e)
{
        ...
}
m_BGFace = m_S.getSceneGroup();
m_Object3d = (Shape3D)m_BGFace.getChild(0);
Bounds m_ObjBounds = m_Object3d.getBounds();
// Now, I would like to obtain the current size (better in 3 dimensions) of m_Obj3D !!


It seems ".obj" file is stored in a specific format that, the longest dimension is used to normalize the loaded object.
Say, in may case, my .obj is stored in the way that:
since from the top to bottom, the object is longest, longer than the size from left side to right side,
and longer than the size from the front to the back, so, the very top line of the object has the coordinate (y_top = 1.0)
and the very bottom line of the object has the coordinate (y_bottom = -1.0)

However, the size (1.0-(-1.0)=2.0) is corresponding to how many pixels on the screen?

This seems to have nothing to do with getLocalToVworld(), right?

Seriously urgent. Please do help.

Best Regards
JIA

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

Junior Member





« Reply #1 - Posted 2009-12-19 22:32:22 »

I'm not sure what you're using, but if you determine the distance between the farthest top point to the farthest bottom point, and then multiply that by your scaling value, you should have the correct size.

Offline jiapei100

Junior Member





« Reply #2 - Posted 2009-12-20 01:15:45 »


Hi, Thanks elias !!

You are absolutely correct.
[size=15pt]If I'm able to know the distance between the farthest top point to the farthest bottom point,[/size]
I should be able to calculate out the correct size.

You point out what's the key, but you didn't show me the answer !!!
[size=15pt]How can I obtain the coordinate of the farthest top point? and How can I obtain the coordinate of the farthest bottom point?[/size]

Can you give me a clue? I know that getLocalToVworld() might work, but it always gives out the value
1.0 for the farthest top point ,  and the value.
-1.0 for the farthest bottom point.
getLocalToVworld()  doesn't actually consider what is the current canvas size, say 640*480.
getLocalToVworld()  always givems 1.0 and -1.0 for the farthest top and bottom points.

What I need, is not 1.0 or -1.0, I need something representing the row number of this point !!!! For instance, 239 and -157.

Hope you can really help !!!

Best Regards
JIA


I'm not sure what you're using, but if you determine the distance between the farthest top point to the farthest bottom point, and then multiply that by your scaling value, you should have the correct size.


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 tom
« Reply #3 - Posted 2009-12-20 02:28:26 »

you could try getBounds(). If it is a Shape3D it will be a BoundingBox otherwise it is a BoundingSphere.

Offline jiapei100

Junior Member





« Reply #4 - Posted 2009-12-20 02:58:23 »


Hi, Thank you so much Tom.
You are always helpful.

I got the bounds of the loaded object.

1  
Bounds m_bounds = m_Obj3d.getBounds();


And the current m_bounds is of value:

1  
2  
3  
4  
5  
6  
7  
8  
lower=Point3d
x=-0.88
y=-1.0
z=-0.67
upper=Point3d
x=0.88
y=1.0
z=0.67


However, as we can see, the bounds are normalized so that the object's longest axis (Y) is normalized to "between -1.0 and 1.0".
I'm still not able to find the value mapping to the screen.
what I mean is
y=-1.0 should be corresponding to around -100 pixels, while
y=1.0 should be corresponding to around +100 pixels.


Can you help please?

Best Regards
JIA



you could try getBounds(). If it is a Shape3D it will be a BoundingBox otherwise it is a BoundingSphere.

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.

ctomni231 (33 views)
2014-07-18 06:55:21

Zero Volt (29 views)
2014-07-17 23:47:54

danieldean (24 views)
2014-07-17 23:41:23

MustardPeter (26 views)
2014-07-16 23:30:00

Cero (41 views)
2014-07-16 00:42:17

Riven (43 views)
2014-07-14 18:02:53

OpenGLShaders (31 views)
2014-07-14 16:23:47

Riven (30 views)
2014-07-14 11:51:35

quew8 (29 views)
2014-07-13 13:57:52

SHC (65 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!