// begin/end model rendering to screen void BeginModelRenderingView( CAnyProjection3D &prProjection, CDrawPort *pdp) { ASSERT( _iRenderingType==0 && _pdp==NULL); // set 3D projection _iRenderingType = 1; _pdp = pdp; prProjection->ObjectPlacementL() = CPlacement3D(FLOAT3D(0,0,0), ANGLE3D(0,0,0)); prProjection->Prepare(); // in case of mirror projection, move mirror clip plane a bit father from the mirrored models, // so we have less clipping (for instance, player feet) if( prProjection->pr_bMirror) prProjection->pr_plMirrorView.pl_distance -= 0.06f; // -0.06 is because entire projection is offseted by +0.05 _aprProjection = prProjection; _pdp->SetProjection( _aprProjection); // make FPU precision low _fpuOldPrecision = GetFPUPrecision(); SetFPUPrecision(FPT_24BIT); // prepare common arrays for simple shadows rendering _avtxCommon.PopAll(); _atexCommon.PopAll(); _acolCommon.PopAll(); // eventually setup truform extern INDEX gap_bForceTruform; extern INDEX ogl_bTruformLinearNormals; if( ogl_bTruformLinearNormals) ogl_bTruformLinearNormals = 1; if( gap_bForceTruform) { gap_bForceTruform = 1; gfxSetTruform( _pGfx->gl_iTessellationLevel, ogl_bTruformLinearNormals); } }
// assure that floating point precision is 53 bits void AssureFPT_53(void) { if (GetFPUPrecision()!=FPT_53BIT) { ASSERTALWAYS( "Floating precision must be set to 53 bits during CSG!"); SetFPUPrecision(FPT_53BIT); } }
/* * Destructor with automatic restoring of FPU precision. */ CSetFPUPrecision::~CSetFPUPrecision(void) { // check consistency ASSERT(GetFPUPrecision()==sfp_fptNewPrecision); // restore old precision if needed if (sfp_fptNewPrecision!=sfp_fptOldPrecision) { SetFPUPrecision(sfp_fptOldPrecision); } }
/* * Constructor with automatic setting of FPU precision. */ CSetFPUPrecision::CSetFPUPrecision(enum FPUPrecisionType fptNew) { // remember old precision sfp_fptOldPrecision = GetFPUPrecision(); // set new precision if needed sfp_fptNewPrecision = fptNew; if (sfp_fptNewPrecision!=sfp_fptOldPrecision) { SetFPUPrecision(fptNew); } }
void EndModelRenderingView( BOOL bRestoreOrtho/*=TRUE*/) { ASSERT( _iRenderingType==1 && _pdp!=NULL); // assure that FPU precision was low all the model rendering time, then revert to old FPU precision ASSERT( GetFPUPrecision()==FPT_24BIT); SetFPUPrecision(_fpuOldPrecision); // restore front face direction gfxFrontFace(GFX_CCW); // render all batched shadows extern void RenderBatchedSimpleShadows_View(void); RenderBatchedSimpleShadows_View(); // back to 2D projection? if( bRestoreOrtho) _pdp->SetOrtho(); _iRenderingType = 0; _pdp = NULL; // eventually disable re-enable clipping gfxEnableClipping(); if( _aprProjection->pr_bMirror || _aprProjection->pr_bWarp) gfxEnableClipPlane(); }
/* * Copy selected sectors of a source brush to a 3D object. */ void CWorld::CopySourceBrushSectorsToObject( CEntity &enBrush, CBrushSectorSelectionForCSG &bscselSectors, const CPlacement3D &plSourcePlacement, CObject3D &obObject, const CPlacement3D &plTargetPlacement, DOUBLEaabbox3D &boxSourceAbsolute ) { ASSERT(GetFPUPrecision()==FPT_53BIT); // get the brush mip from the entity CBrushMip &bmBrushMip = *GetBrushMip(enBrush); // calculate placement of the brush in absolute space (taking relative // world placement and entity placement in account) CPlacement3D plBrush = enBrush.en_plPlacement; plBrush.RelativeToAbsolute(plSourcePlacement); // copy selected sectors of brush to object3d object bmBrushMip.ToObject3D(obObject, bscselSectors); // make a copy of the object and find its box in absolute space CObject3D obAbsolute; obAbsolute = obObject; CSimpleProjection3D_DOUBLE prToAbsolute; prToAbsolute.ObjectPlacementL() = plBrush; prToAbsolute.ViewerPlacementL() = CPlacement3D(FLOAT3D(0,0,0), ANGLE3D(0,0,0)); prToAbsolute.Prepare(); obAbsolute.Project(prToAbsolute); obAbsolute.GetBoundingBox(boxSourceAbsolute); // project the brush into target space CSimpleProjection3D_DOUBLE prSimple; prSimple.ObjectPlacementL() = plBrush; prSimple.ViewerPlacementL() = plTargetPlacement; prSimple.Prepare(); obObject.Project(prSimple); }
/* * Move sectors of a target brush that are affected, to a 3D object. */ void CWorld::MoveTargetBrushPartToObject( CEntity &enBrush, DOUBLEaabbox3D &boxAffected, CObject3D &obObject ) { ASSERT(GetFPUPrecision()==FPT_53BIT); // get the brush mip from the entity CBrushMip &bmBrushMip = *GetBrushMip(enBrush); // copy those sectors of brush touching given bbox to 3D object CBrushSectorSelectionForCSG bscselSectors; bmBrushMip.SelectSectorsInRange(bscselSectors, DOUBLEtoFLOAT(boxAffected)); bmBrushMip.ToObject3D(obObject, bscselSectors); bmBrushMip.DeleteSelectedSectors(bscselSectors); // if no sectors are moved this way if (obObject.ob_aoscSectors.Count()==0) { // move the open sector to object CBrushSectorSelectionForCSG bscselOpen; bmBrushMip.SelectOpenSector(bscselOpen); bmBrushMip.ToObject3D(obObject, bscselOpen); bmBrushMip.DeleteSelectedSectors(bscselOpen); } }