开发者

Draw camera position in specific view port

Most of this code should be fairly self explanatory. I got an display function and my view port function. There are two modes which is 4 small view ports in the window or one large. I got one camera which can be moved and if in 4 view port mode just 3 fixed angles. The thing is I want the free moving cameras position to be displayed in the 3 other view ports. I tried doing it by drawing spheres using opengl but the problem is that then the position gets draw in the free roaming camera too as it shows the same scene.

It doesn't have to be a sphere, just something simple that represents the cameras spacial position in these three other views.

Drawing the scene once with camera object showing for the three viewports, render to texture. Clear and draw scene without camera object render to texture and then stitch these together before actually drawing the scene seems like a lot o work for something that should be easy.

void display(int what)
    {
        if(what==5){
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        camControll();}

        if(what==1){
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(75,15,-5,0,5,-5,0,1,0);}

        if(what==2){
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(0,110,0,0,0,0,1,0,0);}

        if(what==3){
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0f, float(320) / float(240), 0.1f, 100.0f); 
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        camControll();}

        if(what==4){
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(185,75,25,0,28,0,0,1,0);}



        glClearColor(0, 0, 0, 1);
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        drawScene();
        drawCamera();
        glutSwapBuffers();
    }

    void viewport(){
    glEnable(GL_SCISSOR_TEST);

        if(!divided_view_port)
        {
        glViewport(0, 0, w, h);
        glScissor(0,0,640,480);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0f, w / h, 0.1f, 100.0f);
        display(5);
        }

    else
    {
        ////////////////////// bottom left - working
        glViewport(0, 0, w/2, h/2);
        glScissor(0,0,w/2,h/2);
        glMatrixMode(GL_PROJECT开发者_Go百科ION);
        glLoadIdentity();
        gluPerspective(45.0f, w / h, 0.1f, 300.0f);
        display(1);
        //////////////////////


        ////////////////////// top right - working
        glViewport(w/2, h/2, w/2, h/2);
        glScissor(w/2,h/2,w/2,h/2);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0f, w / h, 0.1f, 300.0f);
        display(2);
        //////////////////////

        ////////////////////// bottom right -working
        glViewport(w/2, 0, w/2, h/2);
        glScissor(w/2,0,w/2,h/2);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0f, w / h, 0.1f, 300.0f);
        display(3);
        ////////////////////////

        ////////////////////////// top left
        glViewport(0, h/2, w/2, h/2);
        glScissor(0,h/2,w/2,h/2);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0f, w / h, 0.1f, 300.0f);
        display(4);
        ///////////////////////////
    }

    glDisable(GL_SCISSOR_TEST);
    glMatrixMode(GL_MODELVIEW);
    }

So what I basically need is to hide this object in specific viewport.


Why not make that single Sphere object (or the entity responsible for drawing the sphere) aware of the "current viewport" (which happens to be the what variable in your code) and let it be invisible if it's the given viewport?

This solution exactly corresponds to the logic involved here sounds both simple and correct.

A more general solution would be to give each "camera" a GUID and make it available for the entity responsible for drawing Cameras to check the GUID of the "camera" bound to the viewport which is being rendered at the moment. If they happen to be equal, ignore the camera object during this draw pass.


I think that should be easy if you would just draw point, because if you want to see point in viewport, its center have to be in viewport, otherwise nothing of it is displayed even if you set huge point size. Then you have 2 options to eliminate flickering effect (as when you put 2 squares in the very same possition they will flicker one over another). You can just move that point little behind camera, or use nonzero value for near clipping plane in glFrustrum/gluPerspective call.. and well if you update point position every time you move camera you have no chance of seeing that point in your moving camera and you can use single scene.

And second option, I don't know if you can update just single viewport, but maybe just setting scene, displaying it to moving camera, drawing camera position and displaying it for other 3 viewports should be easy also..


Why don't you draw the sphere behind the moving camera's near plane? That should ensure that the moving camera doesn't see the sphere at all, but its position is clearly marked for the others.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜