Changeset 709

Show
Ignore:
Timestamp:
08/21/07 15:12:28 (16 months ago)
Author:
leo
Message:

Fixed tiled rendering, save viewport information in the view class.

Location:
trunk
Files:
2 removed
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/common/algebra.h

    r694 r709  
    769769Matrix44 CreateLookAtMatrix(const Vector3& Eye, const Vector3& Target, const Vector3& Up); 
    770770Matrix44 CreatePerspectiveMatrix(float FoVy, float Aspect, float Near, float Far); 
    771 Matrix44 CreateOrthoMatrix44(float Left, float Right, float Bottom, float Top, float Near, float Far); 
     771Matrix44 CreateOrthoMatrix(float Left, float Right, float Bottom, float Top, float Near, float Far); 
    772772 
    773773// ============================================================================ 
  • trunk/common/lc_camera.cpp

    r700 r709  
    3939    m_FOV = 30.0f; // TODO: animate FOV 
    4040 
     41    SetOrtho(IsSide()); 
    4142    SetVisible(CameraType == LC_CAMERA_USER); 
    4243} 
     
    340341void lcCamera::LoadProjection(float Aspect) 
    341342{ 
    342     // FIXME: tiled rendering 
    343 //  if (m_pTR != NULL) 
    344 //      m_pTR->BeginTile(); 
    345 //  else 
    346     { 
    347         glMatrixMode(GL_PROJECTION); 
    348         glLoadIdentity(); 
    349  
    350         if (IsOrtho()) 
    351         { 
    352             float ymax, ymin, xmin, xmax, znear, zfar; 
    353             Vector3 frontvec = Vector3(m_ViewWorld[2]);//m_Target - m_Eye; // FIXME: free ortho cameras = crash 
    354             ymax = (frontvec.Length())*sinf(DTOR*m_FOV/2); 
    355             ymin = -ymax; 
    356             xmin = ymin * Aspect; 
    357             xmax = ymax * Aspect; 
    358             znear = m_NearDist; 
    359             zfar = m_FarDist; 
    360             glOrtho(xmin, xmax, ymin, ymax, znear, zfar); 
    361         } 
    362         else 
    363         { 
    364             gluPerspective(m_FOV, Aspect, m_NearDist, m_FarDist); 
    365         } 
     343    glMatrixMode(GL_PROJECTION); 
     344    glLoadIdentity(); 
     345 
     346    if (IsOrtho()) 
     347    { 
     348        float ymax, ymin, xmin, xmax, znear, zfar; 
     349        Vector3 frontvec = Vector3(m_ViewWorld[2]);//m_Target - m_Eye; // FIXME: free ortho cameras = crash 
     350        ymax = (frontvec.Length())*sinf(DTOR*m_FOV/2); 
     351        ymin = -ymax; 
     352        xmin = ymin * Aspect; 
     353        xmax = ymax * Aspect; 
     354        znear = m_NearDist; 
     355        zfar = m_FarDist; 
     356        glOrtho(xmin, xmax, ymin, ymax, znear, zfar); 
     357    } 
     358    else 
     359    { 
     360        gluPerspective(m_FOV, Aspect, m_NearDist, m_FarDist); 
    366361    } 
    367362 
  • trunk/common/project.cpp

    r708 r709  
    15601560    RenderBackground(view); 
    15611561 
    1562     // Load the camera. 
    1563     float w = (float)view->GetWidth(); 
    1564     float h = (float)view->GetHeight(); 
    1565     float ratio = w/h; 
    1566  
    1567     view->GetCamera()->LoadProjection(ratio); 
     1562    // Setup the projection and camera matrices. 
     1563    Matrix44 Projection = view->GetProjectionMatrix(); 
     1564 
     1565    glMatrixMode(GL_PROJECTION); 
     1566    glLoadMatrixf(Projection); 
     1567 
     1568    glMatrixMode(GL_MODELVIEW); 
     1569    glLoadMatrixf(view->GetCamera()->m_WorldView); 
    15681570 
    15691571    // Render 3D objects. 
     
    18001802 
    18011803            Matrix44 ModelView = Camera->m_WorldView; 
    1802             Matrix44 Projection = CreatePerspectiveMatrix(Camera->m_FOV, Aspect, Camera->m_NearDist, Camera->m_FarDist); 
     1804            Matrix44 Projection = view->GetProjectionMatrix(); 
    18031805 
    18041806            // Unproject edge center points to world space. 
    1805             int Viewport[4] = { 0, 0, view->GetWidth(), view->GetHeight() }, i; 
    1806  
    18071807            Vector3 Points[10] = 
    18081808            { 
    1809                 Vector3(0, (float)Viewport[3] / 2, 0), 
    1810                 Vector3(0, (float)Viewport[3] / 2, 1), 
    1811                 Vector3((float)Viewport[2] / 2, 0, 0), 
    1812                 Vector3((float)Viewport[2] / 2, 0, 1), 
    1813                 Vector3((float)Viewport[2], (float)Viewport[3] / 2, 0), 
    1814                 Vector3((float)Viewport[2], (float)Viewport[3] / 2, 1), 
    1815                 Vector3((float)Viewport[2] / 2, (float)Viewport[3], 0), 
    1816                 Vector3((float)Viewport[2] / 2, (float)Viewport[3], 1), 
    1817                 Vector3((float)Viewport[2] / 2, (float)Viewport[3] / 2, 0), 
    1818                 Vector3((float)Viewport[2] / 2, (float)Viewport[3] / 2, 1), 
     1809                Vector3(0, (float)view->m_Viewport[3] / 2, 0), 
     1810                Vector3(0, (float)view->m_Viewport[3] / 2, 1), 
     1811                Vector3((float)view->m_Viewport[2] / 2, 0, 0), 
     1812                Vector3((float)view->m_Viewport[2] / 2, 0, 1), 
     1813                Vector3((float)view->m_Viewport[2], (float)view->m_Viewport[3] / 2, 0), 
     1814                Vector3((float)view->m_Viewport[2], (float)view->m_Viewport[3] / 2, 1), 
     1815                Vector3((float)view->m_Viewport[2] / 2, (float)view->m_Viewport[3], 0), 
     1816                Vector3((float)view->m_Viewport[2] / 2, (float)view->m_Viewport[3], 1), 
     1817                Vector3((float)view->m_Viewport[2] / 2, (float)view->m_Viewport[3] / 2, 0), 
     1818                Vector3((float)view->m_Viewport[2] / 2, (float)view->m_Viewport[3] / 2, 1), 
    18191819            }; 
    18201820 
    1821             UnprojectPoints(Points, 10, ModelView, Projection, Viewport); 
     1821            UnprojectPoints(Points, 10, ModelView, Projection, view->m_Viewport); 
    18221822 
    18231823            // Intersect lines with base plane. 
    18241824            Vector3 Intersections[5]; 
     1825            int i; 
    18251826 
    18261827            for (i = 0; i < 5; i++) 
     
    25842585                    GLdouble ScreenX, ScreenY, ScreenZ; 
    25852586                    GLdouble ModelMatrix[16], ProjMatrix[16]; 
    2586                     GLint Vp[4]; 
    25872587 
    25882588                    glGetDoublev(GL_MODELVIEW_MATRIX, ModelMatrix); 
    25892589                    glGetDoublev(GL_PROJECTION_MATRIX, ProjMatrix); 
    2590                     glGetIntegerv(GL_VIEWPORT, Vp); 
    2591  
    2592                     gluProject(0, 0, 0, ModelMatrix, ProjMatrix, Vp, &ScreenX, &ScreenY, &ScreenZ); 
     2590 
     2591                    gluProject(0, 0, 0, ModelMatrix, ProjMatrix, m_ActiveView->m_Viewport, &ScreenX, &ScreenY, &ScreenZ); 
    25932592 
    25942593                    glMatrixMode(GL_PROJECTION); 
    25952594                    glPushMatrix(); 
    25962595                    glLoadIdentity(); 
    2597                     glOrtho(0, Vp[2], 0, Vp[3], -1, 1); 
     2596                    glOrtho(m_ActiveView->m_Viewport[0], m_ActiveView->m_Viewport[2], m_ActiveView->m_Viewport[1], m_ActiveView->m_Viewport[3], -1, 1); 
    25982597                    glMatrixMode(GL_MODELVIEW); 
    25992598                    glPushMatrix(); 
     
    26142613                    glBegin(GL_QUADS); 
    26152614                    glColor3f(0.8f, 0.8f, 0.0f); 
    2616                     m_pScreenFont->PrintText((float)ScreenX - Vp[0] - (cx / 2), (float)ScreenY - Vp[1] + (cy / 2), 0.0f, buf); 
     2615                    m_pScreenFont->PrintText((float)ScreenX - m_ActiveView->m_Viewport[0] - (cx / 2), (float)ScreenY - m_ActiveView->m_Viewport[1] + (cy / 2), 0.0f, buf); 
    26172616                    glEnd(); 
    26182617 
     
    63686367    GLdouble px, py, pz, rx, ry, rz; 
    63696368    GLdouble modelMatrix[16], projMatrix[16]; 
    6370     GLint viewport[4]; 
    63716369 
    63726370    m_ActiveView->LoadViewportProjection(); 
    63736371    glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix); 
    63746372    glGetDoublev(GL_PROJECTION_MATRIX,projMatrix); 
    6375     glGetIntegerv(GL_VIEWPORT,viewport); 
    63766373 
    63776374    // Unproject the selected point against both the front and the back clipping plane 
    6378     gluUnProject(x, y, 0, modelMatrix, projMatrix, viewport, &px, &py, &pz); 
    6379     gluUnProject(x, y, 1, modelMatrix, projMatrix, viewport, &rx, &ry, &rz); 
     6375    gluUnProject(x, y, 0, modelMatrix, projMatrix, m_ActiveView->m_Viewport, &px, &py, &pz); 
     6376    gluUnProject(x, y, 1, modelMatrix, projMatrix, m_ActiveView->m_Viewport, &rx, &ry, &rz); 
    63806377 
    63816378    ClickRay.Start = Vector3((float)px, (float)py, (float)pz); 
     
    73367333                GLdouble modelMatrix[16], projMatrix[16], p1[3], p2[3], p3[3]; 
    73377334                float ax, ay; 
    7338                 GLint viewport[4]; 
    73397335 
    73407336          glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); 
    73417337          glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); 
    7342           glGetIntegerv(GL_VIEWPORT, viewport); 
    7343           gluUnProject( 5, 5, 0.1, modelMatrix,projMatrix,viewport,&p1[0],&p1[1],&p1[2]); 
    7344           gluUnProject(10, 5, 0.1, modelMatrix,projMatrix,viewport,&p2[0],&p2[1],&p2[2]); 
    7345           gluUnProject( 5,10, 0.1, modelMatrix,projMatrix,viewport,&p3[0],&p3[1],&p3[2]); 
     7338          gluUnProject( 5, 5, 0.1, modelMatrix, projMatrix, m_ActiveView->m_Viewport, &p1[0], &p1[1], &p1[2]); 
     7339          gluUnProject(10, 5, 0.1, modelMatrix, projMatrix, m_ActiveView->m_Viewport, &p2[0], &p2[1], &p2[2]); 
     7340          gluUnProject( 5,10, 0.1, modelMatrix, projMatrix, m_ActiveView->m_Viewport, &p3[0], &p3[1], &p3[2]); 
    73467341                 
    73477342          Vector3 vx = Normalize(Vector3((float)(p2[0] - p1[0]), (float)(p2[1] - p1[1]), 0));//p2[2] - p1[2] }; 
     
    74127407{ 
    74137408    GLdouble modelMatrix[16], projMatrix[16], point[3]; 
    7414     GLint viewport[4]; 
    74157409 
    74167410    if (m_nTracking != LC_TRACK_NONE) 
     
    74307424    glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); 
    74317425    glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); 
    7432     glGetIntegerv(GL_VIEWPORT, viewport); 
    7433  
    7434     gluUnProject(x, y, 0.9, modelMatrix, projMatrix, viewport, &point[0], &point[1], &point[2]); 
     7426 
     7427    gluUnProject(x, y, 0.9, modelMatrix, projMatrix, m_ActiveView->m_Viewport, &point[0], &point[1], &point[2]); 
    74357428    m_fTrack[0] = (float)point[0]; m_fTrack[1] = (float)point[1]; m_fTrack[2] = (float)point[2]; 
    74367429 
     
    76057598 
    76067599            double tmp[3]; 
    7607             gluUnProject(x+1, y-1, 0.9, modelMatrix, projMatrix, viewport, &tmp[0], &tmp[1], &tmp[2]); 
     7600            gluUnProject(x+1, y-1, 0.9, modelMatrix, projMatrix, m_ActiveView->m_Viewport, &tmp[0], &tmp[1], &tmp[2]); 
    76087601 
    76097602            StartTracking(LC_TRACK_START_LEFT); 
     
    76257618        { 
    76267619            double tmp[3]; 
    7627             gluUnProject(x+1, y-1, 0.9, modelMatrix, projMatrix, viewport, &tmp[0], &tmp[1], &tmp[2]); 
     7620            gluUnProject(x+1, y-1, 0.9, modelMatrix, projMatrix, m_ActiveView->m_Viewport, &tmp[0], &tmp[1], &tmp[2]); 
    76287621            SelectAndFocusNone(false); 
    76297622            StartTracking(LC_TRACK_START_LEFT); 
     
    76947687{ 
    76957688    GLdouble modelMatrix[16], projMatrix[16], point[3]; 
    7696     GLint viewport[4]; 
    76977689 
    76987690    if (SetActiveView(view)) 
     
    77027694    glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); 
    77037695    glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); 
    7704     glGetIntegerv(GL_VIEWPORT, viewport); 
    77057696 
    77067697    // why this is here ? 
    7707     gluUnProject(x, y, 0.9, modelMatrix, projMatrix, viewport, &point[0], &point[1], &point[2]); 
     7698    gluUnProject(x, y, 0.9, modelMatrix, projMatrix, m_ActiveView->m_Viewport, &point[0], &point[1], &point[2]); 
    77087699    m_fTrack[0] = (float)point[0]; m_fTrack[1] = (float)point[1]; m_fTrack[2] = (float)point[2]; 
    77097700 
     
    77597750{ 
    77607751    GLdouble modelMatrix[16], projMatrix[16], point[3]; 
    7761     GLint viewport[4]; 
    77627752 
    77637753    if (StopTracking(false)) 
     
    77747764    glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); 
    77757765    glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); 
    7776     glGetIntegerv(GL_VIEWPORT, viewport); 
    7777  
    7778     gluUnProject(x, y, 0.9, modelMatrix, projMatrix, viewport, &point[0], &point[1], &point[2]); 
     7766 
     7767    gluUnProject(x, y, 0.9, modelMatrix, projMatrix, m_ActiveView->m_Viewport, &point[0], &point[1], &point[2]); 
    77797768    m_fTrack[0] = (float)point[0]; m_fTrack[1] = (float)point[1]; m_fTrack[2] = (float)point[2]; 
    77807769 
     
    78277816 
    78287817    GLdouble modelMatrix[16], projMatrix[16], tmp[3]; 
    7829     GLint viewport[4]; 
    78307818    float ptx, pty, ptz; 
    78317819 
     
    78337821    glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); 
    78347822    glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); 
    7835     glGetIntegerv(GL_VIEWPORT, viewport); 
    7836  
    7837     gluUnProject(x, y, 0.9, modelMatrix, projMatrix, viewport, &tmp[0], &tmp[1], &tmp[2]); 
     7823 
     7824    gluUnProject(x, y, 0.9, modelMatrix, projMatrix, m_ActiveView->m_Viewport, &tmp[0], &tmp[1], &tmp[2]); 
    78387825    ptx = (float)tmp[0]; pty = (float)tmp[1]; ptz = (float)tmp[2]; 
    78397826 
     
    78447831            int ptx = x, pty = y; 
    78457832 
    7846             if (ptx >= viewport[0] + viewport[2]) 
    7847                 ptx = viewport[0] + viewport[2] - 1; 
    7848             else if (ptx <= viewport[0]) 
    7849                 ptx = viewport[0] + 1; 
    7850  
    7851             if (pty >= viewport[1] + viewport[3]) 
    7852                 pty = viewport[1] + viewport[3] - 1; 
    7853             else if (pty <= viewport[1]) 
    7854                 pty = viewport[1] + 1; 
     7833            if (ptx >= m_ActiveView->m_Viewport[0] + m_ActiveView->m_Viewport[2]) 
     7834                ptx = m_ActiveView->m_Viewport[0] + m_ActiveView->m_Viewport[2] - 1; 
     7835            else if (ptx <= m_ActiveView->m_Viewport[0]) 
     7836                ptx = m_ActiveView->m_Viewport[0] + 1; 
     7837 
     7838            if (pty >= m_ActiveView->m_Viewport[1] + m_ActiveView->m_Viewport[3]) 
     7839                pty = m_ActiveView->m_Viewport[1] + m_ActiveView->m_Viewport[3] - 1; 
     7840            else if (pty <= m_ActiveView->m_Viewport[1]) 
     7841                pty = m_ActiveView->m_Viewport[1] + 1; 
    78557842 
    78567843            m_fTrack[0] = (float)ptx; 
     
    84978484        GLdouble px, py, pz, rx, ry, rz; 
    84988485        GLdouble ModelMatrix[16], ProjMatrix[16]; 
    8499         GLint Viewport[4]; 
    85008486 
    85018487        m_ActiveView->LoadViewportProjection(); 
    85028488        glGetDoublev(GL_MODELVIEW_MATRIX, ModelMatrix); 
    85038489        glGetDoublev(GL_PROJECTION_MATRIX, ProjMatrix); 
    8504         glGetIntegerv(GL_VIEWPORT, Viewport); 
    85058490 
    85068491        // Unproject the mouse point against both the front and the back clipping planes. 
    8507         gluUnProject(x, y, 0, ModelMatrix, ProjMatrix, Viewport, &px, &py, &pz); 
    8508         gluUnProject(x, y, 1, ModelMatrix, ProjMatrix, Viewport, &rx, &ry, &rz); 
     8492        gluUnProject(x, y, 0, ModelMatrix, ProjMatrix, m_ActiveView->m_Viewport, &px, &py, &pz); 
     8493        gluUnProject(x, y, 1, ModelMatrix, ProjMatrix, m_ActiveView->m_Viewport, &rx, &ry, &rz); 
    85098494 
    85108495        Vector3 SegStart((float)rx, (float)ry, (float)rz); 
  • trunk/common/view.cpp

    r708 r709  
    146146    GLWindow::OnSize(cx, cy); 
    147147 
     148    m_Viewport[0] = 0; 
     149    m_Viewport[1] = 0; 
     150    m_Viewport[2] = cx; 
     151    m_Viewport[3] = cy; 
     152 
    148153    UpdateOverlayScale(); 
     154} 
     155 
     156Matrix44 View::GetProjectionMatrix() const 
     157{ 
     158    if (!m_Camera) 
     159        return IdentityMatrix44(); 
     160 
     161    float Aspect = (float)m_nWidth/(float)m_nHeight; 
     162 
     163    if (m_Camera->IsOrtho()) 
     164    { 
     165        float ymax, ymin, xmin, xmax, znear, zfar; 
     166        Vector3 frontvec = Vector3(m_Camera->m_ViewWorld[2]);//m_Target - m_Eye; // FIXME: free ortho cameras = crash 
     167        ymax = (frontvec.Length())*sinf(DTOR*m_Camera->m_FOV/2); 
     168        ymin = -ymax; 
     169        xmin = ymin * Aspect; 
     170        xmax = ymax * Aspect; 
     171        znear = m_Camera->m_NearDist; 
     172        zfar = m_Camera->m_FarDist; 
     173        return CreateOrthoMatrix(xmin, xmax, ymin, ymax, znear, zfar); 
     174    } 
     175    else 
     176        return CreatePerspectiveMatrix(m_Camera->m_FOV, Aspect, m_Camera->m_NearDist, m_Camera->m_FarDist); 
    149177} 
    150178 
     
    163191    GLdouble ScreenX, ScreenY, ScreenZ, PointX, PointY, PointZ; 
    164192    GLdouble ModelMatrix[16], ProjMatrix[16]; 
    165     GLint Viewport[4]; 
    166193 
    167194    LoadViewportProjection(); 
    168195    glGetDoublev(GL_MODELVIEW_MATRIX, ModelMatrix); 
    169196    glGetDoublev(GL_PROJECTION_MATRIX, ProjMatrix); 
    170     glGetIntegerv(GL_VIEWPORT, Viewport); 
    171197 
    172198    const Vector3& Center = m_Project->GetOverlayCenter(); 
     
    174200    // Calculate the scaling factor by projecting the center to the front plane then 
    175201    // projecting a point close to it back. 
    176     gluProject(Center[0], Center[1], Center[2], ModelMatrix, ProjMatrix, Viewport, &ScreenX, &ScreenY, &ScreenZ); 
    177     gluUnProject(ScreenX + 10.0f, ScreenY, ScreenZ, ModelMatrix, ProjMatrix, Viewport, &PointX, &PointY, &PointZ); 
     202    gluProject(Center[0], Center[1], Center[2], ModelMatrix, ProjMatrix, m_Viewport, &ScreenX, &ScreenY, &ScreenZ); 
     203    gluUnProject(ScreenX + 10.0f, ScreenY, ScreenZ, ModelMatrix, ProjMatrix, m_Viewport, &PointX, &PointY, &PointZ); 
    178204 
    179205    Vector3 Dist((float)PointX - Center[0], (float)PointY - Center[1], (float)PointZ - Center[2]); 
  • trunk/common/view.h

    r673 r709  
    3535    void SetCamera(lcCamera* cam); 
    3636    void UpdateCamera(); 
     37    Matrix44 GetProjectionMatrix() const; 
    3738 
    3839public: 
    3940    float m_OverlayScale; 
    4041 
    41 protected: 
    42     Project* m_Project; 
    43  
     42    int m_Viewport[4]; 
    4443    lcCamera* m_Camera; 
    4544    String m_CameraName; 
     45 
     46    Project* m_Project; // TODO: remove m_Project. 
    4647}; 
    4748 
  • trunk/win/Cadview.cpp

    r678 r709  
    231231    int tw = pw, th = ph; // tile size 
    232232 
    233     MEMORYSTATUS MemStat; 
    234     MemStat.dwLength = sizeof(MEMORYSTATUS); 
    235     GlobalMemoryStatus(&MemStat); 
    236  
    237     if (DWORD(pw*ph*3) > MemStat.dwTotalPhys) 
    238     { 
    239         tw = 512; 
    240         th = 512; 
    241     } 
     233    if (tw > 1024 || th > 1024) 
     234        tw = th = 1024; 
    242235 
    243236    HDC hMemDC = CreateCompatibleDC(GetDC()->m_hDC); 
     
    310303        if (tw != pw) 
    311304        { 
    312             /* FIXME tiled rendering 
    313             lcCamera* pCam = view.GetCamera(); 
    314             pCam->StartTiledRendering(tw, th, pw, ph, viewaspect); 
    315             do  
     305            lcCamera* Camera = view.GetCamera(); 
     306 
     307            int CurrentTile = 0; 
     308            int TileWidth = tw; 
     309            int TileHeight = th; 
     310            int ImageWidth = pw; 
     311            int ImageHeight = ph; 
     312            int Columns = (ImageWidth + TileWidth - 1) / TileWidth; 
     313            int Rows = (ImageHeight + TileHeight - 1) / TileHeight; 
     314            float xmin, xmax, ymin, ymax; 
     315            ymax = Camera->m_NearDist * tan(Camera->m_FOV * 3.14159265f / 360.0f); 
     316            ymin = -ymax; 
     317            xmin = ymin * viewaspect; 
     318            xmax = ymax * viewaspect; 
     319 
     320            for (;;) 
    316321            { 
    317                 project->Render(&view, false, false); 
     322                int CurrentTileWidth, CurrentTileHeight; 
     323 
     324                // which tile (by row and column) we're about to render 
     325                int CurrentRow = CurrentTile / Columns; 
     326                int CurrentColumn = CurrentTile % Columns; 
     327 
     328                // Compute actual size of this tile with border 
     329                if (CurrentRow < Rows-1) 
     330                    CurrentTileHeight = TileHeight; 
     331                else 
     332                    CurrentTileHeight = ImageHeight - (Rows-1) * (TileHeight); 
     333                 
     334                if (CurrentColumn < Columns-1) 
     335                    CurrentTileWidth = TileWidth; 
     336                else 
     337                    CurrentTileWidth = ImageWidth - (Columns-1) * (TileWidth); 
     338     
     339                glViewport(0, 0, CurrentTileWidth, CurrentTileHeight); 
     340 
     341                project->RenderBackground(&view); 
     342 
     343                float left, right, bottom, top; 
     344 
     345                glMatrixMode(GL_PROJECTION); 
     346                glLoadIdentity(); 
     347 
     348                // Compute projection parameters. 
     349                left = xmin + (xmax - xmin) * (CurrentColumn * TileWidth) / ImageWidth; 
     350                right = left + (xmax - xmin) * CurrentTileWidth / ImageWidth; 
     351                bottom = ymin + (ymax - ymin) * (CurrentRow * TileHeight) / ImageHeight; 
     352                top = bottom + (ymax - ymin) * CurrentTileHeight / ImageHeight; 
     353 
     354                glFrustum(left, right, bottom, top, Camera->m_NearDist, Camera->m_FarDist); 
     355 
     356                glMatrixMode(GL_MODELVIEW); 
     357                glLoadMatrixf(view.GetCamera()->m_WorldView); 
     358 
     359                project->RenderScene(&view); 
    318360                glFinish(); 
    319                 int tr, tc, ctw, cth; 
    320                 pCam->GetTileInfo(&tr, &tc, &ctw, &cth); 
     361 
     362                int ctw = CurrentTileWidth; 
     363                int cth = CurrentTileHeight; 
     364                int tr = Rows - CurrentRow - 1; 
     365                int tc = CurrentColumn; 
    321366 
    322367                lpbi = (LPBITMAPINFOHEADER)GlobalLock(MakeDib(hBm, 24)); 
     
    327372 
    328373                pDC->SetStretchBltMode(COLORONCOLOR); 
    329                 StretchDIBits(pDC->m_hDC, rc.left+1+(w*c)+mx + tc*tw, rc.top+1+(h*r)+my + tr*th, ctw, cth, 0, 0, ctw, cth,  
     374                StretchDIBits(pDC->m_hDC, rc.left+1+(w*c)+mx + tc*tw, rc.top+1+(h*r)+my + tr*th+th-cth, ctw, cth, 0, 0, ctw, cth,  
    330375                    (LPBYTE) lpbi + lpbi->biSize + lpbi->biClrUsed * sizeof(RGBQUAD), &bi, DIB_RGB_COLORS, SRCCOPY); 
    331376                if (lpbi) GlobalFreePtr(lpbi); 
    332             } while (pCam->EndTile()); 
    333             */ 
     377 
     378                // Increment tile counter. 
     379                CurrentTile++; 
     380                if (CurrentTile >= Rows * Columns)  
     381                    break; 
     382            } 
    334383        } 
    335384        else 
     
    347396            if (lpbi) GlobalFreePtr(lpbi); 
    348397        } 
    349  
    350         // OpenGL Rendering 
    351 //          CCamera* pOld = pDoc->GetActiveCamera(); 
    352 //          pDoc->m_ViewCameras[pDoc->m_nActiveViewport] = pDoc->GetCamera(CAMERA_MAIN); 
    353 //          pDoc->m_ViewCameras[pDoc->m_nActiveViewport] = pOld; 
    354398 
    355399        DWORD dwPrint = theApp.GetProfileInt("Settings","Print", PRINT_NUMBERS|PRINT_BORDER); 
  • trunk/win/Terrwnd.cpp

    r681 r709  
    8383    glViewport(0, 0, m_szView.cx, m_szView.cy); 
    8484 
    85     m_pCamera->LoadProjection(aspect); 
     85    Matrix44 Projection = CreatePerspectiveMatrix(m_pCamera->m_FOV, aspect, m_pCamera->m_NearDist, m_pCamera->m_FarDist); 
     86 
     87    glMatrixMode(GL_PROJECTION); 
     88    glLoadMatrixf(Projection); 
     89 
     90    glMatrixMode(GL_MODELVIEW); 
     91    glLoadMatrixf(m_pCamera->m_WorldView); 
    8692 
    8793    m_pTerrain->Render(m_pCamera, aspect);