2cameras at once/stereoscopic 3d?

Started by Disastorm, July 18, 2011, 08:46:24 PM

Previous topic - Next topic

Disastorm

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.

Nemetz

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

Disastorm

#2
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.


EgonOlsen

#4
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.

monkokio

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?

EgonOlsen

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...

monkokio

#7
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.

EgonOlsen

Setting the fov (and yfov) will result in a different aspect ratio.

monkokio

Absolutely perfect!
Thank you so much, EgonOlsen! You have been a tremendous help!

To sum everything up:


// 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();




EgonOlsen

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.