// set modelview matrix if not already set void CRenderModel::SetModelView(void) { _pfModelProfile.StartTimer( CModelProfile::PTI_VIEW_SETMODELVIEW); _pfModelProfile.IncrementTimerAveragingCounter( CModelProfile::PTI_VIEW_SETMODELVIEW); // adjust clipping to frustum if( rm_ulFlags & RMF_INSIDE) gfxDisableClipping(); else gfxEnableClipping(); // adjust clipping to mirror-plane (if any) extern INDEX gap_iOptimizeClipping; if( gap_iOptimizeClipping>0 && (_aprProjection->pr_bMirror || _aprProjection->pr_bWarp)) { if( rm_ulFlags & RMF_INMIRROR) gfxDisableClipPlane(); else gfxEnableClipPlane(); } // make transform matrix const FLOATmatrix3D &m = rm_mObjectToView; const FLOAT3D &v = rm_vObjectToView; FLOAT glm[16]; glm[0] = m(1,1); glm[4] = m(1,2); glm[ 8] = m(1,3); glm[12] = v(1); glm[1] = m(2,1); glm[5] = m(2,2); glm[ 9] = m(2,3); glm[13] = v(2); glm[2] = m(3,1); glm[6] = m(3,2); glm[10] = m(3,3); glm[14] = v(3); glm[3] = 0; glm[7] = 0; glm[11] = 0; glm[15] = 1; gfxSetViewMatrix(glm); // all done _pfModelProfile.StopTimer( CModelProfile::PTI_VIEW_SETMODELVIEW); }
// Prepare scene for terrain rendering void PrepareScene(CAnyProjection3D &apr, CDrawPort *pdp, CTerrain *ptrTerrain) { ASSERT(ptrTerrain!=NULL); ASSERT(ptrTerrain->tr_penEntity!=NULL); // Set current terrain _ptrTerrain = ptrTerrain; // Set drawport _pdp = pdp; // Prepare and set the projection apr->ObjectPlacementL() = CPlacement3D(FLOAT3D(0,0,0), ANGLE3D(0,0,0)); apr->Prepare(); _aprProjection = apr; _pdp->SetProjection( _aprProjection); CEntity *pen = ptrTerrain->tr_penEntity; // calculate projection of viewer in absolute space const FLOATmatrix3D &mViewer = _aprProjection->pr_ViewerRotationMatrix; _vViewer(1) = -mViewer(3,1); _vViewer(2) = -mViewer(3,2); _vViewer(3) = -mViewer(3,3); // calculate projection of viewer in object space _vViewerObj = _vViewer * !pen->en_mRotation; const CPlacement3D &plTerrain = pen->GetLerpedPlacement(); _mObjectToView = mViewer * pen->en_mRotation; _vObjectToView = (plTerrain.pl_PositionVector - _aprProjection->pr_vViewerPosition) * mViewer; // make transform matrix const FLOATmatrix3D &m = _mObjectToView; const FLOAT3D &v = _vObjectToView; FLOAT glm[16]; glm[0] = m(1,1); glm[4] = m(1,2); glm[ 8] = m(1,3); glm[12] = v(1); glm[1] = m(2,1); glm[5] = m(2,2); glm[ 9] = m(2,3); glm[13] = v(2); glm[2] = m(3,1); glm[6] = m(3,2); glm[10] = m(3,3); glm[14] = v(3); glm[3] = 0; glm[7] = 0; glm[11] = 0; glm[15] = 1; gfxSetViewMatrix(glm); // Get viewer in absolute space _vViewerAbs = (_aprProjection->ViewerPlacementR().pl_PositionVector - pen->en_plPlacement.pl_PositionVector) * !pen->en_mRotation; gfxDisableBlend(); gfxDisableTexture(); gfxDisableAlphaTest(); gfxEnableDepthTest(); gfxEnableDepthWrite(); gfxCullFace(GFX_BACK); }
static DOUBLE TrisTroughputPass(INDEX ct) { if( !_pdp->Lock()) { ASSERT(FALSE); return 0.0; } StartTimer(); gfxSetFrustum( -0.5f, +0.5f, -0.5f, +0.5f, 0.5f, 2.0f); gfxSetViewMatrix(NULL); gfxCullFace(GFX_NONE); _pdp->Fill(C_GRAY|255); _pdp->FillZBuffer(1.0f); if(_bTexture) { gfxEnableTexture(); } else { gfxDisableTexture(); } if(_bBlend) { gfxEnableBlend(); gfxBlendFunc( GFX_ONE, GFX_ONE); } else { gfxDisableBlend(); } if(_bDepth) { gfxEnableDepthTest(); gfxEnableDepthWrite(); } else { gfxDisableDepthTest(); gfxDisableDepthWrite(); } gfxDisableAlphaTest(); gfxSetVertexArray( &_avtx[0], _avtx.Count()); gfxLockArrays(); gfxSetTexCoordArray( &_atex[0], FALSE); gfxSetColorArray( &_acol[0]); if(_bMultiTexture) { gfxSetTextureUnit(1); gfxEnableTexture(); gfxSetTexture( _ulTexObject, _tpLocal); gfxSetTexCoordArray( &_atex[0], FALSE); gfxSetTextureUnit(0); } for( INDEX i=0; i<ct; i++) gfxDrawElements( _aiElements.Count(), &_aiElements[0]); gfxUnlockArrays(); if(_bMultiTexture) { gfxSetTextureUnit(1); gfxDisableTexture(); gfxSetTextureUnit(0); } _pdp->Unlock(); gfxFinish(); _pvp->SwapBuffers(); return StopTimer(); }