www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Uncle Ray on October 20, 2014, 02:43:01 pm

Title: Question,how to set two camera in jpct?
Post by: Uncle Ray on October 20, 2014, 02:43:01 pm
SOLVED
Thanks for ego's and thomas's great help,the problem solved perfect.
(http://i42.photobucket.com/albums/e308/409544041/cam_zps24380dbc.jpg)
Just two cameras in the same screen,how to implement?
Is the any example?
Thx,ego.
Just a little simple example,any help will be much appreciated.

Title: Re: Question,how to set two camera in jpct?
Post by: Uncle Ray on October 20, 2014, 05:30:24 pm
Any tips?
Title: Re: Question,how to set two camera in jpct?
Post by: EgonOlsen on October 20, 2014, 05:56:29 pm
The basic approach would be:


You should use OpenGL ES 2.0 for this or render targets won't work reliable. And it will have a huge impact on your frame rate, because you have to render the scene twice for each frame.
Title: Re: Question,how to set two camera in jpct?
Post by: Uncle Ray on October 20, 2014, 06:13:13 pm
thx,a little complicated,but i will tried it,any progresses will reported soon.
Title: Re: Question,how to set two camera in jpct?
Post by: EgonOlsen on October 20, 2014, 07:09:08 pm
It's not complicated, it's actually pretty simple. All you do is render the scene twice with different cameras, one time into the mirror texture and one time into the normal frame buffer.
Title: Re: Question,how to set two camera in jpct?
Post by: Uncle Ray on October 21, 2014, 11:11:36 am
I create new world world2,and new Frambuffer fb2.

cam2(world2);
world2.renderScene(fb2);
world2.draw(fb2);


in the second framebuffer,the second camera  is ok,but the second framebuffer is location in the(0,0);

how to set the framebuffer's location?
jpct just have framebuffer(width,heght),where is framebuffer_set(x,y)?


Title: Re: Question,how to set two camera in jpct?
Post by: EgonOlsen on October 21, 2014, 12:24:09 pm
That's not what i meant. You don't need two FrameBuffers for this. You just a need an additional texture, that you set as a render target of your (single) FrameBuffer instance, render the mirrored scene, remove the render target again and then do the normal rendering.
Title: Re: Question,how to set two camera in jpct?
Post by: Uncle Ray on October 21, 2014, 12:33:01 pm
And more,i can't understande which fb.render target(texture tex) used for?
it's just like blit()?
or other use?

in my thought:
1 set camera1 in the world1,and set world1 in the framebuffer1
2 set camera2 in the world2 ,and set world2 in the framebuffer2
3,set framebuffer1 area as  Full-screen(ie 1920*1080);
4 set framebuffer2 area as part_screen(ie 256*256);
5,render framebuffer1 and framebuffer2


Is that any wrong with my thought?
Title: Re: Question,how to set two camera in jpct?
Post by: EgonOlsen on October 21, 2014, 01:35:54 pm
Is that any wrong with my thought?
Yes: It doesn't work that way, you can't mix frame buffers. A FrameBuffer instance is not much more than a container for some gl context. A render target is exactly what the name says: A target to render into. If you don't set one, the default render target of any FrameBuffer instance is the gl context of your screen. If you set a render target, all rendering happens into that target. With that, you render your mirror scene into a texture and you can then blit that texture later as a mirror view. And you have to switch the camera in one World instance instead of using two worlds unless you want to double all your Object3D instance.
I've actually described the whole process in my first reply. I'm not sure how you came up with an idea that has actually nothing do to with it... ???
Title: Re: Question,how to set two camera in jpct?
Post by: EgonOlsen on October 21, 2014, 01:36:31 pm
I can upload an example later if that would help...
Title: Re: Question,how to set two camera in jpct?
Post by: Uncle Ray on October 21, 2014, 02:37:29 pm
Thx,if there are some examples,that would be much helpful.
Title: Re: Question,how to set two camera in jpct?
Post by: Uncle Ray on October 21, 2014, 03:31:45 pm
got it,but.........
(http://i42.photobucket.com/albums/e308/409544041/test1_zps7c71d273.jpg)


the second camera is reverse....
how to fix it?
Title: Re: Question,how to set two camera in jpct?
Post by: Uncle Ray on October 21, 2014, 03:59:05 pm
i really got it(maybe...)

0.texture is no need for some jpg,just" Texture mtexture=new Texture(256,256);"could usefull too.
1.framebuffer contains camera .
2,framebuffer's default render target is all of the scene(ie world)
3.uses setrendertarget could translate framebuffer into texture.
4 blit this texture in the screen.(the texture means second camera)
5,remove target(so the framebuffer back to first camera)

first render:(second camera)
world=>camera2=>framebuffer1=>texture=>framebuffer1.blit(texture)=>framebuffer.display

second render:(first camera)
world=>camera1=>framebuffer1=>framebuffer.display



Question still, why second camera reverse....??? :(
Title: Re: Question,how to set two camera in jpct?
Post by: EgonOlsen on October 21, 2014, 04:18:13 pm
That's because that is the default coordinate system that OpenGL uses for the screen. Try to blit with (x,dy,dx,-dy...) instead of (x,0,dx,dy...), i.e. start at the bottom with a negative height.
Title: Re: Question,how to set two camera in jpct?
Post by: Uncle Ray on October 21, 2014, 05:05:09 pm


it's Wrong,they just the same camera....


 //on start_time
           public Texture mtexture=new Texture(256,256);
           public framebuffer fb=framebuffer(w,h);
           public World world=new World();

//on frame_time
           

           //first rendering
            cam.auto(world, cam, Objec3D1);
       fb.setRenderTarget(mtexture);
       fb.clear();
       world.renderScene(fb);
       world.draw(fb);
       fb.display();
       fb.removeRenderTarget();
      
       //second rendering
       cam.auto(world, cam, Object3D2);
       fb.clear(back);
       world.renderScene(fb);
       world.draw(fb);      
       fb.blit(mtexture, 0, 0, 700, 8,256, -256,device_width/2,device_height/4,100,false);
//-256 must be negative,otherwise the second camera would be revise    
       fb.display();   
Title: Re: Question,how to set two camera in jpct?
Post by: gamenewer on October 22, 2014, 03:29:02 am
How about the framerate in this case ?
Title: Re: Question,how to set two camera in jpct?
Post by: Uncle Ray on October 22, 2014, 06:34:33 am
a little drop,but not much.
Title: Re: Question,how to set two camera in jpct?
Post by: Uncle Ray on October 22, 2014, 06:36:53 am
How about the framerate in this case ?

maybe you came from china,we can talk in qq
(my qq:409544041)
Title: Re: Question,how to set two camera in jpct?
Post by: Uncle Ray on October 22, 2014, 09:24:38 am
i had made a mistake,they just the same camera....
Title: Re: Question,how to set two camera in jpct?
Post by: Uncle Ray on October 22, 2014, 11:23:32 am
I still failed,i have search all of this forum and google,all of them are not anything about how to set two camera in jpct.
Anyone helps one,thx.
Title: Re: Question,how to set two camera in jpct?
Post by: Uncle Ray on October 22, 2014, 11:29:04 am
i think problem is how to switch camera?

Title: Re: Question,how to set two camera in jpct?
Post by: Thomas. on October 22, 2014, 12:16:03 pm
You have to use method World.setCameraTo(...) (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/World.html#setCameraTo(com.threed.jpct.Camera))
Title: Re: Question,how to set two camera in jpct?
Post by: Uncle Ray on October 22, 2014, 03:55:41 pm
thanks to ego and thomas,the problem solved here is the code.
 cam1.cam01=world.getcamera;//
           //first rendering
           world.setCameraTo(cam2.cam01);   
       cam2.move(world, missile01,2);
       fb.setRenderTarget(mtexture);
       fb.clear(back);
       world.renderScene(fb);
       world.draw(fb);
       fb.display();
       fb.removeRenderTarget();
   
       //second rendering
       world.setCameraTo(cam1.cam01);   //without this,two views would be share the same camera.
       cam1.move(world,tes1,1);
       fb.clear(back); 
       world.renderScene(fb);
       world.draw(fb);
      
   fb.blit(mtexture, 0, 0,device_width*5/6, 8,256,   -256,device_width/6,device_height/5,100,false);//-256 must negative,otherwise the second camera would be reverse   
      
       fb.display();
      
       }