Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11855 Posts in 1569 Topics- by 3058 Members - Latest Member: xynewhand

12. February 2012, 02:56:33 AM
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)Texture Size and Quad Shape
Pages: [1]
Print
Author Topic: Texture Size and Quad Shape  (Read 383 times)
elijah
Enjoying the stay
*
Offline Offline

Posts: 72


View Profile
« on: 26. June 2010, 03:53:12 AM »

Is there a way to determine the size of the Quad Shape3D that must be created based upon the Texture Size without stretching the image? The other question is also for button and label size.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4337


May the 4th, be with you...


View Profile
« Reply #1 on: 26. June 2010, 09:30:46 AM »

In parallel projection, it's easy. But I guess, that's not, what you want Wink.

If you want to use perspective projection, you could try to do it by casting a pick ray at (w/2,h/2), where w and h are the size if the texture. Then you calculate, w' and h' at the shape's distance from the camera.

Marvin
Logged
elijah
Enjoying the stay
*
Offline Offline

Posts: 72


View Profile
« Reply #2 on: 26. June 2010, 08:06:31 PM »

Is there any code examples in xith-tk ( or books ) that I should look at to help me understand your explanation. It looks very simple. Is it something like

PickRay pr = new PickRay( RenderPassConfig, canvas, canvas.getWidth()/2, canvas.getHeight()/2 ) ;
pr.recalculate( Image.getWidth()/2, Image.getHeight()/2 );

then how to get w' and h' ? Hope you can help me further.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4337


May the 4th, be with you...


View Profile
« Reply #3 on: 26. June 2010, 11:12:38 PM »

The recalculate is unnecessary, if you pass the image's size into the constructor.

The rest should be simple vector math.

Code:
// Define a point on the image shape's boundary (where it is located). We start with the pick ray's origin...
Point3f boundary = new Point3f( pr.getOrigin() );
// Set the pick ray's length to the distance from canvas to the image shape.
pr.getDirection().normalize();
pr.getDirection().setLength( absDistanceCanvasToImage );
// ...and add the pick ray's direction vector.
boundary.add( pr.getDirection() );
// Define the center of the image shape (where it is located).
Point3f center = new Point3f( 0f, 0f, -absDistanceCanvasToImage );
// The distance from 'center' to 'boundary' is half of the image shape's height (where it is located).
float height = center.distanceTo( boundary ) * 2f;

The width can now be calculated by using the image's aspect ratio and the calculated height.

The code is untested and written straight from my head. But it should basically work.

Marvin
Logged
elijah
Enjoying the stay
*
Offline Offline

Posts: 72


View Profile
« Reply #4 on: 02. July 2010, 07:10:47 PM »

Thank you for your help. I will try this and will post back on the testing
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic