Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

12046 Posts in 1593 Topics- by 597 Members - Latest Member: Pymntizwb

20. May 2013, 03:17:10 pm
Xith3D CommunityXith3D InternalsDeveloper discussion (Moderators: Marvin Fröhlich, 'n ddrylliog)Aspect ratio
Pages: [1]
Print
Author Topic: Aspect ratio  (Read 1080 times)
pertteli
Just dropped in

Offline Offline

Posts: 2


View Profile
« on: 19. August 2007, 12:54:05 pm »

I'm trying to integrate a Xith canvas in my AWT GUI. I seem to get problems with aspect ratio. If I resize the window, the aspect ratio of Xith rendering changes.

This happens with org.xith3d.test.ui.SwingIntegrationTest, too. The rotating sphere becames an ellipse if you resize the window. In any real life application you want the aspect ratio to stay fixed, ie. people's heads aren't supposed to go elliptic depending on the window size. Is there a solution, apart from defining a fixed size fo the canvas?

I'm initializing the GUI this way:

Code:
Xith3DEnvironment env=new Xith3DEnvironment(this);
Canvas3DPanel p=new Canvas3DPanel();
add("Center",p);
Canvas 3D c=p.getCanvas();
env.addCanvas(c);
env.addPerspectiveBranch(createScene());

Is this the correct way?
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4403


May the 4th, be with you...


View Profile
« Reply #1 on: 19. August 2007, 06:33:41 pm »

You could try to resize the viewport size (in RenderPass) in an inverted way to the canvas aspect ratio. You could register a resize listener at the canvas to automate this. Note: Using the canvas'es resize listener is thread safe.

Marvin
Logged
pertteli
Just dropped in

Offline Offline

Posts: 2


View Profile
« Reply #2 on: 20. August 2007, 12:04:39 am »

The following approach seems to work. I didn't need any inverting calculations, just set the viewport size to what the canvas size is.

I implement ComponentListener to get resize events from the canvas:
Code:
class MyTest implements java.awt.ComponentListener {
   RenderPassConfigProvider conf;
   Canvas3D canvas;

   public void componentResized(ComponentEvent e) {
       Rect2i vp=conf.getViewport();
       if (vp==null) vp=new Rect2i();    // seems to be null initially
       vp.setSize(canvas.getWidth(),canvas.getHeight());
       conf.setViewport(vp);
   }

And when initializing the scene:

Code:
   Canvas3DPanel p=new Canvas3DPanel();
   add("Center",p);
   p.addComponentListener(this);
   canvas=p.getCanvas();
   env.addCanvas(canvas);
   RenderPass rp=env.addPerspectiveBranch(createScene());
   conf=rp.getConfig();

It works for a simple test, at least. Any loopholes? Could this become a Xith built-in functionality, because it's practically always needed if you have a resizing canvas?
« Last Edit: 20. August 2007, 12:14:10 am by pertteli » Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4403


May the 4th, be with you...


View Profile
« Reply #3 on: 20. August 2007, 12:17:45 am »

The following approach seems to work. I didn't need any inverting calculations, just set the viewport size to what the canvas size is.

Oh, you're right. You only need a regular viewport size.

But don't use the AWT ComponentListener for that. As I said, use the Canvas3D's ResizeListener through this method:
Code:
addResizeListener(ResizeListener2i listener);

By using the AWT ComponentListner you have three problems:
  • It is not thread safe.
  • You stick your application to JOGL_AWT.
  • It is a little more coding with castings to use the AWT listener


It works for a simple test, at least. Any loopholes? Maybe this might become a built-in functionality in Xith, because it's practically always needed if you have a resizing canvas, right?

Yes, this is a good idea.

Marvin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic