void pl3DPipeline::ScreenToWorldPoint(int n, uint32_t stride, int32_t* scrX, int32_t* scrY, float dist, uint32_t strideOut, hsPoint3* worldOut) { while( n-- ) { hsPoint3 scrP; scrP.Set(float(*scrX++), float(*scrY++), float(dist)); *worldOut++ = GetViewTransform().ScreenToWorld(scrP); } }
void FMaterialEditorViewportClient::FocusViewportOnBounds(const FBoxSphereBounds Bounds, bool bInstant /*= false*/) { const FVector Position = Bounds.Origin; float Radius = Bounds.SphereRadius; float AspectToUse = AspectRatio; FIntPoint ViewportSize = Viewport->GetSizeXY(); if (!bUseControllingActorViewInfo && ViewportSize.X > 0 && ViewportSize.Y > 0) { AspectToUse = Viewport->GetDesiredAspectRatio(); } const bool bEnable = false; ToggleOrbitCamera(bEnable); /** * We need to make sure we are fitting the sphere into the viewport completely, so if the height of the viewport is less * than the width of the viewport, we scale the radius by the aspect ratio in order to compensate for the fact that we have * less visible vertically than horizontally. */ if (AspectToUse > 1.0f) { Radius *= AspectToUse; } /** * Now that we have a adjusted radius, we are taking half of the viewport's FOV, * converting it to radians, and then figuring out the camera's distance from the center * of the bounding sphere using some simple trig. Once we have the distance, we back up * along the camera's forward vector from the center of the sphere, and set our new view location. */ const float HalfFOVRadians = FMath::DegreesToRadians(ViewFOV / 2.0f); const float DistanceFromSphere = Radius / FMath::Sin(HalfFOVRadians); FViewportCameraTransform& ViewTransform = GetViewTransform(); FVector CameraOffsetVector = ViewTransform.GetRotation().Vector() * -DistanceFromSphere; ViewTransform.SetLookAt(Position); ViewTransform.TransitionToLocation(Position + CameraOffsetVector, EditorViewportWidget, bInstant); // Tell the viewport to redraw itself. Invalidate(); }
hsMatrix44 pl3DPipeline::IGetCameraToNDC() { hsMatrix44 cam2ndc = GetViewTransform().GetCameraToNDC(); if (fView.IsPerspective()) { // Want to scale down W and offset in Z without // changing values of x/w, y/w. This is just // minimal math for // Mproj' * p = Mscaletrans * Mproj * p // where Mscaletrans = // [ s 0 0 0 ] // [ 0 s 0 0 ] // [ 0 0 s 0 ] // [ 0 0 t s ] // Resulting matrix Mproj' is not exactly "Fog Friendly", // but is close enough. // Resulting point is [sx, sy, sz + tw, sw] and after divide // is [x/w, y/w, z/w + t/s, 1/sw] float scale = 1.f - float(fCurrRenderLayer) * fTweaks.fPerspLayerScale; float zTrans = -scale * float(fCurrRenderLayer) * fTweaks.fPerspLayerTrans; cam2ndc.fMap[0][0] *= scale; cam2ndc.fMap[1][1] *= scale; cam2ndc.fMap[2][2] *= scale; cam2ndc.fMap[2][2] += zTrans * cam2ndc.fMap[3][2]; cam2ndc.fMap[3][2] *= scale; } else { plConst(float) kZTrans = -1.e-4f; cam2ndc.fMap[2][3] += kZTrans * fCurrRenderLayer; } return cam2ndc; }
glm::mat4 Camera::GetViewProjectionTransform() const { return GetProjectionTransform() * GetViewTransform(); }
inline Matrix44 ShaderManager::GetViewTransform() const { Matrix44 view; GetViewTransform( view ); return view; }