void DecoScene::PointScreen2WorldRay(const vector2& pt, vector3& outOrigin, vector3& outDir) const { vector3 viewVec = PointScreen2Camera(pt); matrix44 invview; RI->GetTransform(TT_WorldToCamera, invview); invview.invert(); if (camera->isOrthogonal()) { vector4 viewOrigin(viewVec); viewOrigin.z = 0.f; vector4 viewDir(0, 0, -1, 0); viewOrigin.w = 1.f; viewOrigin = invview * vector4(viewOrigin); vector4 worldVec = invview * viewDir; outOrigin = vector3(viewOrigin.x, viewOrigin.y, viewOrigin.z); outDir = vector3(worldVec.x, worldVec.y, worldVec.z); } else { viewVec.normalize(); outOrigin = camera->getEye(); vector4 worldVec = invview * vector4(viewVec); outDir = vector3(worldVec.x, worldVec.y, worldVec.z); } }
Vector3 PerspectiveCamera::samplePosition(const Sample& sample, Vector3* surfaceNormal, float* pdfArea) const { Vector3 pCamera; if (mLensRadius > 0.0f) { Vector2 lensSample = mLensRadius * uniformSampleDisk(sample.lensU1, sample.lensU2); Vector3 viewOrigin(lensSample.x, lensSample.y, 0.0f); pCamera = mOrientation * viewOrigin + mPosition; } else { pCamera = mPosition; } if (pdfArea) { *pdfArea = mLensRadius > 0.0f ? 1.0f / (mLensRadius * mLensRadius * PI) : 1.0f; } *surfaceNormal = getLook(); return pCamera; }
static void UpdateProjectionMatrix(FSceneView* View, FMatrix OffAxisMatrix) { View->ProjectionMatrixUnadjustedForRHI = OffAxisMatrix; FVector viewOrigin(0.0f, 0.0f, View->ProjectionMatrixUnadjustedForRHI.M[3][3]); View->ViewMatrices.ViewMatrix.SetOrigin(View->ViewMatrices.ViewMatrix.GetOrigin() - viewOrigin); View->InvViewMatrix = View->ViewMatrices.ViewMatrix.Inverse(); View->ViewMatrices.ViewOrigin += View->InvViewMatrix.TransformPosition(-viewOrigin); View->ViewMatrices.PreViewTranslation = -View->ViewMatrices.ViewOrigin; View->ViewMatrices.ProjMatrix = _AdjustProjectionMatrixForRHI(View->ProjectionMatrixUnadjustedForRHI); View->ViewProjectionMatrix = View->ViewMatrices.GetViewProjMatrix(); View->InvViewProjectionMatrix = View->ViewMatrices.GetInvProjMatrix() * View->InvViewMatrix; FMatrix TranslatedViewMatrix = FTranslationMatrix(-View->ViewMatrices.PreViewTranslation) * View->ViewMatrices.ViewMatrix; View->ViewMatrices.TranslatedViewProjectionMatrix = TranslatedViewMatrix * View->ViewMatrices.ProjMatrix; View->ViewMatrices.InvTranslatedViewProjectionMatrix = View->ViewMatrices.TranslatedViewProjectionMatrix.Inverse(); View->ShadowViewMatrices = View->ViewMatrices; //View->InvDeviceZToWorldZTransform = CreateInvDeviceZToWorldZTransform(View->ProjectionMatrixUnadjustedForRHI); GetViewFrustumBounds(View->ViewFrustum, View->ViewProjectionMatrix, false); }