void CameraEffect::beginScene(unsigned int clearMode, const Vector4f& clearColor) { _effectBlocked = true; assert( Camera::_currentCamera == NULL ); Camera::_currentCamera = this; // frame synchronization phase Frame::synchronizeAll(); _dxCR( iDirect3DDevice->SetViewport( &_viewPort ) ); if( _currentEffect == engine::pfxNone || _currentEffect == engine::pfxBloom ) { IDirect3DSurface9* iDirect3DSurface; _renderTarget->iDirect3DTexture()->GetSurfaceLevel( 0, &iDirect3DSurface ); _dxCR( _rts->BeginScene( iDirect3DSurface, &_viewPort ) ); iDirect3DSurface->Release(); } else { IDirect3DSurface9* iDirect3DSurface; _newImage->iDirect3DTexture()->GetSurfaceLevel( 0, &iDirect3DSurface ); _dxCR( _rts->BeginScene( iDirect3DSurface, &_viewPort ) ); iDirect3DSurface->Release(); } if( clearMode ) _dxCR( iDirect3DDevice->Clear( 0, NULL, clearMode, wrap( clearColor ), 1.0f, 0L ) ); // setup transformation matrices if( _frame ) { D3DXMatrixInverse( &Camera::viewMatrix, NULL, &_frame->LTM ); _dxCR( iDirect3DDevice->SetTransform( D3DTS_VIEW, &Camera::viewMatrix ) ); } Camera::projectionMatrix = _projection; _dxCR( iDirect3DDevice->SetTransform( D3DTS_PROJECTION, &_projection ) ); Camera::viewPort = _viewPort; Camera::eyePos = dxPos( &_frame->LTM ); Camera::eyeDirection = dxAt( &_frame->LTM ); Camera::fov = _fov; Camera::nearClipPlane = _nearClipPlane; Camera::farClipPlane = _farClipPlane; // normalize camera eye D3DXVec3Normalize( &eyeDirection, &eyeDirection ); // frustrum planes updateFrustrum(); }
void ScreenCamera::beginScene(unsigned int clearMode, const Vector4f& clearColor) { assert( Camera::_currentCamera == NULL ); Camera::_currentCamera = this; // frame synchronization phase Frame::synchronizeAll(); _dxCR( iDirect3DDevice->SetViewport( &_viewPort ) ); if( clearMode ) _dxCR( iDirect3DDevice->Clear( 0, NULL, clearMode, wrap( clearColor ), 1.0f, 0L ) ); _dxCR( iDirect3DDevice->BeginScene() ); // setup transformation matrices if( _frame ) { D3DXMatrixInverse( &viewMatrix, NULL, &_frame->LTM ); _dxCR( iDirect3DDevice->SetTransform( D3DTS_VIEW, &viewMatrix ) ); } projectionMatrix = _projection; _dxCR( iDirect3DDevice->SetTransform( D3DTS_PROJECTION, &_projection ) ); viewPort = _viewPort; eyePos = dxPos( &_frame->LTM ); eyeDirection = dxAt( &_frame->LTM ); fov = _fov; nearClipPlane = _nearClipPlane; farClipPlane = _farClipPlane; // normalize camera eye D3DXVec3Normalize( &eyeDirection, &eyeDirection ); // update frustrum planes updateFrustrum(); }
Vector3f Frame::getAt(void) { if( isDirty() ) synchronizeSafe(); return wrap( dxAt( <M ) ); }
HRESULT CMayaManager::PerspectiveCamera_Synchronize() { MDagPath MayaCamera; M3dView panel; for(UINT iView= 0; iView < M3dView::numberOf3dViews(); iView++) { D3DXMATRIX mCamera; M3dView::get3dView(iView, panel); panel.getCamera(MayaCamera); MayaCamera.pop(); MString perspNameStr( "persp" ); MString cameraNameStr = MayaCamera.partialPathName(); cameraNameStr = cameraNameStr.substring(0, perspNameStr.length()-1 ); const char* cameraName= cameraNameStr.asChar(); if(cameraNameStr == perspNameStr ) { MayaCamera.extendToShape(); MFloatMatrix fView(MayaCamera.inclusiveMatrix().matrix ); ConvertWorldMatrix(mCamera, fView); panel.getCamera(MayaCamera); MFnCamera fnMayaCamera(MayaCamera.node()); MVector mUp= fnMayaCamera.upDirection(); MVector mAt= fnMayaCamera.viewDirection(); MPoint mEye= fnMayaCamera.eyePoint(MSpace::kWorld); D3DXVECTOR3 dxEye( (float)mEye.x, (float)mEye.y, (float)-mEye.z ); D3DXVECTOR3 dxAt( (float)mAt.x, (float)mAt.y, (float)-mAt.z ); D3DXVECTOR3 dxUp( (float)mUp.x, (float)mUp.y, (float)-mUp.z ); D3DXVECTOR4 fEye; D3DXVECTOR4 fAt; D3DXVECTOR3 fUp; D3DXVec3Transform(&fEye, &dxEye,(D3DXMATRIX*)&mCamera); D3DXVec3Transform(&fAt, &dxAt,(D3DXMATRIX*)&mCamera); D3DXVec3TransformNormal(&fUp, &dxUp,(D3DXMATRIX*)&mCamera); D3DXMatrixLookAtLH(&PerspectiveCamera_View, (D3DXVECTOR3*)&fEye, (D3DXVECTOR3*)&fAt, &fUp); // Projection matrix float zNear = (float)fnMayaCamera.nearClippingPlane(); float zFar = (float)fnMayaCamera.farClippingPlane(); float hFOV = (float)fnMayaCamera.horizontalFieldOfView(); float f = (float) (1.0f / (float) tan( hFOV / 2.0f )); ZeroMemory( &PerspectiveCamera_Projection, sizeof(PerspectiveCamera_Projection) ); PerspectiveCamera_Projection._11 = f; PerspectiveCamera_Projection._22 = f; PerspectiveCamera_Projection._33 = (zFar+zNear) / (zFar-zNear); PerspectiveCamera_Projection._34 = 1.0f; PerspectiveCamera_Projection._43 = -2 * (zFar*zNear)/(zFar-zNear); break; } } return S_OK; }