Author Topic: 2cameras at once/stereoscopic 3d?  (Read 5485 times)

Offline Disastorm

  • long
  • ***
  • Posts: 161
    • View Profile
2cameras at once/stereoscopic 3d?
« on: July 18, 2011, 08:46:24 pm »
Hello, I have a 3d phone (older japanese Sharp phone, not the newer LG or HTC one, so I don't know their apis, but maybe the same) and basically all it requires for 3d is to send a doubled image with the left eye image on the left side and the right eye image on the right side on a single SurfaceView.  I was just wondering If there is a way to do this with jpct? Also would be nice making some 3d apps since there aren't many out there right now.
« Last Edit: July 18, 2011, 10:25:29 pm by Disastorm »

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Re: 2cameras at once/stereoscopic 3d?
« Reply #1 on: July 19, 2011, 01:37:34 am »
Jpct doesn't support any camera itself, but you can implement it)
If you saw camera class in documentation, it's another camera, which translate objects form the World to screen.
If you want make some application with camera, just use search....
for example this one  - http://www.jpct.net/forum2/index.php?topic=1586.0

Offline Disastorm

  • long
  • ***
  • Posts: 161
    • View Profile
Re: 2cameras at once/stereoscopic 3d?
« Reply #2 on: July 19, 2011, 03:37:26 am »
Actually that is the camera i was talking about, the one that renders image to the screen.  Is there any way i can use two cameras to render two images to the same screen in different positions?  That way if I have a game I can put two cameras in it, at eye-distance apart, and then that will make my game 3D.  It sounds so easy for such a cool feature.
« Last Edit: July 19, 2011, 03:39:48 am by Disastorm »

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: 2cameras at once/stereoscopic 3d?
« Reply #4 on: July 19, 2011, 04:41:38 pm »
You can easily render the same scene twice but the difficulties might start when trying to combine both results into one framebuffer without making one overwrite the other. You might want to play around with http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Config.html#viewportOffsetX, but i'm not sure if this will work properly on all devices.
« Last Edit: August 23, 2011, 08:31:09 am by EgonOlsen »

Offline monkokio

  • byte
  • *
  • Posts: 3
    • View Profile
Re: 2cameras at once/stereoscopic 3d?
« Reply #5 on: August 22, 2011, 08:41:48 am »
I am trying to work with the LG Real3D API that just came out. It is asking for the image to be displayed in the same way.

I am super close, I can get two images rendered correctly by creating the frame buffer with half the width and then setting Config.viewportOffsetX between each render.

The one problem is that the render uses the aspect ratio of half of the screen (what I set the frame buffer to) - when I want it to use the aspect ratio of the entire screen. The LG API interleaves the pixel columns of two renders, which spaces out the images and makes them appear to be at the aspect ratio of the whole screen.

Any ideas on how to get this last part working?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: 2cameras at once/stereoscopic 3d?
« Reply #6 on: August 22, 2011, 10:03:29 am »
You can turn off automatic adjustment of FOV by setting this to false: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Config.html#autoMaintainAspectRatio

You can then set any FOV you want in Camera. I'm not sure if that is exactly what you are talking about though...

Offline monkokio

  • byte
  • *
  • Posts: 3
    • View Profile
Re: 2cameras at once/stereoscopic 3d?
« Reply #7 on: August 22, 2011, 07:26:12 pm »
Thanks for the tip, I have been digging around and it seems like this flag is used primarily to avoid changing the aspect ratio when drawing to a render target that has a different aspect ratio. I don't see a way to explicitly set the aspect ratio when the autoMaintainAspectRatio flag is false.
If I am able to set the aspect ratio directly, I think that will be exactly enough to get this working correctly.

When I get back to my workstation tonight, I will poke around and post a follow-up with my progress.
« Last Edit: August 22, 2011, 07:36:47 pm by monkokio »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: 2cameras at once/stereoscopic 3d?
« Reply #8 on: August 22, 2011, 08:11:40 pm »
Setting the fov (and yfov) will result in a different aspect ratio.

Offline monkokio

  • byte
  • *
  • Posts: 3
    • View Profile
Re: 2cameras at once/stereoscopic 3d?
« Reply #9 on: August 23, 2011, 07:50:37 am »
Absolutely perfect!
Thank you so much, EgonOlsen! You have been a tremendous help!

To sum everything up:
Code: [Select]

// create the FrameBuffer at half the width of the actual window
mFrameBuffer = new FrameBuffer(gl, w/2, h);

// compute your FOV values (using the aspect ratio of the actual window)
float xFOV = SOME_CHOSEN_VALUE;
float yFOV = 2.0f * Math.atan( Math.tan(xFOV * 0.5f) * h/w );

// tell the camera to render at the aspect ratio of the actual window, not the aspect ratio of the frame buffer
com.threed.jpct.Config.autoMaintainAspectRatio = false;
Camera cam = world.getCamera();
cam.setFOVLimits(LOWER_LIMIT, HIGHER_LIMIT); // I wanted a narrow FOV, so I found that I needed to change my FOV limits
cam.setFOV( (float) Math.atan( xFOV  ) );
cam.setYFOV( (float) Math.atan( yFOV  ) );


// ... when it comes time to render ...

cam.setPosition( LEFT_EYE_POSITION );
cam.lookAt( TARGET_POSITION );
com.threed.jpct.Config.viewportOffsetX = 0.0f;
world.renderScene(fb);
world.draw(fb);

cam.setPosition(RIGHT_EYE_POSITION );
cam.lookAt( TARGET_POSITION );
com.threed.jpct.Config.viewportOffsetX = 1.0f;
world.renderScene(fb);
world.draw(fb);

fb.display();



Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: 2cameras at once/stereoscopic 3d?
« Reply #10 on: August 23, 2011, 09:32:16 am »
And then everything is in real 3D?...cool! Maybe you want to wrap this in a little helper class? That would be a nice addition to the wiki.